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}
source share