If given a line (represented by either a vector or two points on the line) how do I find the point at which the line intersects a plane? I've found loads of resources on this but I can't understand the equations there (they don't seem to be standard algebraic). I would like an equation (no matter how long) that can be interpreted by a standard programming language (I'm using Java).
相关问题
- Is GLFW designed to use without LWJGL (in java)?
- How does gl_ClipVertex work relative to gl_ClipDis
- How to plot line in matlab with theta/rho data
- Incorrect Clipping and 3D Projection when using Sl
- Create depth map from 3d points
相关文章
- Algorithm for partially filling a polygonal mesh
- Robust polygon normal calculation
- Keep constant number of visible circles in 3D anim
- How do I remove axis from a rotation matrix?
- How to smooth the blocks of a 3D voxel world?
- Mayavi: rotate around y axis
- D3.js - detect intersection area
- Adb install progress bar
You'll need to consider three cases:
You can express the line in paramaterized form, like here:
http://answers.yahoo.com/question/index?qid=20080830195656AA3aEBr
The first few pages of this lecture do the same for the plane:
http://math.mit.edu/classes/18.02/notes/lecture5compl-09.pdf
If the normal to the plane is perpendicular to the direction along the line, then you have an edge case and need to see whether it intersects at all, or lies within the plane.
Otherwise, you have one point of intersection, and can solve for it.
I know this isn't code but to get a robust solution you'll probably want to put this in the context of your application.
EDIT: Here's an example for which there's exactly one point of intersection. Say you start with the parameterized equations in the first link:
The parameter
t
can be anything. The (infinite) set of all(x, y, z)
that satisfy these equations comprise the line. Then, if you have the equation for a plane, say:(taken from here) you can substitute the equations for
x
,y
, andz
above into the equation for the plane, which is now in only the parametert
. Solve fort
. This is the particular value oft
for that line that lies in the plane. Then you can solve forx
,y
, andz
by going back up to the line equations and substitutingt
back in.Using numpy and python:
Based on this Matlab code (minus the checks for intersection), in Python
Result
I checked it graphically it seems to work,
This I believe is a more robust implementation of the link shared before
Just to expand on ZGorlock's answer, I have done the dot product, plus and scalse of 3D Vectors. The references for these calculations are Dot Product, Add two 3D vectors and Scaling. Note: Vec3D is just a custom class which has points: x, y and z.
If you have two points p and q that define a line, and a plane in the general cartesian form ax+by+cz+d = 0, you can use the parametric method.
If you needed this for coding purposes, here's a javascript snippet:
This question is old but since there is such a much more convenient solution I figured it might help someone.
Plane and line intersections are quite elegant when expressed in homogeneous coordinates but lets assume you just want the solution:
There is a vector 4x1 p which describes the plane such that p^T*x =0 for any homogeneous point on the plane. Next compute the plucker coordinates for the line L=ab^T - ba^T where a = {point_1; 1}, b={point_2;1}, both 4x1 on the line
compute: x=L*p = {x0,x1,x2,x3}
x_intersect=({x0,x1,x2}/x3) where if x3 is zero there is no intersection in the euclidean sense.