Plane Equation from two parallel Lines in OpenGL - need help

247 Views Asked by At

I am attempting to determine a plane for slicing 3D objects in OpenGL. For this I have traced two parallel rays into the 3D world (from a 2D window). It is possible to determine a plane by two parallel lines, but I am having difficulties getting to a representation of the given plane.

1) How do I represent a plane given by two vectors (when I can only use vectors and matrices)? 2) How do I then determine if a point is above or below the plane? (I assume that I can do that by plugging in the point's coordinates in the equation and seeing if it's below or above an absolute threshold)

I'd be very much obliged by anyone who can help.

2

There are 2 best solutions below

4
On

Plane can be represented easiest by:

$$ A x + By + Cz = D $$

Now vector $(A,B,C)$ is perpendicular to the plane. Given two vectors that lie in the plane it's easiest to find such vector by computing cross product.

To find value of $D$ you need to plug in some point into your equation (knowing it's in the plane and knowing $A,B,C$ already) and this will give you $D$.

For checking if something is above or below plane you need some clear definition of above. Most likely you'd like vertical lines to have large $z$ values to be above. This picks one of the half volumes of your world with inequality:

$$ Ax+By+Cz > D $$

This is equation for the upper side provided $C>0$ (otherwise just change sign of everything).

0
On

No doubt you tried to do the same thing that you would for two intersecting lines: compute a normal to the plane by taking the cross product of the two lines’ direction vectors. This fails when the lines are parallel: the cross product of the direction vectors vanishes. You need to find some other vector that’s parallel to the plane. Presumably you know points $\mathbf p$ and $\mathbf q$ on the respective lines: $\mathbf p-\mathbf q$ is parallel to their common plane. So, if $\mathbf v$ is the common direction vector, we have $\mathbf n=\mathbf v\times(\mathbf p-\mathbf q)$ and an equation of the plane is $\mathbf n\cdot\mathbf x = \mathbf n\cdot\mathbf p$ or $\mathbf n\cdot\mathbf x = \mathbf n\cdot\mathbf q$. There are other ways to find this equation, but they’re not as efficient.

If $\mathbf n$ is a unit vector, the above equation says that all of the points on the plane have the same projection onto $\mathbf n$. This same projection allows you to distinguish the two half-spaces defined by the plane: those vectors with longer projections onto $\mathbf n$ are on one side of the plane—that into which $\mathbf n$ points—while those with shorter projections are on the other. Multiplying $\mathbf n$ by a positive scalar doesn’t affect the direction of the inequality, so we can drop the requirement that $\mathbf n$ be a unit vector. Which of these half-spaces is “above” the plane is something that you’ll have to decide based on other considerations. It’s convenient to choose the direction of $\mathbf n$ so that $\mathbf n\cdot\mathbf x\gt\mathbf n\cdot\mathbf p$ means that $\mathbf x$ is “above” the plane. If you’re testing many points, you can of course precomputed $\mathbf n\cdot\mathbf p$.