سؤال

Okay so I have this class

public sealed class LightSource
{
    public readonly Point3D Source;
    public readonly Point3D Direction;

    public readonly float ConeAngle;

    public List<Ray> Lights { get; private set; }

    public const double MaxRadian = 2.0 * Math.PI;

    public LightSource(Point3D source, Point3D direction, float coneAngle)
    {
        this.Source = source;
        this.Direction = direction;

        if (coneAngle <= 0 || coneAngle > LightSource.MaxRadian)
        {
            throw new ArgumentException("coneAngle <= 0 || coneAngle > LightSource.MaxRadian");
        }

        this.ConeAngle = coneAngle;
        this.Lights = LightSource.GenerateLights(this.Source, this.Direction, this.ConeAngle);
    }

    public static List<Ray> GenerateLights(Point3D source, Point3D direction, float coneAngle)
    {
        //How would i do this?
    }
}

How would I realize the method GenerateLights to give me a list of rays that are inside my cone angle. Lets say the amount of rays will be some constant. Thank You.

هل كانت مفيدة؟

المحلول

I'm no expert, but just to give you a starting point: perhaps you could put a grid perpendicular to the direction you're aiming, and only keep the rays whose angle from the direction is within coneAngle?

ASCII art:

                                      +--+--+
                                      |  |  |
                                      +--+--+
                     direction        |  |  |    
staring point ----------------------> +--+--+
                                      |  |  |
                                      +--+--+
                                      |  |  |  
                                      +--+--+

imagine the grid is perpendicular to the "direction" vector.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top