Ejemplo n.º 1
0
 public Ray Transfer(Ray incomingRay)
 {
     incomingRay.NormalizeDirection();
     var inParams = ComplexLens.ConvertBackSurfaceRayToParameters(incomingRay);
     var outParams = LrtfTable.EvaluateLrtf3D(inParams);
     return ComplexLens.ConvertParametersToFrontSurfaceRay(outParams);
 }
Ejemplo n.º 2
0
        internal Ray TransferDebug(Ray incomingRay,
            out IList<Vector3d> intersections, bool saveIntersections)
        {
            //Console.WriteLine("Complex lens");

            intersections = null;
            if (saveIntersections)
            {
                intersections = new List<Vector3d>();
            }

            double lastRefractiveIndex = MediumRefractiveIndex;
            Vector3d shiftFromLensCenter = Vector3d.Zero;
            //Console.WriteLine("Blue, {0}, ", incomingRay.ToLine());
            //Console.WriteLine("Incoming: {0}, ", Ray.NormalizeDirection(incomingRay).ToString());
            Ray outgoingRay = new Ray(incomingRay);
            //if (ElementSurfaces.First().Surface.Intersect(incomingRay) == null)
            //{
            // The ray might have its origin just on the back surface.
            // Try move the origin a bit in order to let it intersect
            // the surface.
            Vector3d origin = incomingRay.Origin;
            origin.Z += 10e-6;
            incomingRay.Origin = origin;
            //}

            foreach (ElementSurface surface in ElementSurfaces)
            {
                double nextRefractiveIndex = surface.NextRefractiveIndex;

                // Compute intersection

                // the intersection is done on the element surface in its
                // normalized position
                Intersection intersection = surface.Surface.Intersect(incomingRay);
                if (intersection == null)
                {
                    // no intersection at all
                    return null;
                }

                if (saveIntersections)
                {
                    intersections.Add(intersection.Position);
                }

                if (intersection.Position.Xy.LengthSquared >
                    surface.ApertureRadius * surface.ApertureRadius)
                {
                    // intersection is outside the aperture
                    return null;
                }

                // Compute refracted ray

                if (Math.Abs(lastRefractiveIndex - nextRefractiveIndex) > epsilon)
                {
                    // there is a change of refractive index
                    Vector3d intersectionPos = intersection.Position;
                    Vector3d normal = surface.SurfaceNormalField.GetNormal(intersectionPos);
                    if (!surface.Convex)
                    {
                        normal = -normal;
                    }
                    incomingRay.NormalizeDirection();
                    Vector3d refractedDirection = Ray.Refract(
                        incomingRay.Direction, normal, lastRefractiveIndex,
                        nextRefractiveIndex, false);
                    if (refractedDirection == Vector3d.Zero)
                    {
                        return null;
                    }
                    outgoingRay = new Ray(intersectionPos, refractedDirection);
                }
                else
                {
                    // there's no border between different media and thus no refraction
                    outgoingRay = new Ray(incomingRay.Origin, incomingRay.Direction);
                }

                lastRefractiveIndex = nextRefractiveIndex;
                incomingRay = new Ray(outgoingRay.Origin, outgoingRay.Direction);
                //Console.WriteLine("Red, {0}, ", outgoingRay.ToLine());
                //Console.WriteLine("Outgoing: {0}, ", Ray.NormalizeDirection(outgoingRay).ToString());
            }

            outgoingRay.NormalizeDirection();
            return outgoingRay;
        }