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;
}
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)));
p.normal
and point - p.point
. Can you please explain(maybe using picture) that? In my case, p.normal = (1, 0, 0)
and point - p.point = (-200, 0, 0)
. –
Herodias point
and p
. In your case, what do you think that is? I think it's -200. –
Horton -200
.. So is it correct if I say by using dotProduct
we could find distance between 2 points? –
Herodias p
and q
is sqrt((p-q).(p-q))
. –
Horton d = point - p.point
. Then we're projecting d
onto the normal. The projection formula is p=dot(d,n)/||n||^2*n={n is unit}=dot(d,n)*n
. Since n
is unit, the signed length of that vector is dot(d,n)
. –
Moderato For those curious as to how the dot product formula posted by Beta is derived, here is a visual proof:
N Q
^ |
| | d
| |
| |
---------- P -------+------ > plane
d is the signed distance between Q and the plane
P is a known point that lies on the plane.
N is a normal unit vector perpendicular to the the plane at P.
To find d, we move d to where P and N are
N
^
|
|
+--------Q
| /
d | /
|θ /
|/
---------- P -------------- > plane
Use cosine to generate Equation 1
cos(θ) = adjacent / hypotenuse
cos(θ) = d / |PQ| -- |PQ| is length of (Q-P)
d = |PQ| x cos(θ) -- Equation 1
Using the following dot product formula
a · b = |a| × |b| × cos(θ)
We derive Equation 2
N . (Q-P) = |N| x |PQ| x cos(θ)
N . (Q-P) = 1 x |PQ| x cos(θ) -- |N| is 1 because unit vector
|PQ| x cos(θ) = N . (Q-P) -- Equation 2
Substitute the left side of Equation 2 with Equation 1
d = N . (Q-P)
© 2022 - 2024 — McMap. All rights reserved.