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?
Answer
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.
a point
P
with position vectorr
is in the plane if and only if the vector drawn fromP_0
toP
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.
No comments:
Post a Comment