Distance to plane

I wrote a simple helper method that trains the distance from a point to a plane. However, it seems that this leads to meaningless results. Thus, the code i for creating the plane is:

Plane = new Plane(vertices.First().Position, vertices.Skip(1).First().Position, vertices.Skip(2).First().Position); 

Pretty simple, I hope you agree. It creates an XNA plane structure using three points.

Now, right after that:

 foreach (var v in vertices) { float d = Math.Abs(v.ComputeDistance(Plane)); if (d > Constants.TOLERANCE) throw new ArgumentException("all points in a polygon must share a common plane"); } 

Using the same set of vertices that I used to build the plane, I get this exception! Mathematically, this is not possible, since these three points must lie on a plane.

My ComputeDistance Method:

 public static float ComputeDistance(this Vector3 point, Plane plane) { float dot = Vector3.Dot(plane.Normal, point); float value = dot - plane.D; return value; } 

As I understand it, this is correct. So what can I do wrong? Or may I encounter an error in the implementation of XNA?

Some sample data:

 Points: {X:0 Y:-0.5000001 Z:0.8660254} {X:0.75 Y:-0.5000001 Z:-0.4330128} {X:-0.75 Y:-0.5000001 Z:-0.4330126} Plane created: {Normal:{X:0 Y:0.9999999 Z:0} D:0.5} //I believe D should equal -0.5? Distance from point 1 to plane: 1.0 
+4
source share
2 answers

It seems that your Plane implemented in such a way that D not a projection of one of your points onto the normal plane, but rather negative. You can think of it as projecting a vector from a plane to the origin onto a normal one.

In any case, I believe that the change

 float value = dot - plane.D; 

to

 float value = dot + plane.D; 

must fix the situation. NTN.

+6
source

Well, I'm not quite sure that I understand the math here, but I suspect (based on the http://mathworld.wolfram.com/Point-PlaneDistance.html formulas among others) that

 float value = dot - plane.D; 

it should be

 float value = dot / plane.D; 

EDIT: Well, as mentioned in the comments below, this did not work. My best suggestion then is to look at the link or "distance between a point and a plane" by Google and try to implement the formula differently.

+1
source

Source: https://habr.com/ru/post/1332066/


All Articles