Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Let's see if I can clarify the maths a bit.

You have two lines:

  • Line r1 such that some point p1 = a + L*b where a is a position vector and b is the direction and L is a parameter.
  • Line r2 such that some point p2 = c + M*d where c is a position vector and d is the direction and M is a parameter.

Each line has its own parameter.

You want to find where these intersect. At the intersection point, p1 = p2. Unless r1 and r2 are parallel, there must exist some values for L and M for which p1 = p2 is true. You only need one of these values to find the intersection point.

This is easiest to solve by splitting r1 and r2 from cartesian form into parametric form, where the x and y coordinates of the vectors are described separately:

r1 is such that p1x = ax + L*bx and p1y = ay + L*by.

r2 is such that p2x = cx + M*dx and p2y = cy + M*dy.

You can then rearrange the equations to isolate and eliminate either L or M and solve for the other. The resultant equation (derivation herederivation here) is, M = ((cy - ay) * bx - (cx - ax) * by) / (dx * by - dy * bx). You could write your code around that. This tutorial might also help to understand the concepts.

Let's see if I can clarify the maths a bit.

You have two lines:

  • Line r1 such that some point p1 = a + L*b where a is a position vector and b is the direction and L is a parameter.
  • Line r2 such that some point p2 = c + M*d where c is a position vector and d is the direction and M is a parameter.

Each line has its own parameter.

You want to find where these intersect. At the intersection point, p1 = p2. Unless r1 and r2 are parallel, there must exist some values for L and M for which p1 = p2 is true. You only need one of these values to find the intersection point.

This is easiest to solve by splitting r1 and r2 from cartesian form into parametric form, where the x and y coordinates of the vectors are described separately:

r1 is such that p1x = ax + L*bx and p1y = ay + L*by.

r2 is such that p2x = cx + M*dx and p2y = cy + M*dy.

You can then rearrange the equations to isolate and eliminate either L or M and solve for the other. The resultant equation (derivation here) is, M = ((cy - ay) * bx - (cx - ax) * by) / (dx * by - dy * bx). You could write your code around that. This tutorial might also help to understand the concepts.

Let's see if I can clarify the maths a bit.

You have two lines:

  • Line r1 such that some point p1 = a + L*b where a is a position vector and b is the direction and L is a parameter.
  • Line r2 such that some point p2 = c + M*d where c is a position vector and d is the direction and M is a parameter.

Each line has its own parameter.

You want to find where these intersect. At the intersection point, p1 = p2. Unless r1 and r2 are parallel, there must exist some values for L and M for which p1 = p2 is true. You only need one of these values to find the intersection point.

This is easiest to solve by splitting r1 and r2 from cartesian form into parametric form, where the x and y coordinates of the vectors are described separately:

r1 is such that p1x = ax + L*bx and p1y = ay + L*by.

r2 is such that p2x = cx + M*dx and p2y = cy + M*dy.

You can then rearrange the equations to isolate and eliminate either L or M and solve for the other. The resultant equation (derivation here) is, M = ((cy - ay) * bx - (cx - ax) * by) / (dx * by - dy * bx). You could write your code around that. This tutorial might also help to understand the concepts.

Source Link
Anko
  • 13.5k
  • 10
  • 56
  • 82

Let's see if I can clarify the maths a bit.

You have two lines:

  • Line r1 such that some point p1 = a + L*b where a is a position vector and b is the direction and L is a parameter.
  • Line r2 such that some point p2 = c + M*d where c is a position vector and d is the direction and M is a parameter.

Each line has its own parameter.

You want to find where these intersect. At the intersection point, p1 = p2. Unless r1 and r2 are parallel, there must exist some values for L and M for which p1 = p2 is true. You only need one of these values to find the intersection point.

This is easiest to solve by splitting r1 and r2 from cartesian form into parametric form, where the x and y coordinates of the vectors are described separately:

r1 is such that p1x = ax + L*bx and p1y = ay + L*by.

r2 is such that p2x = cx + M*dx and p2y = cy + M*dy.

You can then rearrange the equations to isolate and eliminate either L or M and solve for the other. The resultant equation (derivation here) is, M = ((cy - ay) * bx - (cx - ax) * by) / (dx * by - dy * bx). You could write your code around that. This tutorial might also help to understand the concepts.