Пример #1
0
        public Normal3 Sample(Random random)
        {
            /// Get Point uniformly on Disc
            double angle = random.NextDouble() * 2 * Math.PI;
            double r     = random.NextDouble() + random.NextDouble();

            r = r < 1 ? r : 2 - r;
            double u = r * Math.Cos(angle);
            double v = r * Math.Sin(angle);
            /// Raise Disc point to Hemisphere
            double  w          = Math.Sqrt(1 - u * u - v * v);
            Normal3 uDirection = Normal3.AnyPerpendicular(Orientation);
            Normal3 vDirection = Normal3.Perpendicular(Orientation, uDirection);

            return(new Normal3(uDirection * (float)u + vDirection * (float)v + Orientation * (float)w));
        }
Пример #2
0
        public Normal3 Sample(Random random)
        {
            /// Compute Height
            double theta = Math.Pow((random.NextDouble() - 0.5d) * Math.PI, Exponent);
            double r     = Math.Cos(theta);
            double w     = Math.Sin(theta);
            /// Compute u and v
            double angle = random.NextDouble() * 2 * Math.PI;
            double u     = r * Math.Cos(angle);
            double v     = r * Math.Sin(angle);
            /// Transform to Orientation
            Normal3 uDirection = Normal3.AnyPerpendicular(Orientation);
            Normal3 vDirection = Normal3.Perpendicular(Orientation, uDirection);

            return(new Normal3(uDirection * (float)u + vDirection * (float)v + Orientation * (float)w));
        }