Ultrashock Forums > Flash > ActionScript > UltraMath
[Math] Rectangle Problem

You are currently viewing our website as a guest which gives you limited access to forums, files and other resources.

Click here to join now for free, and start interacting with our members, download files and much more!

Click here if you are looking for our Flash files and other professional assets.
 
Post Reply | View first unread | Rate Thread Search this Thread | Thread Tools | Display Modes

#1
Bookmark and Share!
[Math] Rectangle Problem
Old 2008-03-13



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.
[ Born2Code™ ]
postbit arrow 8 comments | 970 views postbit arrow Reply: with Quote   
Registered User
jr_alivio is offline
seperator
Posts: 1,317
2003-04-15
Age: 21
jr_alivio lives in Philippines
jr_alivio's Avatar
seperator

Ultrashock Member Comments:
Andy M's Avatar Andy M Andy M is offline Super Moderator Andy M lives in Canada 2008-03-13 #2 Old  
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-...inates-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.
Reply With Quote  
jr_alivio's Avatar jr_alivio jr_alivio is offline jr_alivio lives in Philippines 2008-03-13 #3 Old  
pretty good job andy, thanks. what if i'm given A, B and theta and im solving for x and y? other way around. that would be impossible right?
Reply With Quote  
Andy M's Avatar Andy M Andy M is offline Super Moderator Andy M lives in Canada 2008-03-13 #4 Old  
It's possible to do. You'd just rearrange this: cos(t) = adjacent/hypotenuse = A1/x

so now it's x = A1/cos(t).

Of course you'll either need A1 or you'll end up having four equations and four unknowns. You'll then need to solve them with a matrix.
Reply With Quote  
jr_alivio's Avatar jr_alivio jr_alivio is offline jr_alivio lives in Philippines 2008-03-13 #5 Old  
yep, would need a1. you mean linear equations?
Reply With Quote  
Andy M's Avatar Andy M Andy M is offline Super Moderator Andy M lives in Canada 2008-03-13 #6 Old  
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).
Reply With Quote  
Nutrox's Avatar Nutrox Nutrox is offline Super Moderator Nutrox lives in United Kingdom 17 Creative Assets 2008-03-13 #7 Old  
I have a cheatsheet in my blog that covers a lot of the basic trigonometry, and it is geared towards use in Flash.

Reply With Quote  
jr_alivio's Avatar jr_alivio jr_alivio is offline jr_alivio lives in Philippines 2008-03-14 #8 Old  
thanks nutrox and andy for helping
Reply With Quote  
jr_alivio's Avatar jr_alivio jr_alivio is offline jr_alivio lives in Philippines 2008-03-14 #9 Old  
Code:
x = (Bsin(t)) - (Acos(t)) / (sin^2(t) - cos^2(t))
i used simultaneous linear equations off from the first two equations, thanks a bunch for the help andy and nutrox.
Reply With Quote  
Thread Tools
Display Modes Rate This Thread
Rate This Thread: