
in this diagram, let’s say variables x, y and theta are defined. is there a formula to get A and B? i know i can just create it using the drawing api and rotating the movieclip to the specified angle, but i was just thinking if there was a more conventional way of doing it, e.g. a formula.
thanks in advance.
Yup it’s simple geometry.
A is the sum of the lengths of the longer edge of one triangle and the shorter edge of the other. B uses the other edges.
So essentially you’re going to need to solve for all of the smaller triangles (which is only two or four lengths since two sides are known).
Since you know x and y, we can apply Pythagorean. I’ll refer you to a tutorial I wrote in my blog: http://www.ultrashock.com/blog/andy-m/rectangular-2d-and-3d-coordinates-30.html
If you use some geometry, you’ll find that the smaller triangles are just scaled down versions of the bigger one. i.e. the angles should all be the same: theta, 90-theta, and 90.
Anyway in short I will combine the lengths from two triangles and I should get formulas like this (I’ll represent theta as t):
A = A1 + A2 = x*cos(t) + y*sin(t)
B = B1 + B2 = y*cos(t) + x*sin(t)
Where A1 and A2 represent two parts of A as defined by the triangle. The same is with B.
I’m able to arrive at the first term for the equation for A by:
cos(t) = adjacent/hypotenuse = A1/x. Rearrange this to get A1 = x*cos(t). Repeat for other 3 terms.
- 13 March 2008 11:31 PM
-
Hmm well thinking it through, it’s possible to figure out, but not pretty.
Essentially you’ll have to work off these equations:
A = A1 + A2 = x*cos(t) + y*sin(t)
B = B1 + B2 = y*cos(t) + x*sin(t)
which will give you:
A1 + A2 = something
B1 + B2 = something
however there’s not enough information right there.
So then you have to add extra equations such as:
A1^2 + B2^2 = x^2
A2^2 + B1^2 = y^2
Then solve for all four equations:
A1 + A2 = x*cos(t) + y*sin(t)
B1 + B2 = y*cos(t) + x*sin(t)
A1^2 + B2^2 = x^2
A2^2 + B1^2 = y^2
Now actually this is where I was wrong before: it’s not linear for the last two equations so you can’t easily use matrices (or systems of LINEAR equations). I would actually solve it using a greedy algorithm from there (i.e. guess and check).
- 13 March 2008 11:59 PM
-
I have a cheatsheet in my blog that covers a lot of the basic trigonometry, and it is geared towards use in Flash.
- 14 March 2008 01:13 AM
-
- Log in or join for free to make a comment.


