trigonometry · MIT License
Overview
Solve a triangle with the law of sines from two angles and a side (AAS or ASA) or from two sides and an angle across from one of them (SSA, the ambiguous case, with both triangles when there are two), and find the area from two sides and the angle between them.
- Owner-tested on a TI calculator
- Downloaded 5 times
- Version 1.0.0
- 2460 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
- Sides are named by the angle across from them: side a is across from angle A, b from B, and c from C.
- Angles are in degrees.
- For SSA, the known angle is called A and the side across from it a; the other known side is b or c.
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 triangle with the law of sines, including the ambiguous SSA case
The idea
In any triangle, each side divided by the sine of the angle across from it gives the same number. Once you know one side and the angle across from it, that shared ratio gives every other side from its angle, or every other angle from its side.
Two angles and any side (AAS or ASA) always give exactly one triangle: the third angle is 180 minus the other two. Two sides and an angle across from one of them (SSA) is the ambiguous case: it can give no triangle, one triangle, or two different triangles, because an angle B and 180 - B have the same sine.
The formula
a/sin A = b/sin B = c/sin C
SSA: sin B = b sin A / a, then try B and 180 - B
Area = 1/2 a b sin C (C is the angle between sides a and b)
a, b, c- the sides; side a is across from angle A, b from B, and c from C
A, B, C- the angles in degrees, which add to 180
ambiguous case- SSA, where the given side across from the given angle can swing to two positions
Using the program
- Choose 1 for two angles and a side. Type the two angles you know and press Enter at the one you do not know; the program finds it as 180 minus the others.
- Choose which side you know, a, b, or c, and type its length. The program shows the third angle and the shared ratio a/sinA, then all three angles and all three sides.
- Choose 2 for SSA. Type angle A, the side a across from it, which other side you know, and its length. The program shows sin B, then NO TRIANGLE, one triangle, or TRIANGLE 1 and TRIANGLE 2.
- Choose 3 for the area from two sides and the angle between them, or 4 to see the formulas.
Worked example
Two angles and a side: A = 40 degrees, B = 60 degrees, and a = 10. Choose 1, type 40 and 60, press Enter at angle C, then choose 1 for side a and type 10.
C = 180 - 40 - 60 = 80, a/sin A = 10/sin 40 = 15.5572
The program shows C = 180 - others = 80, then b = 13.473 and c = 15.3209.
The ambiguous case: A = 30 degrees, a = 6, and b = 10. Choose 2 and type 30, 6, 1 for side b, and 10. sin B = 10 sin 30 / 6 = 0.8333, so B can be 56.4427 or 180 - 56.4427 = 123.5573 degrees, and both leave room for C.
The program shows 2 triangle(s), then TRIANGLE 1 with C = 93.5573 deg and c = 11.9769, and TRIANGLE 2 with C = 26.4427 deg and c = 5.3436.
The area of a triangle with sides 5 and 7 and a 60 degree angle between them: choose 3 and type 5, 7, and 60. The program shows Area = 1/2 (s1)(s2) sin C = 15.1554 sq units.
Tips and common mistakes
- Label carefully: side a must be the side across from angle A. Mixing up which side is across from which angle is the most common mistake.
- In SSA, if sin B is more than 1 there is no triangle. If sin B is exactly 1 there is one right triangle.
- When sin B is less than 1, check both B and 180 - B: the second one works only if A + B is still less than 180.
- If you know two sides and the angle between them, or all three sides, use the law of cosines instead: the law of sines needs a side and the angle across from it.
Where this comes up
The law of sines opens the oblique-triangle unit of trigonometry and precalculus, right before the law of cosines. Surveying, navigation, and physics problems with forces at angles use it whenever a triangle has no right angle.
Exact reviewed bytes
Source code
from math import sin,asin,pidef pg():input("[enter]");print("\n"*11)def f(v):return ("%.4f"%v).rstrip("0").rstrip(".")def num(m,top=1e7):while 1:try:v=float(input(m))if 0<v<top:return vexcept ValueError:passprint("Positive number"+(" under 180" if top==180 else ""))def pk(m,o):while 1:s=input(m).strip()if len(s)==1 and s in o:return int(s)def S(a):return sin(a*pi/180)def res(A,B,C,a,b,c):print("A = "+f(A)+" deg\nB = "+f(B)+" deg\nC = "+f(C)+" deg\na = "+f(a)+"\nb = "+f(b)+"\nc = "+f(c))print("\n"*11+"6.1 LAW OF SINES\n ___(o )> quack!\nDuckieDai (TM)\nhiddenwordscanner.com\na is across from A, etc.");pg()while 1:k=pk("1 AAS / ASA (any 2 angles)\n2 SSA (ambiguous)\n3 Area (SAS)\n4 Formulas\n0 Exit\n> ","01234");print("\n"*11)if k<1:breakif k==1:print("Type 2 angles.\nPress [enter] for the\nunknown one.");G=[]for n in"ABC":while 1:t=input("Angle "+n+": ").strip()try:if t=="" or 0<float(t)<180:G+=[t];breakexcept ValueError:0if G.count("")!=1:print("Need exactly 2 angles");pg();continueu=G.index("");G=[float(t) if t else 0 for t in G];G[u]=180-sum(G);A,B,C=Gi=pk("Known side:\n1 a (across A)\n2 b (across B)\n3 c (across C)\n> ","123");v=num("Length: ")if G[u]<=0:print("NO TRIANGLE\nangles add to 180+")else:s=(S(A),S(B),S(C));r=v/s[i-1];print("ABC"[u]+" = 180 - others = "+f(G[u])+"\na/sinA = b/sinB = c/sinC\n= "+f(r));pg();res(A,B,C,r*s[0],r*s[1],r*s[2])elif k==2:print("Need angle A and side a\n(across from A)");A=num("Angle A: ",180);a=num("Side a: ");w=pk("Other side given:\n1 b 2 c\n> ","12");L="BC"[w-1];b=num("Side "+L.lower()+": ")q=b*S(A)/a;print("sin "+L+" = "+L.lower()+" sinA / a\n = "+f(q))o=[]if q<=1+1e-9:B1=90 if q>1-1e-9 else asin(q)*180/pifor B in(B1,180-B1):C=180-A-Bif C>1e-8 and not(o and abs(B-o[0][1])<1e-7):o+=[(A,B,C,a,b,a*S(C)/S(A))]print("sin "+L+" > 1: NO TRIANGLE" if q>1+1e-9 else str(len(o))+" triangle(s)"+("\n("+L+" and 180-"+L+" both work)" if len(o)>1 else ""));pg()for t in o:print("TRIANGLE "+str(o.index(t)+1))if w>1:t=(t[0],t[2],t[1],t[3],t[5],t[4])res(*t);pg()continueelif k==3:p=num("Side 1: ");q=num("Side 2: ");C=num("Angle BETWEEN them: ",180);print("Area = 1/2 (s1)(s2) sin C\n = "+f(p*q*S(C)/2)+" sq units")else:print("a/sinA = b/sinB = c/sinC\nSSA: try B and 180-B,\n keep if A+B < 180\nArea = 1/2 ab sin C\n(C between a and b)")pg()
- Filename
SINE61.py- Size
- 2460 bytes
- SHA-256
46d149e9a074074e22ecd8590a531326d5923ad55dfe6b7a60de96408094977c
Usage
Inputs
- A menu choice: 1 AAS or ASA (two angles and a side), 2 SSA (the ambiguous case), 3 area from two sides and the angle between them, 4 formulas, 0 exit
- Angles in degrees, leaving the unknown angle empty in choice 1
- Which side is known, and its length
Outputs
- All three angles and all three sides of the triangle, with the third angle and the ratio a/sinA shown first
- For SSA: sin B, then no triangle, one triangle, or both triangles of the ambiguous case
- The area of a triangle from two sides and the angle between them
Units: Angles in degrees; sides in any one unit, and the area in that unit squared.
Assumptions and limitations
Assumptions
- Sides are named by the angle across from them: side a is across from angle A, b from B, and c from C.
- Angles are in degrees.
- For SSA, the known angle is called A and the side across from it a; the other known side is b or c.
Constraints
- Angles must be between 0 and 180 degrees, and sides between 0 and 10,000,000.
- Answers are rounded to 4 decimal places, with trailing zeros removed.
Known failures
- In choice 1 the side is asked for even when the two angles already add to 180 or more; the program then shows NO TRIANGLE.
- In SSA, when sin B is at most 1 but no angle fits, as when angle A is obtuse and side a is not the longest, the program shows 0 triangle(s).
- An angle so small that its sine rounds to 0, such as 1e-320, stops the program with a division-by-zero 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 for the original source. The published file changes one line: in the SSA case, when sin B is within 1e 9 of 1 the angle is taken as exactly 90 degrees, so a right triangle such as A = 30, a = 5, b = 10 is shown once instead of twice. This exact file has not yet been rerun on a calculator.
- Dependencies
- math
- Suggested calculator name
SINE61— 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 SINE61 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.