I have two lines say P1( 0, -1, 0, -1 ) and P2( -1, 0, 0, -1 ). Since I'm working in 2D, there is no Z component. The x,y,z components are normals and the w component is the distance from origin. I am not given the origin or any points on the line.

What method should I use to programmatically determine the point of intersection for these two lines?

  • \$\begingroup\$ Are they planes or lines(or more specifically line segments)? Terminology is important. \$\endgroup\$ – PlayDeezGames Oct 9 '13 at 17:27
  • \$\begingroup\$ they are lines... \$\endgroup\$ – P. Avery Oct 9 '13 at 17:29
  • 1
    \$\begingroup\$ plane needs 3 points. you have 2. makes it a line. \$\endgroup\$ – PlayDeezGames Oct 9 '13 at 17:33
  • \$\begingroup\$ @PlayDeezGames the absence of the z coordinates makes this solvable with only two points. There's an implied point at 0,0,0, or you can just say it's in the x-y plane. \$\endgroup\$ – Seth Battin Oct 9 '13 at 23:52
  • 4
    \$\begingroup\$ Not gamedev specific; belongs on math.stackexchange.com \$\endgroup\$ – Seth Battin Oct 10 '13 at 2:06

This is a plane intersection problem. You have two plane definitions in the point-normal form. The normal is given, and the point is the distance value w multiplied by the normal.

Wikipedia says:

a point P with position vector r is in the plane if and only if the vector drawn from P_0 to P is perpendicular to (normal vector) n.

(P_0 is your plane's point, n is its normal)

If two vectors are perpendicular, their dot product is zero. Your solution is point P. So you have this equation twice, once for each plane:

n.x * (P.x - P_0.x) + n.y * (P.y - P_0.y) + n.z * (P.z - P_0.z) = 0;

So that leaves you with 3 unknowns and two equations. But lucky you, you happen to know that P.z is zero. Solve the remaining portion of the system of equations and you are done.


From https://stackoverflow.com/questions/563198/how-do-you-detect-where-two-line-segments-intersect

Suppose you have 2 lines : (p,p+r) and (q,q+s). Now, these 2 lines intersect if we can find t and u such that: p + t r = q + u s. Solving both sides, we get t = (q − p) × s / (r × s). if rxs is 0, they are parallel. Visit the above link to understand briefly.

  • \$\begingroup\$ the answers found on the above link all rely on knowledge of points on the line, specifically, the starting and ending points on the line...in my problem, each line is represented by a normal and a distance from the origin, not points on the lines... \$\endgroup\$ – P. Avery Oct 9 '13 at 23:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.