Hidden WordScanner
Private scans · No account required

DuckieDai Unit Circle Trig

Find all six trig values exactly, from a standard angle given as a multiple of pi or from a point (x, y) on the terminal side of an angle.

trigonometry · MIT License

Overview

Find all six trig values exactly, from a standard angle given as a multiple of pi or from a point (x, y) on the terminal side of an angle.

  • Owner-tested on a TI calculator
  • Version 1.0.0
  • 3172 bytes
  • Uses math

Before you run it

  • TI-84 Plus CE Python · No calculator OS or Python App version has been verified.
  • TI Connect CE .py transfer to the Python App; the owner's transfer details were not recorded
  • The angle is in standard position, measured from the positive x-axis.
  • For a point, the angle is the one whose terminal side passes through that point.
  • An angle must be a multiple of pi/6 or pi/4, the standard unit-circle angles.

Try the DuckieDai calculator screen

Follow the program's prompts and result flow before downloading.

JavaScript is required for the optional browser simulation. Source viewing and downloading remain available without it.

Simulation boundary: This preview uses a reviewed browser adapter. It does not execute the downloaded Python and does not prove TI-Python or calculator compatibility.

Learn the math

How exact trig values come from the unit circle

The idea

The unit circle is a circle of radius 1 centred at the origin. An angle in standard position starts on the positive x-axis and turns until it meets the circle, and the point where it lands is (cos, sin) of that angle. Tangent is sin divided by cos, and csc, sec, and cot are the reciprocals of sin, cos, and tan.

The standard angles, multiples of pi/6 and pi/4, land on points made from the 30-60-90 and 45-45-90 triangles, so their values are exact: 1/2, sqrt(2)/2, sqrt(3)/2, and their signs come from the quadrant. A point (x, y) that is not on the unit circle works the same way once you divide by its distance r from the origin.

The formula

sin = y/r, cos = x/r, tan = y/x

r = sqrt(x^2 + y^2)

csc = r/y, sec = r/x, cot = x/y

r
the distance from the origin to the point; 1 on the unit circle
x, y
the coordinates of a point on the angle's terminal side
undef
a value with 0 on the bottom, such as tan at pi/2

Using the program

Worked example

Find all six values for 5pi/6. Choose 1 and type 5, then 6. The angle is in Quadrant 2, where sine is positive and cosine is negative.

5pi/6 lands at (-sqrt(3)/2, 1/2)

The program shows sin = 1/2, cos = -sqrt(3)/2, and tan = -sqrt(3)/3, then csc = 2, sec = -2sqrt(3)/3, and cot = -sqrt(3).

The point (1, 2) is on the terminal side of an angle. Choose 2 and type 1, then 2.

r = sqrt(1^2 + 2^2) = sqrt(5)

The program shows r = sqrt(5), then sin = 2sqrt(5)/5, cos = sqrt(5)/5, and tan = 2. The bottoms are rationalized, so 2/sqrt(5) appears as 2sqrt(5)/5.

Tips and common mistakes

Where this comes up

The unit circle is the heart of the trigonometry unit in precalculus and algebra 2, and its exact values come back in calculus limits, derivatives, and integrals.

Exact reviewed bytes

Source code

Download .py

View source below, copy it when JavaScript is available, or download the exact .py bytes.

  1. from math import sqrt
  2. S=('0','1/2','sqrt(2)/2','sqrt(3)/2','1')
  3. C=('1','sqrt(3)/2','sqrt(2)/2','1/2','0')
  4. T=('0','sqrt(3)/3','1','sqrt(3)','undef')
  5. def pause(s):
  6. print(s);input('Enter...');print('\n'*6)
  7. def integer(p):
  8. while 1:
  9. try:return int(input(p))
  10. except ValueError:print('Whole #')
  11. def number(p):
  12. while 1:
  13. try:
  14. s=input(p).strip()
  15. if '/' in s:
  16. a,b=s.split('/');v=float(a)/float(b)
  17. else:v=float(s)
  18. if v-v or abs(v)>=1e100:raise ValueError
  19. return v
  20. except (ValueError,ZeroDivisionError,OverflowError):print('Number or a/b')
  21. def gcd(a,b):
  22. a=abs(a);b=abs(b)
  23. while b:a,b=b,a%b
  24. return a
  25. def fraction(a,b):
  26. if b==0:return 'undef'
  27. if b<0:a=-a;b=-b
  28. g=gcd(a,b)
  29. a//=g;b//=g
  30. return str(a) if b==1 else str(a)+'/'+str(b)
  31. def rt(n):
  32. k=1;d=2
  33. while d*d<=n:
  34. if n%(d*d):d+=1
  35. else:n//=d*d;k*=d
  36. return k,n
  37. def over(c,q,m):
  38. if q==0:return 'undef'
  39. if c==0:return '0'
  40. if q<0:c=-c;q=-q
  41. g=gcd(c,q);c//=g;q//=g
  42. if m==1:return fraction(c,q)
  43. s=('-' if c<0 else '')+('' if abs(c)==1 else str(abs(c)))+'sqrt('+str(m)+')'
  44. return s if q==1 else s+'/'+str(q)
  45. def neg(v):
  46. if v in ('0','undef'):return v
  47. return v[1:] if v[0]=='-' else '-'+v
  48. def recip(v):
  49. if v=='0':return 'undef'
  50. if v=='undef':return '0'
  51. sg='-' if v[0]=='-' else ''
  52. if sg:v=v[1:]
  53. d={'1':'1','1/2':'2','sqrt(2)/2':'sqrt(2)', 'sqrt(3)/2':'2sqrt(3)/3','sqrt(3)/3':'sqrt(3)','sqrt(3)':'sqrt(3)/3'}
  54. return sg+d.get(v,'?')
  55. def angle():
  56. n=integer('Pi numerator? ');d=integer('Pi denominator? ')
  57. if d==0:pause('Bad');return
  58. if d<0:n=-n;d=-d
  59. a=n%(2*d);g=gcd(a,d);a//=g;d//=g
  60. if d not in (1,2,3,4,6):pause('Not standard');return
  61. q=a*(12//d)
  62. table={0:(0,1,1),2:(1,1,1),3:(2,1,1),4:(3,1,1),6:(4,1,1),8:(3,-1,1),9:(2,-1,1),10:(1,-1,1),12:(0,-1,1),14:(1,-1,-1),15:(2,-1,-1),16:(3,-1,-1),18:(4,1,-1),20:(3,1,-1),21:(2,1,-1),22:(1,1,-1)}
  63. if q not in table:pause('Not standard');return
  64. i,cs,ss=table[q]
  65. si=S[i] if ss>0 else neg(S[i]);co=C[i] if cs>0 else neg(C[i])
  66. ta=T[i] if cs*ss>0 else neg(T[i])
  67. if co=='0':ta='undef'
  68. if si=='0':ta='0'
  69. pause('sin = '+si+'\ncos = '+co+'\ntan = '+ta)
  70. pause('csc = '+recip(si)+'\nsec = '+recip(co)+'\ncot = '+recip(ta))
  71. def fmt(v):
  72. if abs(v)<1e-10:return '0'
  73. if abs(v-round(v))<1e-9:return str(int(round(v)))
  74. return str(round(v,6))
  75. def point():
  76. x=number('x? ');y=number('y? ')
  77. if x==0 and y==0:pause('Not origin');return
  78. r=sqrt(x*x+y*y)
  79. q=1
  80. while q<100 and (abs(x*q-round(x*q))>1e-9 or abs(y*q-round(y*q))>1e-9):q+=1
  81. if q<100:a=int(round(x*q));b=int(round(y*q))
  82. if q<100 and a*a+b*b<10**10:
  83. k,m=rt(a*a+b*b)
  84. print('r =',over(k,q,m))
  85. si=over(b,k*m,m);co=over(a,k*m,m);ta=fraction(b,a)
  86. csc=over(k,b,m);sec=over(k,a,m);cot=fraction(a,b)
  87. else:
  88. print('r =',fmt(r))
  89. f=lambda a,b:'undef' if b==0 else fmt(a/b)
  90. si=f(y,r);co=f(x,r);ta=f(y,x);csc=f(r,y);sec=f(r,x);cot=f(x,y)
  91. pause('sin = '+si+'\ncos = '+co+'\ntan = '+ta)
  92. pause('csc = '+csc+'\nsec = '+sec+'\ncot = '+cot)
  93. def main():
  94. print('DuckieDai(TM) UNIFIX');print('hiddenwordscanner.com');pause('Unit circle + points')
  95. while 1:
  96. print('1 Angle -> Trig\n2 Point -> Trig\n3 Exit')
  97. k=integer('Choice? ')
  98. if k==1:angle()
  99. elif k==2:point()
  100. elif k==3:return
  101. main()
Filename
UNIFIX.py
Size
3172 bytes
SHA-256
68ad4790194686f88d241b339280bbb5ba030ba999498682e24f12c45eb21092

Usage

Inputs

  • A menu choice: 1 angle to trig values, 2 point to trig values, 3 exit
  • For an angle, the top and bottom of its pi fraction as whole numbers, such as 5 and 6 for 5pi/6
  • For a point, its x and y, as decimals or fractions such as 1/2

Outputs

  • sin, cos, and tan, then csc, sec, and cot, as exact values such as sqrt(3)/2 or undef
  • For a point, r, the distance from the origin, in exact form such as 5 or 2sqrt(5)

Units: Angles as a multiple of pi; points as plain numbers.

Assumptions and limitations

Assumptions

  • The angle is in standard position, measured from the positive x-axis.
  • For a point, the angle is the one whose terminal side passes through that point.

Constraints

  • An angle must be a multiple of pi/6 or pi/4, the standard unit-circle angles.
  • Exact answers for a point need x and y with a common denominator under 100; otherwise the six values are decimals to six places.
  • inf, nan, and numbers of 1e100 or more are asked for again.

Known failures

  • The point (0, 0) has no angle, so the program says Not origin and returns to the menu.
  • Points with very large whole-number coordinates are shown as decimals rather than exact values.

Compatibility and review

Review status
Owner-tested on a TI calculator
Tested on
Owner reports personally running this program on a TI-84 Plus CE Python calculator; the test date, OS version, and Python App version were not recorded
What happened
Owner reported pass on the calculator before three changes: the website line was added to the opening screen, the number prompt now asks again when inf, nan, or a number of 1e100 or more is typed, where the original stopped with an error, and points with very large coordinates now show decimals instead of making the calculator search for an exact answer for a very long time. Every other step is unchanged; this exact file has not yet been rerun on a calculator.
Dependencies
math
Suggested calculator name
UNIFIX — you can give it another valid, unique name when you transfer it
Desktop test cases
Not available for this interactive-only source

This exact source auto-launches an interactive calculator session, so compatibility evidence comes from the recorded physical-device review rather than an importable desktop fixture.

Transfer and launch

Download the .py file, send it to your calculator with TI Connect CE as UNIFIX or another name, then open the Python App and try the worked example on this page first. This release has no verified calculator OS or Python App version; treat transfer and execution as unverified until independently tested.

Full installation and troubleshooting guide. Check your teacher's or exam's rules before using any program.

Version history

Did a DuckieDai program help with your homework? Every program here is free. If you would like to say thanks, you can leave a tip on Cash App ($duckiedai214) or read what tips pay for.

Independent compatibility resource: Hidden Word Scanner is independent and is not affiliated with or endorsed by Texas Instruments. TI product names describe compatibility only.

Action-count privacy: Successful downloads, preview starts, and preview completions increment same-origin aggregate counters, and so does a Yes or No answer about whether the program worked. Your browser notes that you answered; that note is never sent to the site. No entered values, source text, IP address, account, cookie, device identifier, or fingerprint is stored with these counts.