Exemple #1
0
        /// <summary>
        /// http://www.had2know.com/academics/equation-plane-through-3-points.html
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <param name="p3"></param>
        public Plane(Point3D p1, Point3D p2, Point3D p3)
        {
            if (p1 == p2 || p1 == p3 || p2 == p3)
            {
                throw new ArgumentException("Must use three different points");
            }
            Vector3D v1    = new Vector3D(p2.X - p1.X, p2.Y - p1.Y, p2.Z - p1.Z);
            Vector3D v2    = new Vector3D(p3.X - p1.X, p3.Y - p1.Y, p3.Z - p1.Z);
            Vector3D cross = v1.CrossProduct(v2);

            if (cross.Length <= float.Epsilon)
            {
                throw new ArgumentException("The 3 points should not be on the same line");
            }
            this.RootPoint = p1;
            this.Normal    = cross.Normalize();
            this.D         = -this.RootPoint.ToVector3D().DotProduct(this.Normal);
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Plane"/> struct.
        /// Creates a plane that contains the three given points.
        /// </summary>
        /// <param name="p1">The first point on the plane.</param>
        /// <param name="p2">The second point on the plane.</param>
        /// <param name="p3">The third point on the plane.</param>
        /// <returns>The plane containing the three points.</returns>
        public static Plane FromPoints(Point3D p1, Point3D p2, Point3D p3)
        {
            // http://www.had2know.com/academics/equation-plane-through-3-points.html
            if (p1 == p2 || p1 == p3 || p2 == p3)
            {
                throw new ArgumentException("Must use three different points");
            }

            var v1    = new Vector3D(p2.X - p1.X, p2.Y - p1.Y, p2.Z - p1.Z);
            var v2    = new Vector3D(p3.X - p1.X, p3.Y - p1.Y, p3.Z - p1.Z);
            var cross = v1.CrossProduct(v2);

            if (cross.Length <= float.Epsilon)
            {
                throw new ArgumentException("The 3 points should not be on the same line");
            }

            return(new Plane(cross.Normalize(), p1));
        }