Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question

closed as off-topic by Seth Battin, bummzack, doppelgreener, Anko, Sean Middleditch Oct 10 '13 at 15:53

  • This question does not appear to be about game development within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

    
Are they planes or lines(or more specifically line segments)? Terminology is important. –  PlayDeezGames Oct 9 '13 at 17:27
    
they are lines... –  P. Avery Oct 9 '13 at 17:29
1  
plane needs 3 points. you have 2. makes it a line. –  PlayDeezGames Oct 9 '13 at 17:33
    
@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. –  Seth Battin Oct 9 '13 at 23:52
4  
Not gamedev specific; belongs on math.stackexchange.com –  Seth Battin Oct 10 '13 at 2:06

2 Answers 2

up vote 4 down vote accepted

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.

share|improve this answer

From http://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.

share|improve this answer
    
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... –  P. Avery Oct 9 '13 at 23:37

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