I cannot find a consistent method for finding the signed distance between a point and a plane. How can I calculate this given a plane defined as a point and a normal?
struct Plane
{
Vec3 point;
Vec3 normal;
}
You're making things much too complicated. If your normal is normalized, you can just do this:
float dist = dotProduct(p.normal, (vectorSubtract(point, p.point)));
dont worry i understand exactly how you feel. I am assuming you want some code snippets. so you can implement it in your own. you need to do a lot more work than just finding out the dot product.
It is up to you to understand this algorithm and to implement it into your own program what i will do is give you an implementation of this algorithm
signed distance between point and plane
Here are some sample "C++" implementations of these algorithms.
// Assume that classes are already given for the objects:
// Point and Vector with
// coordinates {float x, y, z;}
// operators for:
// Point = Point ± Vector
// Vector = Point - Point
// Vector = Scalar * Vector (scalar product)
// Plane with a point and a normal {Point V0; Vector n;}
//===================================================================
// dot product (3D) which allows vector operations in arguments
#define dot(u,v) ((u).x * (v).x + (u).y * (v).y + (u).z * (v).z)
#define norm(v) sqrt(dot(v,v)) // norm = length of vector
#define d(u,v) norm(u-v) // distance = norm of difference
// pbase_Plane(): get base of perpendicular from point to a plane
// Input: P = a 3D point
// PL = a plane with point V0 and normal n
// Output: *B = base point on PL of perpendicular from P
// Return: the distance from P to the plane PL
float
pbase_Plane( Point P, Plane PL, Point* B)
{
float sb, sn, sd;
sn = -dot( PL.n, (P - PL.V0));
sd = dot(PL.n, PL.n);
sb = sn / sd;
*B = P + sb * PL.n;
return d(P, *B);
}
Taken from here: http://www.softsurfer.com/Archive/algorithm_0104/algorithm_0104.htm
PK
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With