Example #1
0
        public Scientrace.SingleRaySource setSingleRayFromXData(XElement xlight, List <Scientrace.UniformTraceModifier> utms,
                                                                Scientrace.Object3dEnvironment env)
        {
            double distance     = this.X.getXDouble(xlight.Attribute("Distance"), 0);
            int    beamcount    = this.X.getXInt(xlight.Attribute("RayCount"), this.X.getXInt(xlight.Attribute("BeamCount"), 1));
            double minintensity = this.X.getXDouble(xlight, "MinIntensity", 0.01);             //default minimum intensity for tracing set to 1%

            Scientrace.NonzeroVector light_direction = this.X.getXNzVector(xlight.Element("Direction"));
            Scientrace.Location      centerloc       = this.X.getXVector(xlight.Element("Location")).toLocation();
            Scientrace.Location      locoffset       = (light_direction.toVector().negative() * distance).toLocation(); //distance cm above surface
            Scientrace.Location      loc             = locoffset + centerloc;
            XMLSpectrumParser        xsp             = new XMLSpectrumParser();

            Scientrace.LightSpectrum spectrum = xsp.parseLightSpectrum(xlight.Element("Spectrum"));
            if (spectrum == null)
            {
                throw new Exception("LightSpectrum " + xlight.Element("Spectrum").ToString() + " unknown");
            }

            Scientrace.SingleRaySource retlight = new Scientrace.SingleRaySource(new Scientrace.Line(loc, light_direction.toUnitVector()),
                                                                                 beamcount, spectrum, env);

            retlight.minimum_intensity_fraction = minintensity;
            retlight.lightsource_modifiers.AddRange(utms);
            retlight.init();
            return(retlight);
        }
        public void paramInit(
            Scientrace.Location lens_sphere_location, double lens_sphere_radius,
            double lens_sphere_radians_min, double lens_sphere_radians_max,
            Scientrace.UnitVector orientation_from_sphere_center, bool double_convex_ring)
        {
            this.sphereLoc    = lens_sphere_location;
            this.sphereRadius = lens_sphere_radius;
            //Console.WriteLine("Sphere radius: "+sphereRadius);
            this.radiansMin       = lens_sphere_radians_min;
            this.radiansMax       = lens_sphere_radians_max;
            this.orientation      = orientation_from_sphere_center;
            this.doubleConvexRing = double_convex_ring;

            if (lens_sphere_radians_min > 0)
            {
                this.innerVoid = new InfiniteCylinderBorder(null, null,
                                                            lens_sphere_location, orientation_from_sphere_center,
                                                            lens_sphere_radius * Math.Sin(lens_sphere_radians_min)
                                                            );
                this.innerVoid.enclosesInside = false;
            }

            this.lensSphere = new Sphere(null, null, lens_sphere_location, lens_sphere_radius);
            this.initBottom();
        }
Example #3
0
        /// <summary>
        /// Creates a line starting at the projection of this.loc on the intersection between this and another Plane.
        /// The direction of the line is that of the crossproduct of this.normal and anotherPlane.normal.
        /// </summary>
        /// <returns>A line along the intersection of this and anotherPlane, returns "null" if two planes are significantly parallel</returns>
        /// <param name="anotherPlane">A plane to calculate the intersection with</param>
        public Scientrace.Line getIntersectionLineWith(Scientrace.Plane anotherPlane)
        {
            Scientrace.UnitVector n1, n2;
            n1 = this.getNorm();
            n2 = anotherPlane.getNorm();
            Vector tw = n1.crossProduct(n2);

            if (tw.length < MainClass.SIGNIFICANTLY_SMALL)
            {
                //Console.WriteLine("WARNING: two planes do not intersect since they are parallel.");
                return(null);
            }
            UnitVector intersection_direction = tw.tryToUnitVector();

            Vector tl1 = n1.crossProduct(intersection_direction);

            if (tl1.length == 0)
            {
                throw new Exception("Plane.getIntersectionLineWith/l1.length can never be zero. If this happens, notify the [email protected] about this..." + this.ToString() + anotherPlane.ToString());
            }
            // l1 lies in "this" plane, and is orthogonal to the intersectionline-direction
            UnitVector l1 = tl1.tryToUnitVector();

            // where l1, starting at this.loc, meets anotherPlane we found a location on the intersectionline.
            Scientrace.Location retLoc = anotherPlane.lineThroughPlane(new Line(this.loc, l1));
            if (retLoc == null)
            {
                Console.WriteLine("WARNING: retLoc == null; l1: " + l1.ToString() + " ; anotherPlane:" + anotherPlane.getNorm().ToString());
                return(null);
            }
            return(new Line(retLoc, intersection_direction));
        }
Example #4
0
        /* Classes supporthing the creation of the lightsource */
        public Scientrace.LightSource setRandomCylinderLightFromXData(XElement xlight,
                                                                      Scientrace.Object3dEnvironment env)
        {
            //Reading LightSource parameters from XML-element

            /* "RandomCylinder"
             * d class.radius, d distance, i beamcount, i maxinteractions, d minintensity
             * str spectrum, vec location, vec direction */
            double radius = this.X.getXDouble(xlight.Attribute("Radius"));

            if (radius <= 0)
            {
                throw new ArgumentOutOfRangeException("Radius " + radius + " out of range");
            }
            double distance  = this.X.getXDouble(xlight.Attribute("Distance"), 0);
            int    beamcount = this.X.getXInt(xlight.Attribute("RayCount"), this.X.getXInt(xlight.Attribute("BeamCount")));
            //int maxinteractions = this.X.getXInt(xlight.Attribute("MaxInteractions"), 8); //default value max_interactions -> 8
            double minintensity = this.X.getXDouble(xlight.Attribute("MinIntensity"), 0.01);             //default minimum intensity for tracing set to 1%

            Scientrace.Vector   light_direction = this.X.getXVector(xlight.Element("Direction"));
            Scientrace.Location centerloc       = this.X.getXVector(xlight.Element("Location")).toLocation();
            Scientrace.Location locoffset       = (light_direction.negative() * distance).toLocation();     //distance cm above surface
            Scientrace.Location loc             = locoffset + centerloc;
            XMLSpectrumParser   xsp             = new XMLSpectrumParser();

            Scientrace.LightSpectrum spectrum = xsp.parseLightSpectrum(xlight.Element("Spectrum"));

            Scientrace.LightSource retlight = new Scientrace.RandomCircleLightSource(env,
                                                                                     loc, light_direction.tryToUnitVector(),
                                                                                     new Scientrace.Plane(new Scientrace.Location(0, 0, 0), new Scientrace.NonzeroVector(1, 0, 0), new Scientrace.NonzeroVector(0, 0, 1)),
                                                                                     radius, beamcount, spectrum);
            //retlight.max_interactions = maxinteractions;
            retlight.minimum_intensity_fraction = minintensity;
            return(retlight);
        }
        public List <ObjectLinePiece> slice(List <ObjectLinePiece> lps, PlaneBorder aPlaneBorder)
        {
            List <ObjectLinePiece> retSlices = new List <ObjectLinePiece>();

            foreach (ObjectLinePiece anObjectLinePiece in lps)
            {
                Line sectLine = anObjectLinePiece.lp.toLine();
                //Console.WriteLine("FOO"+aPlaneBorder.getNormal().dotProduct(sectLine.direction));
                if (Math.Abs(aPlaneBorder.getNormal().dotProduct(sectLine.direction)) < MainClass.SIGNIFICANTLY_SMALL)
                {
                    //Console.WriteLine("BAR");
                    retSlices.Add(anObjectLinePiece);
                    continue;             // line is within the plane, does not intersect. Continue for iLimitBorder loop
                }
                Scientrace.Location node = aPlaneBorder.lineThroughPlane(sectLine);
                if (node == null)
                {
                    Console.WriteLine("WARNING, NODE=null: " + aPlaneBorder.ToString() + " vs. " + sectLine.ToString());
                    continue;             // somehow the line didn't go through the plane in the end... strange..
                }
                // fill return-list
                retSlices.AddRange(this.toOLP(anObjectLinePiece.lp.sliceIfBetween(node), "0 0.2 0.5 1", anObjectLinePiece.o3d));
            }
            return(retSlices);
        }
Example #6
0
 protected void init_Loc_width_height(Scientrace.Location loc, Scientrace.NonzeroVector u, Scientrace.NonzeroVector v)
 {
     this.parallelogram          = new Scientrace.Parallelogram(loc, u, v);
     this.front_normal_direction = u.crossProduct(v).tryToUnitVector();
     this.preserveSVGRatio();
     this.addSurfaceMarkers();
 }
Example #7
0
 public void init(double sphereRadius, Scientrace.Location loc, Scientrace.Location east, Scientrace.Location south)
 {
     this.loc           = loc;
     this.e             = east;
     this.s             = south;
     this.sphere_radius = sphereRadius;
 }
Example #8
0
 public override Scientrace.Location getSVG2DLoc(Scientrace.Location loc)
 {
     Scientrace.Location loc2d  = this.get2DLoc(loc);
     Scientrace.Location retloc = loc2d.elementWiseProduct(new Scientrace.Vector(this.svgxsize / this.parallelogram.plane.u.length, this.svgysize / this.parallelogram.plane.v.length, 1)).toLocation();
     //Console.WriteLine("Loc: "+loc.trico()+" is 2D'd into: "+retloc.trico()+" x/y="+this.svgxsize+"/"+svgysize);
     return(retloc);
 }
Example #9
0
 /// <summary>
 /// End the trace by setting it no longer alive (and make the next cycle void) ending the trace at a given location.
 /// The trace is stored at the tracejournal as:
 /// * trace
 /// * casualty (via the perishQuietly method)
 /// </summary>
 /// <param name="perishlocation">The location where the current trace is ended.</param>
 public void perish(Scientrace.Location perish_location)
 {
     this.endloc = perish_location;
     Scientrace.TraceJournal tj = TraceJournal.Instance;
     tj.recordTrace(this);
     this.perishQuietly();
 }
Example #10
0
        protected void init_Center_and_Sidelength(Scientrace.Location cellcenterloc, Scientrace.Location pointingto, Scientrace.UnitVector orthogonaldirection,
                                                  double sidelength)
        {
            //Check whether cellcenterloc and pointingto values are different
            if (cellcenterloc.distanceTo(pointingto) == 0)
            {
                throw new ZeroNonzeroVectorException("The location (" + cellcenterloc.ToCompactString() + ") of a Rectangle instance may not be equal to the direction (" + pointingto.ToCompactString() + ") it is pointed towards");
            }

            NonzeroVector cellu, cellv, cellc;

            //define top-cell vector orthogonal to orthogonaldirection and the vectorpoint.
            Scientrace.UnitVector focusdir = (pointingto.toVector() - cellcenterloc.toVector()).tryToUnitVector();
            //Console.WriteLine("POINTINGTO: "+pointingto.trico()+ " focusdir: "+focusdir.trico());
            this.front_normal_direction = focusdir.copy();
            cellu = orthogonaldirection.crossProduct(focusdir).tryToNonzeroVector();
            cellu.normalize();
            //UPDATE 20151102: added "negative" to conserve surface direction after crossproduct operation.
            cellv = cellu.crossProduct(focusdir.negative()).tryToNonzeroVector();
            cellv.normalize();
            cellu = cellu * sidelength;     //surface of cell eq: sidelength * sidelength
            cellv = cellv * sidelength;
            cellc = (cellu + cellv) * 0.5;

            this.parallelogram = new Scientrace.Parallelogram(cellcenterloc - cellc.toLocation(), cellu, cellv);
            this.preserveSVGRatio();
            this.addSurfaceMarkers();
        }
Example #11
0
 public override Scientrace.Location get2DLoc(Scientrace.Location loc)
 {
     //Scientrace.VectorTransformOrthonormal trf = new Scientrace.VectorTransformOrthonormal(this.surface.u, this.surface.v);
     //Scientrace.VectorTransform trf = new Scientrace.VectorTransform(this.surface.u, this.surface.v);
     Scientrace.VectorTransform trf = new Scientrace.VectorTransform(this.parallelogram.plane.u.normalized(), this.parallelogram.plane.v.normalized());
     return(trf.transform(loc - this.parallelogram.plane.loc));
 }
 public InfiniteCylinderBorder(Scientrace.Object3dCollection parent, Scientrace.MaterialProperties mprops,
                               Scientrace.Location loc, Scientrace.UnitVector direction, double radius) : base(parent, mprops)
 {
     this.direction = direction;
     this.radius    = radius;
     this.loc       = loc;
 }
Example #13
0
 public Scientrace.Location constructPlaneNodeLoc(Scientrace.Location planeCenter, double radius,
                                                  double angle, Scientrace.NonzeroVector baseVec1, Scientrace.NonzeroVector baseVec2)
 {
     Scientrace.Vector ix = baseVec1.toVector() * radius * Math.Sin(angle);
     Scientrace.Vector iy = baseVec2.toVector() * radius * Math.Cos(angle);
     return(planeCenter + ix + iy);
 }
        /* interface IBorder3D implementation */
        /// <summary>
        /// Return true when the specified aLocation is contained by the Sphere. If the
        /// </summary>
        /// <param name='aLocation'>
        /// If set to <c>true</c> a location.
        /// </param>
        public bool contains(Scientrace.Location aLocation)
        {
            VectorTransform trf   = this.getTransform();
            Location        trLoc = trf.transform(aLocation - this.loc);

            return(((trLoc.x * trLoc.x) + (trLoc.y * trLoc.y) <= 1) == this.enclosesInside);
        }
Example #15
0
        /// <summary>
        /// Required parameters:
        /// (Location) lens_plano_center,
        /// (double) lens_sphere_radius
        /// (double) lens_sphere_radians_min
        /// (double) lens_sphere_radians_max
        /// (UnitVector) orientation_from_sphere_center
        /// </summary>
        /// <param name='shadowObject'>
        /// Shadow object containing parameters from summary.
        /// </param>
        protected void shadowFac_PlanoCenter_And_Radians(ShadowScientrace.ShadowObject3d shadowObject)
        {
            //User values(s)
            Scientrace.Location lens_plano_center = (Scientrace.Location)shadowObject.getObject("lens_plano_center");
            double lens_sphere_radius             = (double)shadowObject.getObject("lens_sphere_radius");
            double lens_sphere_radians_min        = (double)shadowObject.getObject("lens_sphere_radians_min");
            double lens_sphere_radians_max        = (double)shadowObject.getObject("lens_sphere_radians_max");

            Scientrace.UnitVector orientation_from_sphere_center = (Scientrace.UnitVector)shadowObject.getObject("orientation_from_sphere_center");
            bool double_convex_ring = shadowObject.getNBool("double_convex") == true;

            //Derived value(s)
            Scientrace.Location lens_sphere_location = lens_plano_center -
                                                       (orientation_from_sphere_center * lens_sphere_radius * Math.Cos(lens_sphere_radians_max));

            /*double rmin = Math.Sin(lens_sphere_radians_min)*lens_sphere_radius;
             * double rmax = Math.Sin(lens_sphere_radians_max)*lens_sphere_radius;
             * Console.WriteLine("Ring got radius "+lens_sphere_radius+" at"+lens_sphere_location+" radmin/max:{"+lens_sphere_radians_min+"}/{"+lens_sphere_radians_max+"}.");
             * Console.WriteLine("Ring got rmin/rmax "+rmin+" / "+rmax); */


            //Console.WriteLine("Lens sphere: "+lens_sphere_location.tricon()+" Plano center: "+lens_plano_center.trico());
            //construct!
            this.paramInit(lens_sphere_location, lens_sphere_radius, lens_sphere_radians_min, lens_sphere_radians_max,
                           orientation_from_sphere_center, double_convex_ring);
        }
Example #16
0
 public Sphere(Scientrace.Object3dCollection parent, Scientrace.MaterialProperties mprops,
               Scientrace.Location aLocation, double sphereRadius
               ) : base(parent, mprops)
 {
     this.loc    = aLocation;
     this.radius = sphereRadius;
 }
Example #17
0
        public void setPlaneCenterRadians1Radians2(ref Scientrace.Location planeCenter, ref double radians1, ref double radians2)
        {
            // h1(s) and h2(s) are the (squared) radii of dummySphere1 and dummySphere2
            // the convention "h" is due to the triangle hypothenusa description in figure (REF)
            double h1  = this.sphere1Radius;
            double h2  = this.sphere2Radius;
            double h1s = h1 * h1;
            double h2s = h2 * h2;
            // d is the distance from the center of sphere1 to the center of sphere2
            double d = this.sphere1CenterLoc.distanceTo(this.sphere2CenterLoc);
            // p1 and p2 are the signs which describe whether the center of the sphere lies in between planecenter(H) and the other sphere (-1) or on the other side of H (+1).
            // definition using floating point doubles instead of integers to prevent typecasting
            double p1 = Math.Sign(d - this.sphere2Radius);
            double p2 = Math.Sign(d - this.sphere1Radius);
            // a1 is the distance from sphere1 to planeCenter H.
            double a1 = ((d * d) + h1s - h2s) / (2 * d * p1);
            double a2 = (d - (a1 * p1)) / p2;

            //vD12 is the direction from sphere1 towards sphere2
            Scientrace.UnitVector vD12;
            try {
                vD12 = (this.sphere2CenterLoc - this.sphere1CenterLoc).tryToUnitVector();
            } catch
            { throw new ZeroNonzeroVectorException("Two spheres with equal locations (" +
                                                   this.sphere1CenterLoc.trico() + "/" + this.sphere2CenterLoc.trico() +
                                                   ") where defined within a DoubleConvexLens instance."); }
            planeCenter = this.sphere1CenterLoc + vD12 * a1 * p1;
            radians1    = Math.Acos(a1 * p1 / h1);
            radians2    = Math.Acos(a2 * p2 / h2);
        }
Example #18
0
 public void rotateAboutY(double angle, Scientrace.Location center)
 {
     this.loc    = ((this.loc - center).rotateAboutY(angle)).toLocation() + center;
     this.width  = this.width.rotateAboutY(angle);
     this.length = this.length.rotateAboutY(angle);
     this.height = this.height.rotateAboutY(angle);
     this.trf    = null;
 }
Example #19
0
 public string drawCircle(Scientrace.Location center, double radius, Scientrace.NonzeroVector aboutAxis)
 {
     return
         (this.getX3DTranslationTag(center) +                                                                  //where
          this.getX3DRotationTag(NonzeroVector.z1vector(), aboutAxis) +                                        //what direction
          "<Shape>" + this.emissiveColorAppearance(this.primaryRGB) + "<Circle2D radius='" + radius + "' />" + //what shape
          "</Shape></Transform></Transform>");                                                                 //close tags
 }
Example #20
0
 public Scientrace.Location getXLocation(XElement xparent, string xmlkey, Scientrace.Location aDefLoc)
 {
     if (xparent.Element(xmlkey) == null)
     {
         return(aDefLoc);
     }
     return(this.getXLocation(xparent.Element(xmlkey)));
 }
Example #21
0
 // Constructor: plane, sphereCenterLoc, sphereRadius
 protected DoubleConvexLens(Scientrace.Object3dCollection parent, Scientrace.MaterialProperties mprops,
                            //Scientrace.PlaneBorder lensPlane,
                            Scientrace.Location sphere1CenterLoc, double sphere1Radius,
                            Scientrace.Location sphere2CenterLoc, double sphere2Radius)
     : base(parent, mprops)
 {
     this.paramInit(sphere1CenterLoc, sphere1Radius, sphere2CenterLoc, sphere2Radius);
 }
Example #22
0
 public PlaneBorder(Scientrace.Location loc, Scientrace.NonzeroVector allowedDirectionSurfaceNormal)
 {
     this.loc = loc;
     this.allowedDirNormal = allowedDirectionSurfaceNormal;
     this.radius           = allowedDirectionSurfaceNormal.length;
     this.allowedDirNormal.fillOrtogonalVectors(ref this.planeBaseVec1, ref this.planeBaseVec2);
     this.trf    = this.createNewTransform();
     this.tPlane = new Scientrace.Plane(this.loc, this.planeBaseVec1, this.planeBaseVec2);
 }
 public void PGramAngleTest2()
 {
     Scientrace.Location      loc = new Scientrace.Location(1, 2, 3);
     Scientrace.NonzeroVector v1  = new Scientrace.NonzeroVector(-1, 1, 0);
     Scientrace.NonzeroVector v2  = new Scientrace.NonzeroVector(-1, 0, 1);
     Scientrace.NonzeroVector v3  = new Scientrace.NonzeroVector(1, 1, 1);
     Scientrace.Parallelogram pg  = new Scientrace.Parallelogram(loc, v1, v2);
     Assert.AreEqual(pg.angleOnSurface(v3), 0, 1E-15);
 }
 public void PGramInPath1()
 {
     Scientrace.Location      loc   = new Scientrace.Location(1, 2, 3);
     Scientrace.NonzeroVector v1    = new Scientrace.NonzeroVector(5, 0, 0);
     Scientrace.NonzeroVector v2    = new Scientrace.NonzeroVector(0, 2, 0);
     Scientrace.Parallelogram pg    = new Scientrace.Parallelogram(loc, v1, v2);
     Scientrace.Line          cline = new Scientrace.Line(5.5, 3.5, 0, 0, 0, 5);
     Assert.IsTrue(pg.inPath(cline));
 }
Example #25
0
        public Scientrace.CylindricalBorder getCylindricalBorder(XElement xborder)
        {
            Scientrace.Location      loc    = this.X.getXLocation(xborder.Element("Location"));
            Scientrace.NonzeroVector dirlen = this.X.getXNzVector(xborder.Element("DirectionLength"));
            double radius = this.X.getXDouble(xborder.Attribute("Radius"));

            Scientrace.CylindricalBorder retcyl = new Scientrace.CylindricalBorder(loc, dirlen, radius);
            return(retcyl);
        }
Example #26
0
 public void TrangleInPath1()
 {
     Scientrace.Location loc = new Scientrace.Location(1, 2, 3);
     Scientrace.NonzeroVector v1 = new Scientrace.NonzeroVector(5, 0, 0);
     Scientrace.NonzeroVector v2 = new Scientrace.NonzeroVector(0, 2, 0);
     Scientrace.Triangle pg = new Scientrace.Triangle(loc, v1, v2);
     Scientrace.Line cline = new Scientrace.Line(1.5, 3.5, 0, 0, 0, 5);
     Assert.IsTrue(pg.inPath(cline));
 }
Example #27
0
 public void TrangleInPath1()
 {
     Scientrace.Location      loc   = new Scientrace.Location(1, 2, 3);
     Scientrace.NonzeroVector v1    = new Scientrace.NonzeroVector(5, 0, 0);
     Scientrace.NonzeroVector v2    = new Scientrace.NonzeroVector(0, 2, 0);
     Scientrace.Triangle      pg    = new Scientrace.Triangle(loc, v1, v2);
     Scientrace.Line          cline = new Scientrace.Line(1.5, 3.5, 0, 0, 0, 5);
     Assert.IsTrue(pg.inPath(cline));
 }
Example #28
0
        // Constructor: plane, sphereCenterLoc, sphereRadius
        protected PlanoConvexLens(Scientrace.Object3dCollection parent, Scientrace.MaterialProperties mprops,
			Scientrace.PlaneBorder lensPlane, Scientrace.Location sphereCenterLoc, double sphereRadius)
            : base(parent, mprops)
        {
            this.lensPlane = lensPlane;
            this.sphereCenterLoc = sphereCenterLoc;
            this.sphereRadius = sphereRadius;
            this.dummySphere = new Scientrace.Sphere(null, null, sphereCenterLoc, sphereRadius);
        }
Example #29
0
 public PlaneBorder(Scientrace.Location loc, Scientrace.NonzeroVector allowedDirectionSurfaceNormal)
 {
     this.loc = loc;
     this.allowedDirNormal = allowedDirectionSurfaceNormal;
     this.radius = allowedDirectionSurfaceNormal.length;
     this.allowedDirNormal.fillOrtogonalVectors(ref this.planeBaseVec1, ref this.planeBaseVec2);
     this.trf = this.createNewTransform();
     this.tPlane = new Scientrace.Plane(this.loc, this.planeBaseVec1, this.planeBaseVec2);
 }
Example #30
0
 // Constructor: plane, sphereCenterLoc, sphereRadius
 protected PlanoConvexLens(Scientrace.Object3dCollection parent, Scientrace.MaterialProperties mprops,
                           Scientrace.PlaneBorder lensPlane, Scientrace.Location sphereCenterLoc, double sphereRadius)
     : base(parent, mprops)
 {
     this.lensPlane       = lensPlane;
     this.sphereCenterLoc = sphereCenterLoc;
     this.sphereRadius    = sphereRadius;
     this.dummySphere     = new Scientrace.Sphere(null, null, sphereCenterLoc, sphereRadius);
 }
Example #31
0
 public override Intersection intersects(Trace trace)
 {
     Scientrace.Location intrloc = this.parallelogram.atPath(trace.traceline);
     if (intrloc == null)
     {
         return(new Intersection(false, this));
     }
     return(new Intersection(true, this, intrloc, this.parallelogram, null));
 }
Example #32
0
 public Line(Scientrace.Location startloc, Scientrace.UnitVector dir)
 {
     if (startloc == null)
     throw new ArgumentNullException("startloc");
     if (dir == null)
     throw new ArgumentNullException("dir");
     this.startingpoint = new Location(startloc);
     this.direction = new UnitVector(dir); // dir.copy();
 }
Example #33
0
 public static string get_RGB_Line_XML(Scientrace.Location loc1, Scientrace.Location loc2, string colourRGBstring)
 {
     if (loc1 == null || loc2 == null)
     {
         return("");
     }
     return(@"<!--RGBA_Line--><Shape><LineSet vertexCount='2'><Coordinate point='" + loc2.trico() + " \t" + loc1.trico() + @"' />" +
            "<Color color='" + colourRGBstring + " \t" + colourRGBstring + @"' /></LineSet></Shape>");
 }
Example #34
0
 public void PGramAngleTest2()
 {
     Scientrace.Location loc = new Scientrace.Location(1, 2, 3);
     Scientrace.NonzeroVector v1 = new Scientrace.NonzeroVector(-1, 1, 0);
     Scientrace.NonzeroVector v2 = new Scientrace.NonzeroVector(-1, 0, 1);
     Scientrace.NonzeroVector v3 = new Scientrace.NonzeroVector(1, 1, 1);
     Scientrace.Parallelogram pg = new Scientrace.Parallelogram(loc, v1, v2);
     Assert.AreEqual(pg.angleOnSurface(v3), 0, 1E-15);
 }
Example #35
0
        public double getRadiansSphere2()
        {
            Scientrace.Location planeCenter = null;
            double r1 = 0;
            double r2 = 0;

            this.setPlaneCenterRadians1Radians2(ref planeCenter, ref r1, ref r2);
            return(r2);
        }
Example #36
0
 // Copy constructor
 public IntersectionPoint(IntersectionPoint copyIntersectionPoint)
 {
     this.loc =
     (copyIntersectionPoint.loc == null) ?
     null : new Location(copyIntersectionPoint.loc);
     this.flatshape = copyIntersectionPoint.flatshape;
     /* this.flatshape =
     (copyIntersectionPoint.flatshape == null) ?
     null : new FlatShape2d(copyIntersectionPoint.flatshape); */
 }
Example #37
0
 public Spot(Scientrace.Location loc, Object3d object3d, double intensity, double intensityFraction, Scientrace.Trace trace)
 {
     this.loc = loc;
     this.object3d = object3d;
     this.object3d.spotted(intensity);
     this.intensity = intensity;
     this.intensityFraction = intensityFraction;
     this.trace = trace;
     this.fillPolVecs();
 }
Example #38
0
 public Spot(Scientrace.Spot copyFromSpot)
 {
     this.loc = new Scientrace.Location(copyFromSpot.loc);
     this.object3d = copyFromSpot.object3d;
     // do not spot again, so don't recall spotted from object3d
     this.intensity = copyFromSpot.intensity;
     this.trace = copyFromSpot.trace;
     this.intensityFraction = copyFromSpot.intensityFraction;
     this.fillPolVecs();
 }
Example #39
0
 public void TestRotateAboutCenter()
 {
     Scientrace.Location loc1 = new Scientrace.Location(1, 1, 1);
     Assert.AreEqual(loc1.rotateAboutVector(new Scientrace.NonzeroVector(0,1,0), Math.PI/2).trico(),
     new Scientrace.Location(1,1,-1).trico());
     Assert.AreEqual(
     loc1.rotateAboutVector(new Scientrace.NonzeroVector(0,1,0), new Scientrace.Location(0,1,0), Math.PI/2).trico(),
     new Scientrace.Location(1,1,-1).trico());
     Assert.AreEqual(
     loc1.rotateAboutVector(new Scientrace.NonzeroVector(0,1,0), new Scientrace.Location(0,0,1), Math.PI/2).ToCompactString(),
     new Scientrace.Location(0,1,0).ToCompactString());
     Assert.AreEqual(
     loc1.rotateAboutVector(new Scientrace.NonzeroVector(0,1,0), new Scientrace.Location(1,0,0), Math.PI/2).ToCompactString(),
     new Scientrace.Location(2,1,0).ToCompactString());
 }
Example #40
0
        /*	public Scientrace.Object3d parentObject;*/
        public BoxBorder(Scientrace.Location loc, Scientrace.NonzeroVector width, Scientrace.NonzeroVector height, Scientrace.NonzeroVector length /*, Scientrace.Object3d parentObject*/)
        {
            this.loc = loc;
            this.width = width;
            this.length = length;
            this.height = height;
            /*		this.parentObject = parentObject; */

            //defining the sides of the box
            this.pgrams.Add(new Parallelogram(loc, width, height));
            this.pgrams.Add(new Parallelogram(loc+length, width, height));
            this.pgrams.Add(new Parallelogram(loc, height, length));
            this.pgrams.Add(new Parallelogram(loc+width, height, length));
            this.pgrams.Add(new Parallelogram(loc, width, length));
            this.pgrams.Add(new Parallelogram(loc+height, width, length));
        }
        public void TestRefractionAngleFromVectors()
        {
            Scientrace.UnitVector direction_incoming_trace = new Scientrace.UnitVector(1,0,1);
            Scientrace.Location loc = new Scientrace.Location(0,0,0);
            Scientrace.UnitVector surface_normal = new Scientrace.UnitVector(0,0,1);

            Scientrace.Trace aTrace =  DummyObjects.DummyTrace(600E-9);
                aTrace.traceline.direction = direction_incoming_trace;

            double refindex_from = 1;
            double refindex_to = 1.5;
            Scientrace.DielectricSurfaceInteraction fsi = new Scientrace.DielectricSurfaceInteraction(
                                                        aTrace, loc,
                                                        surface_normal, refindex_from, refindex_to, null);
            //Assert.AreEqual(fsi.dir_in.ToString(), fsi.surface_normal);
            Assert.AreEqual(fsi.dir_s.angleWith(fsi.dir_ip), Math.PI/2);
            Assert.AreEqual(Math.Abs(fsi.amp_ip), Math.Abs(fsi.amp_is), 1E-10);
        }
Example #42
0
 public void PGramIntersectionAtBaseVectors2()
 {
     Scientrace.Location loc = new Scientrace.Location(1, 2, 3);
     Scientrace.NonzeroVector v1 = new Scientrace.NonzeroVector(2, 5, 7);
     Scientrace.NonzeroVector v2 = new Scientrace.NonzeroVector(3, 2, 0);
     Scientrace.Parallelogram pg = new Scientrace.Parallelogram(loc, v1, v2);
     Scientrace.Vector intersection = pg.plane.lineThroughPlane(new Scientrace.Line(1, 1, -1, 2, 2, 2));
     Scientrace.VectorTransform trf = pg.plane.getTransform();
     Scientrace.Vector tintersection = trf.transform(intersection-loc);
     /* when the pgram-plane is shifted through 0,0,0, a transformation of any location in this plane to
      * the base vectors e1 and e2 (based on v1 and v2) should leave a 3rd coordinate set to zero. */
     Assert.AreEqual(tintersection.z, 0, 1E-14);
 }
Example #43
0
 public IntersectionPoint(Scientrace.Location loc, Scientrace.FlatShape2d flatshape)
 {
     this.loc = loc;
     this.flatshape = flatshape;
 }
Example #44
0
 public CylindricalBorder(Scientrace.Location loc, Scientrace.NonzeroVector directionlength, double radius)
 {
     this.radius = radius;
     this.loc = loc;
     this.directionlength = directionlength;
 }
Example #45
0
 /// <summary>
 /// Copy Constructor Initializes a new instance of the <see cref="Scientrace.Plane"/> class.
 /// </summary>
 /// <param name='aPlane'>
 /// A plane instance with the same (copied) values (yet different instances) as parameters.
 /// </param>
 public Plane(Scientrace.Plane aPlane)
 {
     this.loc = aPlane.loc.copy();
     this.u = aPlane.u.copy();
     this.v = aPlane.v.copy();
 }
Example #46
0
 public Plane(Scientrace.Location loc, Scientrace.NonzeroVector u, Scientrace.NonzeroVector v)
 {
     this.loc = loc;
     this.u = u;
     this.v = v;
 }
Example #47
0
 public void PGramLineIntersects()
 {
     Scientrace.Location loc = new Scientrace.Location(1, 2, 3);
     Scientrace.NonzeroVector v1 = new Scientrace.NonzeroVector(1, 0, 0);
     Scientrace.NonzeroVector v2 = new Scientrace.NonzeroVector(0, 1, 0);
     Scientrace.Parallelogram pg = new Scientrace.Parallelogram(loc, v1, v2);
     //this line intersects the defined plane at (5,5,3)
     Scientrace.Vector intersection = pg.plane.lineThroughPlane(new Scientrace.Line(1, 1, -1, 2, 2, 2));
     Assert.AreEqual(intersection.x, 5);
     Assert.AreEqual(intersection.y, 5);
     Assert.AreEqual(intersection.z, 3);
 }
Example #48
0
 public Line(Line copyLine)
 {
     this.startingpoint = new Location(copyLine.startingpoint);
     this.direction = new UnitVector(copyLine.direction);
 }
Example #49
0
 // Place the startingpiont "distance" back in space along the direction of the line.
 public void rewind(double distance)
 {
     this.startingpoint = this.startingpoint - (this.direction.toVector()*distance);
 }
Example #50
0
 public void PGramInPath1()
 {
     Scientrace.Location loc = new Scientrace.Location(1, 2, 3);
     Scientrace.NonzeroVector v1 = new Scientrace.NonzeroVector(5, 0, 0);
     Scientrace.NonzeroVector v2 = new Scientrace.NonzeroVector(0, 2, 0);
     Scientrace.Parallelogram pg = new Scientrace.Parallelogram(loc, v1, v2);
     Scientrace.Line cline = new Scientrace.Line(5.5, 3.5, 0, 0, 0, 5);
     Assert.IsTrue(pg.inPath(cline));
 }
Example #51
0
 public Line(double x, double y, double z, double dirx, double diry, double dirz)
 {
     this.startingpoint = new Scientrace.Location(x, y, z);
     this.direction = new Scientrace.UnitVector(dirx, diry, dirz);
 }
Example #52
0
 public void init(double sphereRadius, Scientrace.Location loc, Scientrace.Location east, Scientrace.Location south)
 {
     this.loc = loc;
     this.e = east;
     this.s = south;
     this.sphere_radius = sphereRadius;
 }
Example #53
0
        protected void paramInit(Scientrace.Location sphere1CenterLoc, double sphere1Radius,
		Scientrace.Location sphere2CenterLoc, double sphere2Radius)
        {
            //this.lensPlane = lensPlane;
            this.sphere1CenterLoc = sphere1CenterLoc;
            this.sphere2CenterLoc = sphere2CenterLoc;
            this.sphere2Radius = sphere2Radius;
            this.sphere1Radius = sphere1Radius;
            this.dummySphere1 = new Scientrace.Sphere(null, null, sphere1CenterLoc, sphere1Radius);
            this.dummySphere2 = new Scientrace.Sphere(null, null, sphere2CenterLoc, sphere2Radius);
        }
Example #54
0
 public void TestDistance()
 {
     Scientrace.Location loc1 = new Scientrace.Location(1, 1, 1);
     Scientrace.Location loc2 = new Scientrace.Location(4, 5, 6);
     Assert.AreEqual(loc1.distanceTo(loc2), Math.Sqrt(50));
 }
Example #55
0
 public void rotateAboutY(double angle, Scientrace.Location center)
 {
     this.loc = ((this.loc - center).rotateAboutY(angle)).toLocation()+center;
     this.width = this.width.rotateAboutY(angle);
     this.length = this.length.rotateAboutY(angle);
     this.height = this.height.rotateAboutY(angle);
     this.trf = null;
 }
Example #56
0
        public void paramInit(Scientrace.Location center, 
		                         Scientrace.UnitVector direction, Scientrace.Plane plane, int linecount,
		                         double radius, double loops, double distance)
        {
            this.loops = loops;
            this.radius = radius;
            this.center = center;
            //direction had been commented out. WHY? Re-enabled.
            this.direction = direction;
            this.spiral_plane = plane;
            this.tag = String.Format("{0:0.###}",loops)+"LoopSpiral";
            this.distance = distance;
            //added later:
            this.linecount = linecount;
            //and removed again:
            //this.spectrum = spectrum;
        }