예제 #1
0
        public static Vec4D CreateHorizon(Vec4D pole, double z, double theta)
        {
            Vec4D cross = CreateHorizontal(pole);

            //double phi = Math.Acos(z);
            //return MatrixTransforms.Rotate(theta, pole) * MatrixTransforms.Rotate(phi, cross) * pole;
            return(MatrixTransforms.Rotate(theta, pole) * ((pole * z) + (cross * Math.Sqrt(1 - z * z))));
        }
예제 #2
0
        /// <summary>Used to initialize a <see cref="Ray"/> with an already-normalized <paramref name="direction"/> vector.</summary>
        public Ray(Vec4D origin, Vec4D direction)
        {
            Origin    = origin;
            Direction = direction;

#if DEBUG
            Util.AssertNearlyEqual(direction.SquaredLength, 1, 1e-9, "Ray was instantiated with a non-unit direction vector.");
#endif
        }
예제 #3
0
        public static Vec4D CreateHorizontal(Vec4D vector)
        {
            // Cross against a (arbitrary) up vector to create horizontal vector
            Vec4D cross = vector.Cross(new Vec4D(0, 0, 1, 0));

            // If our up vector matches our input vector, return an arbitrary horizontal
            if (cross == new Vec4D(0, 0, 0, 0))
            {
                return(new Vec4D(1, 0, 0, 0));
            }

            return(cross.Normalize());
        }
예제 #4
0
        public static Mat4x4D Rotate(double angle, Vec4D axis)
        {
            axis = axis.Normalize();

            double cos = Math.Cos(angle);
            double sin = Math.Sin(angle);

            double cosOpp = 1 - cos;

            return(new Mat4x4D(
                       cos + axis.X * axis.X * cosOpp, axis.X * axis.Y * cosOpp - axis.Z * sin, axis.X * axis.Z * cosOpp + axis.Y * sin, 0,
                       axis.Y * axis.X * cosOpp + axis.Z * sin, cos + axis.Y * axis.Y * cosOpp, axis.Y * axis.Z * cosOpp - axis.X * sin, 0,
                       axis.Z * axis.X * cosOpp - axis.Y * sin, axis.Z * axis.Y * cosOpp + axis.X * sin, cos + axis.Z * axis.Z * cosOpp, 0,
                       0, 0, 0, 1));
        }
예제 #5
0
 /// <summary>Create a directional ray starting from <paramref name="origin"/>. The <paramref name="direction"/> vector will be normalized.</summary>
 public static Ray Directional(Vec4D origin, Vec4D direction)
 {
     return(new Ray(origin, direction.Normalize()));
 }
예제 #6
0
 /// <summary>Returns a ray starting from <paramref name="origin"/> and extending infinitely toward the <paramref name="end"/> point.</summary>
 public static Ray FromTo(Vec4D origin, Vec4D end)
 {
     return(new Ray(origin, (end - origin).Normalize()));
 }