Archived

This topic is now archived and is closed to further replies.

Plane Equation

This topic is 5151 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I''m working with stencil shadowing, but I have some a strange problem... When I use the plane equation to determinate whether the point (light) is infront or behind the plane, I get some strange results when the y value drops below 0... The plane of the polygon is precalculated, using the function written below... Something wrong there? GLvoid PlaneEqr(CVector3 vVector, CVector3 vVector2, CVector3 vVector3, GLfloat planeEqr[4]){ planeEqr[0] = vVector.y * (vVector2.z - vVector3.z) + vVector2.y * (vVector3.z - vVector.z) + vVector3.y * (vVector.z - vVector2.z); planeEqr[1] = vVector.z * (vVector2.x - vVector3.x) + vVector2.z * (vVector3.x - vVector.x) + vVector3.z * (vVector.x - vVector2.x); planeEqr[2] = vVector.x * (vVector2.y - vVector3.y) + vVector2.x * (vVector3.y - vVector.y) + vVector3.x * (vVector.y - vVector2.y); planeEqr[3] = -(vVector.x * (vVector2.y * vVector3.z - vVector3.y * vVector2.z) + vVector2.x * (vVector3.y * vVector.z - vVector.y * vVector3.z) + vVector3.x * (vVector.y * vVector2.z - vVector2.y * vVector.z)); } The plane equation is using as written below and when the vLightPos.y (y coord of the light) is below 0... It says that the point are opposite site of the plane - which is isn''t... Anyone sees the error somewhere? if (sFaces[neighbourIndex].planeEqr[0] * vLightPos.x + sFaces[neighbourIndex].planeEqr[1] * vLightPos.y + sFaces[neighbourIndex].planeEqr[2] * vLightPos.z + sFaces[neighbourIndex].planeEqr[3] > 0.0f)

Share this post


Link to post
Share on other sites
Sorry but that code is very ugly and I dont try to find your errors there

I suggest you to write functions (classes are better) to manipulate these low level problems...

Plane equation: N * P + d = 0 (implicit form)

where N is your normal, d a number and N your ''normal'' that is in general a vector ortogonal to your plane.
(*) is the dot product.

If you have three points you compute your equation in this way

given P0,P1,P2

N = (P1-P0)^(P2-P0) (cross product)
d = -N*P0

Given a point P

distance(P, plane) = (N*P + d)/Len(N)

or "point is in front of the plane" if N*p + d > 0

So...write some vector function and your life will be easier...




Share this post


Link to post
Share on other sites