2
votes

Im working on a raytracer in C. I am trying to figure out the math for the ray-plane intersection. I have

d = ((Po-Lo) (dot) N) / (L (dot) N)

Now if I am correct...

n - the planes normal ray
Po = single point on the plane
L = the vector that represents the ray I am shooting
Lo = a point on the line

I am confused as to how this works. Does the point on the line (Lo) need to land on the plane if I am going pixel by pixel? if that is true couldn't I just represent that point with the direction vector of what ray (L) that I am casting?

I feel like I am completely over complicating this but I am utterly lost on how to get this working in my code.

EDIT:

d = a scalar in the real world domain.

So d needs to equal zero in order for the plane and the ray (at the point I'm looking at) to intersect? And can I use a direction vector coordinates to represent that point on the line>

1
d seems to be a scalar. What does it represent?n. 1.8e9-where's-my-share m.
If you want to potentially save yourself some headaches when it comes to intersections, you can store all your primitives in local coordinates (i.e. at the origin with unit sizes) and keep an affine transformation associated with each one (for rotation, scaling, and translation). When you do the intersection logic, you can do the inverse transform on the ray and solve the simplified intersection problem where P0 = 0, L0 = the transformed ray's origin, and N is just the up vector in your coordinate system. Then you can transform the resulting intersection point back into world coordinates.Simon Broadhead
This answer on line-plane intersection should help (its almost the same thing as ray-plane intersection), it references C code too, stackoverflow.com/a/18543221/432509 (and to reference exact function developer.blender.org/diffusion/B/browse/master/source/blender/…)ideasman42

1 Answers

4
votes

For any point p on the plane, this equation is true:

dot(Po-p,N) = 0

For any point p on the line, this equation is true:

p = Lo+L*d

If the point is going to be both on the plane and on the line (the intersection), then they both must be true. Therefore we can substitute:

dot(Po-(Lo+L*d),N) = 0

By doing some algebra, we can solve for d:

dot((Po-Lo)-L*d),N) = 0
dot(Po-Lo,N) - dot(L*d,N) = 0
dot(Po-Lo,N) - d*dot(L,N) = 0
dot(Po-Lo,N) = d*dot(L,N)
d = dot(Po-Lo,N)/dot(L,N)