trigonometry · MIT License
Overview
Solve a right triangle from two sides or a side and an angle: find the missing side, the two acute angles, and all six trig ratios.
- Owner-tested on a TI calculator
- Version 1.0.0
- 2499 bytes
- Uses math
Tried it? Did this program work on your calculator?
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
- Opposite and adjacent are named from the angle you are working with; the hypotenuse is the longest side, across from the right angle.
- Sides must be positive numbers less than 1e50, typed as decimals or fractions such as 3/2.
- The hypotenuse must be longer than the other known side, and the angle in option 4 must be less than 90 degrees.
Try the DuckieDai calculator screen
Follow the program's prompts and result flow before downloading.
TI-84 Plus CE Python · screen preview
Learn the math
How to solve a right triangle with SOHCAHTOA
The idea
In a right triangle, the trig ratios link an acute angle to the sides. Name the sides from that angle: the opposite side is across from it, the adjacent side is next to it, and the hypotenuse is the longest side, across from the right angle.
Two pieces of information are enough to solve the whole triangle: two sides, or a side and an acute angle. The Pythagorean theorem finds a missing side, and an inverse trig function finds a missing angle.
The formula
sin = opp/hyp, cos = adj/hyp, tan = opp/adj
opp^2 + adj^2 = hyp^2
angle = tan^-1(opp/adj)
opp- the side across from the angle
adj- the side next to the angle that is not the hypotenuse
hyp- the hypotenuse, the longest side
SOHCAHTOA- Sine is Opposite over Hypotenuse, Cosine is Adjacent over Hypotenuse, Tangent is Opposite over Adjacent
Using the program
- Choose 1 for the missing side, 2 for the two acute angles, or 3 for all six ratios. Then choose which two sides you know and enter them.
- Choose 4 when you know an acute angle in degrees and one side. Pick which side you know, opposite, adjacent, or hypotenuse, and enter its length.
- Sides can be decimals or fractions such as 3/2. The hypotenuse must be the longest side.
- Ratios are fractions when the sides are whole numbers, and decimals to six places otherwise.
Worked example
A right triangle has legs 3 and 4. Choose 1, then 1 for opposite and adjacent, and enter 3 and 4.
hyp = sqrt(3^2 + 4^2) = sqrt(25) = 5
The program shows Opp = 3, Adj = 4, and Hyp = 5. Choose 3 with the same sides for the ratios: sin = 3/5, cos = 4/5, and tan = 3/4, then csc = 5/3, sec = 5/4, and cot = 4/3.
Choose 2 with the same sides for the angles. The program shows Angle = 36.869898 deg and Other = 53.130102 deg, which add up to 90.
A ladder 10 long leans at 35 degrees to the ground. Choose 4, type 35, then 3 for hypotenuse, and 10. The program shows Opp = 5.735764, the height reached, and Adj = 8.19152, the distance from the wall.
Tips and common mistakes
- Label the sides from the angle you are using; the opposite side of one acute angle is the adjacent side of the other.
- Make sure your calculator is in degree mode when you check an answer by hand; the program always uses degrees.
- The two acute angles of a right triangle always add up to 90 degrees, which makes a quick check.
- A decimal ratio such as 0.707107 may be an exact value in disguise: 0.707107 is sqrt(2)/2.
Where this comes up
Right triangle trigonometry starts in geometry and continues in precalculus, and physics uses it to split forces and velocities into components.
Exact reviewed bytes
Source code
# DuckieDai(TM) - Right Triangle (TI-84 CE Python)from math import sqrt,atan,pi,sin,cosdef pause():input('Enter...')print('\n'*6)def get(p):while True:try:s=input(p).strip()if '/' in s:a,b=s.split('/');v=float(a)/float(b)else:v=float(s)if 0<v<1e50:return vexcept (ValueError,ZeroDivisionError,OverflowError):passprint('Positive number only')def choose(p,hi):while True:try:v=int(input(p))if 1<=v<=hi:return vexcept ValueError:passprint('Choose 1-',hi)def fmt(v):if abs(v-round(v))<1e-9:return str(int(round(v)))return str(round(v,6))def gcd(a,b):while b:a,b=b,a%breturn adef ratio(a,b):# Exact fractions for integer-valued sides; decimal otherwise.if abs(a-round(a))<1e-9 and abs(b-round(b))<1e-9:n=int(round(a));d=int(round(b));g=gcd(n,d)return str(n//g) if d//g==1 else str(n//g)+'/'+str(d//g)return fmt(a/b)def sides():print('KNOWN SIDES')print('1 Opp + Adj')print('2 Opp + Hyp')print('3 Adj + Hyp')k=choose('Choice? ',3)if k==1:o=get('Opp? ');a=get('Adj? ')return o,a,sqrt(o*o+a*a)if k==2:o=get('Opp? ');h=get('Hyp? ')if h<=o:print('Hyp must be larger');pause();return Nonereturn o,sqrt(h*h-o*o),ha=get('Adj? ');h=get('Hyp? ')if h<=a:print('Hyp must be larger');pause();return Nonereturn sqrt(h*h-a*a),a,hdef show(o,a,h):print('Opp =',fmt(o));print('Adj =',fmt(a));print('Hyp =',fmt(h))def six(o,a,h):print('sin =',ratio(o,h));print('cos =',ratio(a,h));print('tan =',ratio(o,a));pause()print('csc =',ratio(h,o));print('sec =',ratio(h,a));print('cot =',ratio(a,o));pause()def triangle(mode):t=sides()if t is None:returno,a,h=tprint('\n'*5)if mode==1:show(o,a,h)elif mode==2:angle=atan(o/a)*180/piprint('Angle =',fmt(angle),'deg')print('Other =',fmt(90-angle),'deg')else:show(o,a,h);pause();six(o,a,h);returnpause()def side_angle():t=get('Angle deg? ')if t>=90:print('Angle must be <90');pause();returnprint('Known: 1 Opp 2 Adj 3 Hyp')k=choose('Choice? ',3);v=get('Length? ')r=t*pi/180if k==1:h=v/sin(r)elif k==2:h=v/cos(r)else:h=vprint('\n'*5);show(h*sin(r),h*cos(r),h);pause()def main():print('RIGHT TRIANGLE')print('DuckieDai(TM)')print('hiddenwordscanner.com');pause()while True:print('1 Missing side')print('2 Missing angle')print('3 All 6 ratios')print('4 Side + angle')print('5 Exit')k=choose('Choice? ',5)if k==5:returnif k==4:side_angle()else:triangle(k)main()
- Filename
RTRIG.py- Size
- 2499 bytes
- SHA-256
150d0ca8876e2b255376416f321be2da567340461b114f2b2feae2ad7fb156ab
Usage
Inputs
- A menu choice: 1 missing side, 2 missing angle, 3 all six ratios, 4 side and angle, 5 exit
- Which two sides you know: opposite and adjacent, opposite and hypotenuse, or adjacent and hypotenuse
- Side lengths, and for option 4 an acute angle in degrees and one side
Outputs
- The opposite, adjacent, and hypotenuse
- The angle and the other acute angle, in degrees
- sin, cos, tan, csc, sec, and cot as fractions when the sides are whole numbers, or as decimals
Units: Any one length unit for every side; angles in degrees.
Assumptions and limitations
Assumptions
- Opposite and adjacent are named from the angle you are working with; the hypotenuse is the longest side, across from the right angle.
Constraints
- Sides must be positive numbers less than 1e50, typed as decimals or fractions such as 3/2.
- The hypotenuse must be longer than the other known side, and the angle in option 4 must be less than 90 degrees.
Known failures
- A ratio with a square-root side, such as the 1, 1, sqrt(2) triangle, is shown as a decimal, 0.707107, not as sqrt(2)/2.
- With the opposite side known and an extremely small angle, such as 1e-320 degrees, the hypotenuse is too large for the calculator and the program stops with an error.
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 the website line was added to the opening screen. The steps after the opening screen are unchanged; this exact file has not yet been rerun on a calculator.
- Dependencies
- math
- Suggested calculator name
RTRIG— 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 RTRIG 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
- 1.0.0 — current version, published . Download this reviewed version
Related learning
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.