namespace GeometriCS { /// /// Euclidean plane with double precision. /// /// /// Plane follows the equation Ax + By + Cz - D = 0 /// public class Planed { /// /// A coefficient of the plane. /// /// /// Plane follows the equation Ax + By + Cz - D = 0 /// public double Coeff_A { get; set; } /// /// B coefficient of the plane. /// /// /// Plane follows the equation Ax + By + Cz - D = 0 /// public double Coeff_B { get; set; } /// /// C coefficient of the plane. /// /// /// Plane follows the equation Ax + By + Cz - D = 0 /// public double Coeff_C { get; set; } /// /// D coefficient of the plane. /// /// /// Plane follows the equation Ax + By + Cz - D = 0 /// public double Coeff_D { get; set; } /// /// Normal vector to the plane. /// public Vector3d Normal => new Vector3d(Coeff_A, Coeff_B, Coeff_C); /// /// Distance of the plane from origin along the normal vector. (signed!) /// public double Distance => -Coeff_D; /// /// Construct the plane from its normal and distance from origin. /// /// Normal vector of the plane. /// Distance from origin along normal. public Planed(Vector3d normal, double distance) { Coeff_A = normal.X; Coeff_B = normal.Y; Coeff_C = normal.Z; Coeff_D = -distance; } /// /// Construct the plane from its normal and distance from origin. /// /// A coefficient of the plane. /// B coefficient of the plane. /// C coefficient of the plane. /// D coefficient of the plane. /// /// Plane follows the equation Ax + By + Cz - D = 0 /// public Planed(double coeff_a, double coeff_b, double coeff_c, double coeff_d) { Coeff_A = coeff_a; Coeff_B = coeff_b; Coeff_C = coeff_c; Coeff_D = coeff_d; } /// /// String representation of the plane. /// /// (normal vector, distance from origin) public override string ToString() { return $"({Normal}, {Distance})"; } /// /// Do the two objects represent the same plane? /// /// Object to compare. /// /// If the planes have inverse normals and also inverse distances, they are considered not equal despite looking the same. /// /// true If the planes have the same coefficients. false public override bool Equals(object? obj) { if (obj is Planed asPlane) { return this == asPlane; } else { return false; } } public override int GetHashCode() { return HashCode.Combine(Coeff_A, Coeff_B, Coeff_C, Coeff_D); } /// /// Deep copy the plane. /// /// Deep copy of the plane. public object Clone() { return new Planed(Coeff_A, Coeff_B, Coeff_C, Coeff_D); } /// /// Are the planes equal? /// /// First plane. /// Second plane. /// /// If the planes have inverse normals and also inverse distances, they are considered not equal despite looking the same. /// /// true If the planes have the same coefficients. false public static bool operator ==(Planed a, Planed b) { return a.Coeff_A == b.Coeff_A && a.Coeff_B == b.Coeff_B && a.Coeff_C == b.Coeff_C && a.Coeff_D == b.Coeff_D; } /// /// Are the planes different? /// /// First plane. /// Second plane. /// true If either the normals or the distance differs, otherwise false. public static bool operator !=(Planed a, Planed b) { return !(a == b); } } }