Esempio n. 1
0
        public static UnitVector DirectionInHemisphere(this IRandomSequence randomSequence, UnitVector normal)
        {
            var r1 = randomSequence.Double(0.0, 1.0);
            var r2 = randomSequence.Double(0.0, 1.0);

            var(vb1, vb2) = normal.Perpendiculars();

            var theta    = Math.Asin(Math.Sqrt(r1));
            var phi      = Math.PI * Math.PI * r2;
            var sinTheta = Math.Sin(theta);
            var cosTheta = Math.Cos(theta);
            var sinPhi   = Math.Sin(phi);
            var cosPhi   = Math.Cos(phi);

            var v1 = vb1 * (sinTheta * sinPhi);
            var v2 = normal * cosTheta;
            var v3 = vb2 * (cosPhi * sinTheta);

            return((v1 + v2 + v3).Normalize());
        }
Esempio n. 2
0
 public Ray(Point rayOrigin, UnitVector rayDirection)
 {
     RayOrigin    = rayOrigin;
     RayDirection = rayDirection;
 }
Esempio n. 3
0
 public static double DotProduct(UnitVector v1, UnitVector v2)
 {
     return(v1.X * v2.X + v1.Y * v2.Y + v1.Z * v2.Z);
 }
Esempio n. 4
0
        public static (UnitVector, UnitVector) NormalizedPerpendiculars(this UnitVector v)
        {
            (var p1, var p2) = v.Perpendiculars();

            return(p1.Normalize(), p2.Normalize());
        }
Esempio n. 5
0
        public static UnitVector Normalize(this NonUnitVector v)
        {
            var mag = v.Magnitude;

            return(UnitVector.UnsafeCreateUnitVector(v.X / mag, v.Y / mag, v.Z / mag));
        }