Jump to content
  • Advertisement
Sign in to follow this  
CoMaNdore

line intersection equation

This topic is 5038 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay im trying to make out the equalation(sp?, word?) for line intersection. As described here: http://astronomy.swin.edu.au/~pbourke/geometry/lineline2d/ It starts with Pa = P1 + ua ( P2 - P1 ) Pb = P3 + ub ( P4 - P3 ) Where ua and ub are in range [0..1] This I understand, as it is just interpolation between 2 poins to generate a line. Now the next thing is to solve for ua and ub, since the line intersects if: ( P1 + ua( P2 - P1 ) ) = ( P3 + ub ( P4 - P3 ) ) I also have no problem understanding this: It means that if a point on P1P2 and P3P4 have the same location, but ua and ub dont need to be equal, just the curret point on the line the article now solves for ua and ub, this is where I get trubble. How can I solve for these, I have tried and tried, just cant get it working. So if anyone could be so kind to solve these step by step, and say what you do each step, I'did be happy. - CoMaNdore

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Now you want to have either ua or ub in the following system :

So, let us recap what you know :
- P1, P2, P3, P4 are known (and all the x1..4 and y1..4)
- There should be a point P = P1 + ua(P2-P1) = P3 + ub(P3-P4) such that both equations :
x1 + ua(x2 - x1) = x3 + ub(x4 - x3) (E1) AND
y1 + ua(y2 - y1) = y3 + ub(y4 - y3) (E2)
are true.

You want to know P, so you ONLY need to know ua or ub, expressed with something you know.

(E1) && (E2) (y4-y3)*(E1) && (x4-x3)*(E2) (1)
x1*(y4-y3) + ua(x2 - x1)*(y4-y3) = x3*(y4-y3) + ub(x4 - x3)*(y4-y3) (E1') &&
y1*(x4-x3) + ua(y2 - y1)*(x4-x3) = y3*(x4-x3) + ub(y4 - y3)*(x4-x3) (E2') (2)

(1) I am just multiplying stuff. Well if a=b, 2a=2b, isn'it ?

(2) Know, if you take have a=b and c=d, than a+c = b+d, no ? an a-c = b-d, after all ? Then you
practicaly write (E1' - E2') to get rid of ub, and voila :


(E1' && E2')

[x1*(y4-y3) + ua(x2 - x1)*(y4-y3)] - [y1*(x4-x3) + ua(y2 - y1)*(x4-x3)] =
[x3*(y4-y3) + ub(x4 - x3)*(y4-y3)] - [y3*(x4-x3) + ub(y4 - y3)*(x4-x3)]



[x1*(y4-y3) + ua(x2 - x1)*(y4-y3)] - [y1*(x4-x3) + ua(y2 - y1)*(x4-x3)] =
x3*(y4-y3) + ub(x4 - x3)*(y4-y3) - y3*(x4-x3) - ub(y4 - y3)*(x4-x3)



x1*(y4-y3) + ua(x2 - x1)*(y4-y3) - y1*(x4-x3) - ua(y2 - y1)*(x4-x3) =
x3*(y4-y3) - y3*(x4-x3)



ua[(x2-x1)*(y4-y3) - (y2-y1)*(x4-x3)] + x1*(y4-y3) - y1*(x4-x3) = x3*(y4-y3) - y3*(x4-x3)



ua[(x2-x1)*(y4-y3) - (y2-y1)*(x4-x3)] = x3*(y4-y3) + y1*(x4-x3) - y3*(x4-x3) - x1*(y4-y3)



ua = [x3*(y4-y3) + y1*(x4-x3) - y3*(x4-x3) - x1*(y4-y3)] / [(x2-x1)*(y4-y3) - (y2-y1)*(x4-x3)]



ua = [(x3-x1)*(x4-x3) + (y1-y3)*(x4-x3)] / [(x2-x1)*(y4-y3) - (y2-y1)*(x4-x3)]

Which is what you want . (CQFD, as we say in french...)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Sorry, I messed up with the message (and I forgot my account detail, so a I cant edit it)

I wrote the equivalent sign many times, and it disapear. So, the demo will use the == sign to tell that stuff are logically equivalent.

Now you want to have either ua or ub in the following system :

So, let us recap what you know :
- P1, P2, P3, P4 are known (and all the x1..4 and y1..4)
- There should be a point P = P1 + ua(P2-P1) = P3 + ub(P3-P4) such that both equations :
x1 + ua(x2 - x1) = x3 + ub(x4 - x3) (E1) AND
y1 + ua(y2 - y1) = y3 + ub(y4 - y3) (E2)
are true.

You want to know P, so you ONLY need to know ua or ub, expressed with something you know.

(E1) && (E2) == (y4-y3)*(E1) && (x4-x3)*(E2) (1)
== x1*(y4-y3) + ua(x2 - x1)*(y4-y3) = x3*(y4-y3) + ub(x4 - x3)*(y4-y3) (E1') &&
y1*(x4-x3) + ua(y2 - y1)*(x4-x3) = y3*(x4-x3) + ub(y4 - y3)*(x4-x3) (E2') (2)

(1) I am just multiplying stuff. Well if a=b, 2a=2b, isn'it ?

(2) Know, if you take have a=b and c=d, than a+c = b+d, no ? an a-c = b-d, after all ? Then you
practicaly write (E1' - E2') to get rid of ub, and voila :


(E1' && E2') ==

[x1*(y4-y3) + ua(x2 - x1)*(y4-y3)] - [y1*(x4-x3) + ua(y2 - y1)*(x4-x3)] =
[x3*(y4-y3) + ub(x4 - x3)*(y4-y3)] - [y3*(x4-x3) + ub(y4 - y3)*(x4-x3)]

==

[x1*(y4-y3) + ua(x2 - x1)*(y4-y3)] - [y1*(x4-x3) + ua(y2 - y1)*(x4-x3)] =
x3*(y4-y3) + ub(x4 - x3)*(y4-y3) - y3*(x4-x3) - ub(y4 - y3)*(x4-x3)

==

x1*(y4-y3) + ua(x2 - x1)*(y4-y3) - y1*(x4-x3) - ua(y2 - y1)*(x4-x3) =
x3*(y4-y3) - y3*(x4-x3)

==

ua[(x2-x1)*(y4-y3) - (y2-y1)*(x4-x3)] + x1*(y4-y3) - y1*(x4-x3) = x3*(y4-y3) - y3*(x4-x3)

==

ua[(x2-x1)*(y4-y3) - (y2-y1)*(x4-x3)] = x3*(y4-y3) + y1*(x4-x3) - y3*(x4-x3) - x1*(y4-y3)

==

ua = [x3*(y4-y3) + y1*(x4-x3) - y3*(x4-x3) - x1*(y4-y3)] / [(x2-x1)*(y4-y3) - (y2-y1)*(x4-x3)]

==

ua = [(x3-x1)*(x4-x3) + (y1-y3)*(x4-x3)] / [(x2-x1)*(y4-y3) - (y2-y1)*(x4-x3)]

Which is what you want . (CQFD, as we say in french...)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!