예제 #1
0
파일: Vector3f.cs 프로젝트: zbx1425/OpenBVE
        /// <summary>Creates a unit vector perpendicular to the plane described by three spatial coordinates, suitable for being a surface normal.</summary>
        /// <param name="a">The first spatial coordinate.</param>
        /// <param name="b">The second spatial coordinate.</param>
        /// <param name="c">The third spatial coordinate.</param>
        /// <param name="normal">On success, receives the vector perpendicular to the described plane. On failure, receives Vector3f.Up.</param>
        /// <returns>The success of the operation. This operation fails if the specified three vectors are colinear.</returns>
        public static bool CreateNormal(Vector3f a, Vector3f b, Vector3f c, out Vector3f normal)
        {
            normal = Vector3f.Cross(b - a, c - a);
            double norm = normal.X * normal.X + normal.Y * normal.Y + normal.Z * normal.Z;

            if (norm != 0.0)
            {
                normal *= 1.0 / System.Math.Sqrt(norm);
                return(true);
            }
            else
            {
                normal = Vector3f.Up;
                return(false);
            }
        }
예제 #2
0
파일: Vector3f.cs 프로젝트: zbx1425/OpenBVE
        /// <summary>Checks whether three spatial coordinates are colinear.</summary>
        /// <param name="a">The first spatial coordinate.</param>
        /// <param name="b">The second spatial coordinate.</param>
        /// <param name="c">The third spatial coordinate.</param>
        /// <returns>A boolean indicating whether the three spatial coordinates are colinear.</returns>
        public static bool AreColinear(Vector3f a, Vector3f b, Vector3f c)
        {
            Vector3f normal = Vector3f.Cross(b - a, c - a);

            return(IsNullVector(normal));
        }