|
|
Re: how to find 3rd edge in triangle
Posted:
Aug 11, 2007 4:15 PM
|
|
> How can I compute the 3rd edge in a scalene triangle > if I know the other 2 edges and the angle between > them? > Thank you.
Many techniques possible.
Here's one:
Put included angle C at origin of XY plane at (o,o), with one known edge 'b' along +X, terminating at B = (b,o), other edge 'a' terminating at coordinates A = (x,y).
Now use x = len(a)*cos(C), y = len(a)*sin(C) for the (x,y) coordinates of A, then the distance formula to find len(c), the distance twixt point A and point B.
It'd be good to cross-check your result with the Law of Cosines i.e. a**2 + b**2 - 2*a*b*cos(C) should equal c**2.
Here's a little Python program (see plaintext view for significant whitespace):
""" Triangle Algorithm for finding c, given a, b and included angle C
by K. Urner """
from math import sqrt, sin, cos, radians, degrees
class Point:
def __init__(self, x=0, y=0): self.x = x self.y = y
def distance(self, other): return sqrt((self.x - other.x)**2 + (self.y - other.y)**2)
def __repr__(self): return 'Point (%s, %s)' % (self.x, self.y)
def triangle(C, a, b): """ Angle C in degrees at the origin, included between two sides of length a, b, return length c. """ pB = Point(b, 0) pA = Point(a*cos(radians(C)), a*sin(radians(C))) return pA.distance(pB)
def test(): a = 5 b = 25 C = 120 # degrees c = triangle(C, a, b) print c print "%s == %s ?" % (c**2, a**2 + b**2 - 2*a*b*cos(radians(C)))
if __name__ == '__main__': test()
Kirby
|
|