namespace Octree { using System; using System.Runtime.Serialization; // // a*x + b*y + c*z + d = 0 // [Serializable] public class Plane { private Point _point; private Point _normal; private double _d; /// /// Gets or sets the D parameter of the plane. /// public double D { get { return _d; } set { _d = value; _point.Coor = (_normal * -_d).Coor; } } /// /// Gets or sets the plane normal. /// public Point Normal { get { return _normal; } set { _normal.Coor = value.Coor; // point remains the same _d = -(Point.Dot(_normal, _point)); } } /// /// Gets or sets the plane point. /// public Point Point { get { return _point; } set { _point.Coor = value.Coor; // normal remains the same _d = -(Point.Dot(_normal, _point)); } } /// /// Creates a new plane with the given parameters. /// /// The point on the plane. /// The normal of the plane. public Plane(double[] point, double[] normal) { SetPointAndNormal(point, normal); } /// /// Creates a new plane with the given parameters. /// /// The a parameter of the plane. /// The b parameter of the plane. /// The c parameter of the plane. /// The d parameter of the plane. public Plane(double a, double b, double c, double d) { _normal = new Point(a, b, c).Normalized; _d = d; _point = _normal * -_d; } /// /// Creates a new plane with the given nornal and d parameter. /// /// The normal of the plane. /// The d parameter of the plane. public Plane(Point normal, double d) { _normal = normal.Normalized; _d = d; _point = _normal * -_d; } public void SetPointAndNormal(double[] point, double[] normal) { _point = new Point(point); _normal = new Point(normal).Normalized; _d = -(Point.Dot(_normal, _point)); } /// /// Returns the distance between the plane and point. /// /// The plane. /// The point. /// The distance. public static double Distance(Plane plane, Point point) { return Point.Dot(plane.Normal, point) + plane.D; } } }