> Actionscript 3 trigonometry?

Actionscript 3 trigonometry?

Posted at: 2014-12-18 
I have the angles and X/Y coordinates of two corners of a right angle triangle (opposite/hypotenuse and opposite/adjacent.)

How can I calculate the adjacent/hypotenuse X coordinate?



So you have coordinates for A and C, and at least one of the angles A,B...right? And you want to find the coordinates of point B?

That's possible, but you also need to know which side of the line AC that B is on.

If you know angle A, then B is pi/2-A (or 90-A in degrees...I don't do actionscript, but most library trig functions work in radians.) so all 3 angles are in fact easily known. If A = (ax,ay) and C = (cx,cy) then:

b = sqrt( (cx-ax)*(cx-ax) + (cy-ay)*(cy-ay) )

a = b * tan(A)

Those are the sides you need for what follows. Create a unit vector (dx, dy) in the direction from A to C:

dx = (cx - ax)/b

dy = (cy - ay)/b .... dividing by b makes dx*dx + dy*dy == 1

A unit vector representing a LEFT turn at C (as shown in your diagram) is (-dy, dx). A right turn would be (dy, -dx). So the coordinates (bx,by) of B are either:

bx = cx - a*dy .... if A->C->B takes a left turn

by = cy + a*dx

....OR....

bx = cx + a*dy .... if A->C->B takes a right turn

by = cy - a*dx

I have the angles and X/Y coordinates of two corners of a right angle triangle (opposite/hypotenuse and opposite/adjacent.)

How can I calculate the adjacent/hypotenuse X coordinate?