Copy link to clipboard
Copied
Hi there,
I'm trying to get the distance between two objects.
Problem is that both objects are -45ยบ rotated but one of them moves up and down with stage resize. So the distance gets a random degree.
I've attached an image so that it could be simpler to understand my problem.
Hope someone could help me.
Regards
PM
Copy link to clipboard
Copied
As long as both objects are at fixed angles (or known angles) this is not too difficult to figure out. First lets start with what you know: you have two points along two lines. You also have a perpendicular line (the blue line) that contains one of the known points (point A) . Basically the problem is to find point C, which is the point where the blue line intersects line B. Keep in mind, we have the equation to line A, line B and point A so the tangent line (blue line) can be inferred. The math can get a little complex, but that should be enough to get you started. Just search for "intersection line formula" or similar. Here is one page which appeasrs useful:
http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/
Copy link to clipboard
Copied
Hi AHernandezIP,
Thanks for the quick reply.
Itโs kind of difficult for me to understand entirely the concept you defined but Iโm giving it a shot.
If I understood you correctly I can use the advantage of having points A and B. So with point A create a 45ยบ third point (A.x+500, B.x+500) that would create me a new line between A and A2. With point B create two points - B2 and B3. B2 and B3 will be 45ยบ points with a distance of 500px from point B. Point B2 will be in the Top-Right direction (B.x+500, B.y-500) and point B3 in the Bottom-Left direction (B.x-500, B.y+500). This will create a new line between B2 and B3. With these two lines (A-A2, B2-B3) I can calculate the intersection (I found this AS3 LineIntersectionLine function build by Keith Hair) and therefore get missing point C. What I donโt understand is if this intersection point is already the distance I want or I still need to calculate the hypotenuse equation based on points A, B and C and get the A-C segment distance.
Take a look at the attached figure.
Hope you could help me
Regards
PM
Copy link to clipboard
Copied
Yep, works perfectly
. Thanks AHernandezIP. And also thanks to Keith Hair.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now