How do you find the intersection of a ray and a parallelogram given the corner and three vertices of the parallelogram?
Can we break this parallelogram into two triangles and perform ray triangle intersection instead?
How do you find the intersection of a ray and a parallelogram given the corner and three vertices of the parallelogram?
Can we break this parallelogram into two triangles and perform ray triangle intersection instead?
You can of course just use triangles. There are ray tracing engines that only use triangles since usually we're interested in arbitrary meshes and specializing the engine to triangles is more valuable than the relatively rare cases that some other shape would apply.
Still, two ray-triangle intersections takes more work than a ray-parallelogram intersection. Indeed, it may be easier to do a ray-parallelogram intersection than a single ray-triangle intersection. They basically work the same way. You do a ray-plane intersection and then determine if the point on the plane is within the parallelogram/triangle. The goal is to solve the following equation for $\alpha$, $\beta$, and $t$.
$$C + t\mathbf v = P+\alpha\mathbf a+\beta\mathbf b$$ $C$ is the location of the camera, $\mathbf v$ is the ray's direction, and $P$ is a corner of the parallelogram, finally $\mathbf a$ and $\mathbf b$ are the vectors from $P$ to the adjacent corners. This reduces to a system of three linear equations. If $\mathbf v$ is parallel to the plane $\mathbf a$ and $\mathbf b$ determine, then there will either be no solution or, if the ray lies in the plane, an infinite number of solutions. Otherwise, you just need to check that $t \geq 0$ (or $t > 0$ depending what you prefer in the case that the camera is on the surface), and that $0 \leq \alpha \leq 1$ and $0 \leq \beta \leq 1$ which ensures that the intersection point is in the parallelogram.