Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168733
Image: ubuntu2004

Some Trigonometric Properties of Triangle

Lauri Ruotsalainen, 2010

Please note that the vertices of the triangle don't necessarily have to be on the unit circle. It should be easy to modify the program so that the coordinates of the vertices are given freely.

Picture:

# Some Trigonometric Properties of Triangle # Lauri Ruotsalainen, 2010 # Returns the distance between points (x1,y1) and (x2,y2) def distance((x1, y1), (x2, y2)): return sqrt((x2-x1)^2 + (y2-y1)^2) # Returns an angle (in radians) when sides a and b are adjacent and the side c is opposite to the angle def angle(a, b, c): return acos((b^2 + c^2 - a^2)/(2*b*c)) # Returns the area of a triangle when an angle alpha and adjacent sides a and b are known def area(alpha, a, b): return 1/2*a*b*sin(alpha) xy = [0]*3 @interact def triangle( a0 = slider(0, 360, 1, 30, label="A"), a1 = slider(0, 360, 1, 180, label="B"), a2 = slider(0, 360, 1, 300, label="C") ): # Coordinates of the angles a = [math.radians(a0), math.radians(a1), math.radians(a2)] for i in range(3): xy[i] = (cos(a[i]), sin(a[i])) # Side lengths (bc, ca, ab) corresponding to triangle vertices (a, b, c) al = [distance(xy[1], xy[2]), distance(xy[2], xy[0]), distance(xy[0], xy[1])] # The angles (a, b, c) in radians ak = [angle(al[0], al[1], al[2]), angle(al[1], al[2], al[0]), angle(al[2], al[0], al[1])] # The area of the triangle A = area(ak[0], al[1], al[2]) unit_circle = circle((0, 0), 1, aspect_ratio=1) # Triangle triangle = line([xy[0], xy[1], xy[2], xy[0]], rgbcolor="black") triangle_points = point(xy, pointsize=30) # Labels of the angles drawn in a distance from points a_label = text("A", (xy[0][0]*1.07, xy[0][1]*1.07)) b_label = text("B", (xy[1][0]*1.07, xy[1][1]*1.07)) c_label = text("C", (xy[2][0]*1.07, xy[2][1]*1.07)) labels = a_label + b_label + c_label show(unit_circle + triangle + triangle_points + labels, figsize=[5, 5], xmin=-1, xmax=1, ymin=-1, ymax=1) html( "$\\angle A = %s^\\circ,$ " "$\\angle B = %s^\circ,$ " "$\\angle C = %s^\circ$" % ( math.degrees(ak[0]), math.degrees(ak[1]), math.degrees(ak[2]) ) ) html("$AB = %s,$ $BC = %s,$ $CA = %s$"%(al[2], al[0], al[1])) html("$\\text{Area A} = %s$"%A)