Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Espaรฑol
      • Franรงais
      • Portuguรชs
  • ๆ—ฅๆœฌ่ชžใ‚ณใƒŸใƒฅใƒ‹ใƒ†ใ‚ฃ
  • ํ•œ๊ตญ ์ปค๋ฎค๋‹ˆํ‹ฐ
0

Get 45 degree distance

New Here ,
Oct 28, 2009 Oct 28, 2009

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

TOPICS
ActionScript
629
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 28, 2009 Oct 28, 2009

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/

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 29, 2009 Oct 29, 2009

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 29, 2009 Oct 29, 2009
LATEST

Yep, works perfectly . Thanks AHernandezIP. And also thanks to Keith Hair.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines