Пример #1
0
        /// <summary>
        /// Gets the rotation matrix from the normal vector (extrusion direction) of an entity.
        /// </summary>
        /// <param name="zAxis">Normal vector.</param>
        /// <returns>Rotation matrix.</returns>
        public static Matrix3 ArbitraryAxis(Vector3 zAxis)
        {
            zAxis.Normalize();

            if (zAxis.Equals(Vector3.UnitZ))
            {
                return(Matrix3.Identity);
            }

            Vector3 wY = Vector3.UnitY;
            Vector3 wZ = Vector3.UnitZ;
            Vector3 aX;

            if ((Math.Abs(zAxis.X) < 1 / 64.0) && (Math.Abs(zAxis.Y) < 1 / 64.0))
            {
                aX = Vector3.CrossProduct(wY, zAxis);
            }
            else
            {
                aX = Vector3.CrossProduct(wZ, zAxis);
            }

            aX.Normalize();

            Vector3 aY = Vector3.CrossProduct(zAxis, aX);

            aY.Normalize();

            return(new Matrix3(aX.X, aY.X, zAxis.X, aX.Y, aY.Y, zAxis.Y, aX.Z, aY.Z, zAxis.Z));
        }
        public static void OffsetLine(Vector3 start, Vector3 end, Vector3 normal, double offset, out Vector3 newStart, out Vector3 newEnd)
        {
            Vector3 dir = end - start;

            dir.Normalize();
            Vector3 perp = Vector3.CrossProduct(normal, dir);

            newStart = start + perp * offset;
            newEnd   = end + perp * offset;
        }