Search tutorials
OK so you have two distinct points and you want some basic info about them
lets call them
http://regentsprep.org/Regents/math/rtritrig/tri3.jpg
StartPoint
(x = 0 , y = 0), andEndPoint
(x = 20 , y = -15) (I know what original names!) To start with is your first leason(from me in trigany two points can be connected to form 2 points on a right triangle.
so lets look at our right triangle(I just used some right triangle i found origianly with google images all credit goes to regentsprep.org)StartPoint(0,0)
is represented by Point B in the PictureEndPoint(20,-15)
is represented by point A in the picture x would be the angle from A to B next lesson about a key concept in trigany right triangle can be solved as long as you have 2 sides.
the Slanted line is the Hypotinus (sp? )(edge BA)is the distance of B to A the BC edge is the OPPOSITE EDGE of the angle were trying to find the AC edge is the ADJACENT Edge of our angle Any Angle in a right Triangle can be found usining Angle =tangent(Opposite/Adjacent) now were gonna need to figure out how long opposite and adjacent sides are Distance = SquareRoot((x1 -x2)^2 + (y1-y2)^2) the two points we know Start(0,0) End(20,-15) are points A and C so DistanceOpposite = Math.sqrt((Start.x -Start.x)^2 +(Start.y - End.y)^2) DistanceOpposite = Math.sqrt((0 -0)^2 +(0 - -15)^2) DistanceOpposite = Math.sqrt((0)^2 +(15)^2) DistanceOpposite = Math.sqrt((0*0)+(15*15)) DistanceOpposite = Math.sqrt(225) DistanceOpposite = 15 DistanceAdjacent = Math.sqrt((Start.x -End.x)^2 +(End.y - End.y)^2) DistanceAdjacent = Math.sqrt((0-20)^2 +((-15)-(-15))^2) DistanceAdjacent = Math.sqrt((-20)^2 +(0)^2) DistanceAdjacent = Math.sqrt((-20*-20) +(0*0)) DistanceAdjacent = Math.sqrt(400 +0) DistanceAdjacent = Math.sqrt(400) DistanceAdjacent = 20 so now we go back to our angle formula Angle =tangent(Opposite/Adjacent) Angle = Math.atan2(Opposite/Adjacent) Angle = Math.atan2(15/20) Angle = Math.atan2(0.75) Angle = (about ) 37 degrees [edit] actually i think on the atan2 Math function it devides it for you so it would be Math.atan2(Opposite,Adjacent) not Math.atan2(Opposite/Adjacent) Hopefully this helped i think all my math is right but if im wrong on anything im sure someone will correct it just remember flash when setting points tends to use radians rather than degrees radians = (Math.PI*degrees)/180 degrees = 180 /(Math.PI*radians) Ok if this didnt help...Q_Hybrid posted the following function for Actionscript here on Flashkit a while ago| » Level Intermediate |
|
Added: 2006-04-27 Rating: 0 Votes: 0 |
| » Author |
| Just learned it for a program i was writing...figured id share...Someone on kirupa asked how to figure out an angle i answered with this..thought some ppl might find it useful |
| » Download |
| Download the files used in this tutorial. |
| Download (0 kb) |
| » Forums |
| More help? Search our boards for quick answers! |
-
You must have javascript enabled in order to post comments.


Comments
There are no comments yet. Be the first to comment!