   closest point on plane & distance
  How do I find the closest point on a plane relative to the specified point?float3 PointOnPlane(const float4 &plane, const float3 &point){ return ...}Also, willDotProduct( (float3)plane, point) + plane.w;equalDistance(point, PointOnPlane(plane,point));?   
  What you want is called the orthogonal projection. To return the point on the plane closest to a given point: (pt . n) / (n . n) * n where n is the normal to the plane (a, b, c) and pt is the point and . denotes dot product.For finding the distance from a point to a plane, go here.   ;  Great, if only I understood scientific notation.Can someone post some source/pseudo code, or point me to a resource that has?[Edited by - remdul on May 27, 2006 12:52:37 PM];  Your plane is defined by a normal N and a point. This normal must be normalized.Take a vector P from an arbitrary point of the plane to the specified point.The dotproduct P*N should return the distance from the plane to the point.[Edited by - Kwak on May 27, 2006 4:58:04 PM];  I haven't tested it, and chances are its not the fastest way to do it but, here it goes:1. Find distance from the plane to the point (store it in 'distance')2. Find the vector of the length 'distance' and direction equal to the normal of the plane3. Subtract this vector from the point4. Return the resulting pointVoila! Should work.Edit: Oh, this gives the x,y,z of the point in world space, not the x,y of the plane.   ;  wasn't paying attention, i only solved part of the problem.Anyway ezbez has given the solution already.(I forgot to substract N*distance from the specified point)Quote:Topic questionAlso, willDotProduct( (float3)plane, point) + plane.w;equalDistance(point, PointOnPlane(plane,point));?if you mean that your plane is of this form: Ax+Bx+Cz+D=0 and float3 plane = [A,B,C]and plane.w = DThen the answer is NOProbably you know that (A,B,C) is the normal of the plane. You must pay attention (A,B,C) must be normalized first for most of the calculations.DotProduct( (float3)plane, point) + plane.w;=DotProduct(Normal,VectorFromOriginToPoint)+aValue;VectorFromOriginToPoint should be a vector from an arbitrary point of the plane to the specified point?And what is plane.w doing there?Distance(point, PointOnPlane(plane,point))Well if PointOnPlane works fine this looks ok.(maybe better to call it ClosestPointOnPlane(plane,point)? just in case the project gets big, i'm nagging now...)[Edited by - Kwak on May 27, 2006 5:53:51 PM];  Actually I tried most of that before, but it either doesn't work, I got my code wrong or this isn't even what I'm looking for.Quote:1. Find distance from the plane to the point (store it in 'distance')2. Find the vector of the length 'distance' and direction equal to the normal of the plane1. >> How do I find the distance? Is that the DotProduct thingie?DotProduct( (float3)plane, point) + plane.w;Does it return the exact distance in world space units or something else? Or is it something you can only use to check on which side of the plane a point is?2. >> I understand the theory, but I can't get it to produce expected results.Some working source code would be *greatly* appreciated.[Edit: removed code didn't make sense][Edited by - remdul on May 28, 2006 7:30:33 AM];I hope you can see DotProduct(P,N) returns the distance from the point to the plane. (This is if N is normalized, or N has a length of 1)P is a vector from an arbitrary point on your plane, to the red point.Easiest way to define a plane is with a point R that is on the plane, and a normal N (perpendicular on the plane, with length 1)so the distance from the plane to the red point = DotProduct(N, P-R)This distance is negative if the point is on the back of the plane (the side where the normal is pointing away from) and positive if (in this case).If you want the real distance, you have to take abs(distance).We dont want the abs(distance) since we need to know if we must add or substract the N*abs(distance) from the vector to the red point. If we don't take the abs of the distance, we can always substract N*abs(distance) from the vector to the red point.So finally your code is//If you work with a plane defined by point and normalPoint ClosestPointOnPlane(Plane plane, Point point){    float distance = DotProduct(plane.Normal, point-plane.point);    return point - distance*plane.Normal;}If you work with 4 floats [A,B,C,D] where your plane is defined by Ax+By+Cz+D=0, then your plane.Normal is Normalize(A,B,C), and the plane.point could be (0,0,-D/C). But here you have to wath out that C is never 0 (no horizontal planes) to avoid devision by zero. So you could make a function ArbitraryPointOnPlane that returns (0,0,-D/C) if C!=0 and (0,-D/B) if c==0. Ithink this method sucks, so i make my own class/struct plane that has a normal and a point.If you dont want to do this because your plane only takes 4*sizeof(float) bytes,and my idea takes 6*sizeof(float), you can always make a struct/class that contains a normal and a float "value" so that value*Normal is a point on the planeI really cant explain it easier than this.PS:DotProduct( (float3)plane, point) + plane.w;=> i really dont know what the 3 floats mean (but i guessed A,B,C in my example)=> and what plane.w means (guessed eather +D or -D in my example)But it looks wrong   ;  I already understand the theory, but have read to much conflicting (or unclear) notes on this matter. I'll play around with the code some more.FYI:float3 is my vector class (XYZ, like your ABC). I store planes as float4s, in which XYZ being a normalized vector and W the distance to origin (since thats all a 'plane' is, and in fact more correct than a point+normal). Casting float4 (plane) to float3 would result in the plane normal.This seems to work:// returns on which side plane the point isfloat PlaneTest(const float4 &plane, const float3 &point){ return DotProduct( (float3)plane, point) + plane.w;}// returns closest point on planefloat3 PointOnPlane(const float4 &plane, const float3 &point){ float d = DotProduct((float3)plane, point-((float3)plane*plane.w)); return point - ((float3)plane * d); }// returns distance between point and planefloat PlaneDistance(const float4 &plane, const float3 &point){ return Distance(point, PointOnPlane(plane,point));}Shouldn't that arrow be parallel to the normal in your image?[Edited by - remdul on May 31, 2006 9:43:13 AM]