The Ultrashock Ultra Bundle
  • Home
  • Community
  • Forum
  • Flash
  • UltraMath
  • Thread
  •  
  • Previous topic
  • Next topic
Sign up to post

Flash
 UltraMath

  • jr_alivio Author 
    • 1647 
    • 0 
    • 8 
    [Math] Rectangle Problem
    jr_alivio

    Last reply Mar 14 2008, 05:44 AM

    by jr_alivio

    Posted: Mar 13 2008, 10:50 PM

    by jr_alivio

     

rectangle.gif

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.

  8 REPLIES
 
Andy M
1  
Andy M

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
  •  
jr_alivio Author 
2  
jr_alivio

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?

  • 13 March 2008 11:42 PM
  •  
Andy M
3  
Andy M

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.

  • 13 March 2008 11:45 PM
  •  
jr_alivio Author 
4  
jr_alivio

yep, would need a1. you mean linear equations?

  • 13 March 2008 11:48 PM
  •  
Andy M
5  
Andy M

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
  •  
Nutrox
6  
Nutrox

I have a cheatsheet in my blog that covers a lot of the basic trigonometry, and it is geared towards use in Flash.

good

  • 14 March 2008 01:13 AM
  •  
jr_alivio Author 
7  
jr_alivio

thanks nutrox and andy for helping smilie

  • 14 March 2008 04:49 AM
  •  
jr_alivio Author 
8  
jr_alivio
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.

  • 14 March 2008 05:44 AM
  •  
  •   Log in or join for free to make a comment.
 
Topic actions
  •  Share on Facebook
  •  Share on Twitter
Topic Categories
  •  Show All Topics
  •  Development
    •  Server Side
    •  Client Side
  •  Creative Software
    •  Web
    •  Video
    •  3D
    •  Illustrator
    •  Photoshop Battles
    •  Photoshop
  •  Design
    •  Typography
    •  Resources & Insight
    •  Checkpoint
  •  Career
    •  Copyright Matters
    •  Advice & issues
    •  Job Seekers
    •  Job Offers
  •  Flash
    •  UltraMath
    •  OOP
    •  Third Party Tools
    •  Open Source alternatives
    •  Data Communication
    •  Components
    •  Flex
    •  AIR
    •  Flash Lite
    •  Flash Professional
    •  Flash Newbie
    •  ActionScript
    •  XML
  •  Lounge
    •  Polls
    •  Random Chat
    •  Showcase And Critique
    •  BombShock Award Nominations
  •  Community Essentials
    •  BombShock Award Winners
    •  Tutorials
    •  Interviews
    •  News
    •  Bitmap tutorials
Popular Topics
  • Sort by: 
  • Activity
  • Views
  • Comments
  • Likes
Advertise with us
  • Your advertisement here!
  • loading
Ultrashock
  • Creative Assets
  • Community
  • Blog
  1. Home
  2. Forum
+/-
Creative Assets
  • Categories
  • Contributors
  • How to buy
Make Money
  • Commission Rates
  • Referral Program
  • Contributor Program
Community
  • Activity Feed
  • Forum
  • Profiles
About
  • Quick Tour
  • Our History
  • Banners & Logos
Support
  • Contact Ultrashock
  • Advertise with us
  • Legal Information
  •  Keep up to date
  • Flash 775  Flash
  • Audio 6,481  Audio
  • Vector 2,130  Vectors
  • Image 12,338  Images
  • Creative Assets 21,724  Assets
  • Profiles 282,659  Members
  • Topics 93,762  Topics
  • Blog 4  Blog
  • Facebook 1,680  Facebook
  • Twitter 1,165  Twitter
  • Join our FREE monthly newsletter!
  • Archive
  • Invalid email address. Please try again.
Subscribe
  • ©2012 Ultrashock LLC - All rights reserved
  • Terms of Use
  • Privacy Policy
  • Switch to dark theme
  • RSS Feeds
  • Top

©2012 Ultrashock LLC - All rights reserved

Printed on Sat, February 04, 2012 - 20:17:50