コード例 #1
0
        public ParallelRandomSquareLightSource(ShadowScientrace.ShadowLightSource shadowObject)
            : base(shadowObject)
        {
            int? random_seed = shadowObject.getNInt("random_seed");
            Scientrace.Location location = shadowObject.getLocation("location"); //corner
            Scientrace.UnitVector direction = shadowObject.getUnitVector("direction");
            int ray_count = shadowObject.getInt("ray_count"); //linecount,
            this.distance = shadowObject.getDouble("distance", 0);//distance,

            //This line has been moved to the LightSource parent shadowconstructor
            //Scientrace.LightSpectrum spectrum = (Scientrace.LightSpectrum)shadowObject.getObject("spectrum"); //spectrum

            Scientrace.Vector width = shadowObject.getVector("width");//urange,
            Scientrace.Vector height = shadowObject.getVector("height");//vrange,

            Random randNum;
            if (random_seed == null || random_seed== -1)
            randNum = new Random();
            else
            randNum = new Random((int)random_seed);

            for (int iline = 0; iline < ray_count; iline++) {
            Scientrace.Line line = new Scientrace.Line(location+(width*randNum.NextDouble()+(height*randNum.NextDouble())).toLocation(), direction);
            // THIS IS BEING DONE BY THE PARENT LIGHTSOURCE CLASS ALREADY: line.startingpoint = line.startingpoint - (direction.toLocation()*distance);
            Scientrace.Trace newtrace = new Scientrace.Trace(spectrum.wl(iline), this, line, env, spectrum.it(iline), spectrum.it(iline));
            newtrace.traceid = "RS"+(random_seed==null?"r":random_seed.ToString())+"-"+iline;
            this.addTrace(newtrace);
            } //end for
        }
コード例 #2
0
        public RandomCircleLightSource(Scientrace.Object3dEnvironment env, Scientrace.Location center, Scientrace.UnitVector direction, 
									Scientrace.Plane plane, double radius, int linecount, LightSpectrum spectrum)
            : base(env)
        {
            //this.direction = direction;
            Random randNum = new Random();
            Scientrace.UnitVector urange, vrange;
            double r1, r2;
            urange = plane.u.toUnitVector();
            vrange = plane.v.toUnitVector();
            Scientrace.Line line;
            for (int iline = 0; iline < linecount; iline++) {
            //Scientrace.Line line = new Scientrace.Line(loc+(urange*randNum.NextDouble()+(vrange*randNum.NextDouble())).toLocation(), direction);
            r1 = 1-randNum.NextDouble()*2;
            r2 = 1-randNum.NextDouble()*2;
            if (Math.Pow(r1,2)+Math.Pow(r2,2)<1) {
                line = new Scientrace.Line(center+((urange*r1*radius)+(vrange*r2*radius)).toLocation(),direction);
                } else {
                iline--;
                continue;
                }
            //this.traces.Add(new Scientrace.Trace(wavelength*0.6, this, line, env));
            //this.traces.Add(new Scientrace.Trace(wavelength*0.8, this, line, env));
            //double wavelength = wlmin+(randNum.NextDouble()*(wlmax-wlmin));
            double wavelength = spectrum.wl(iline);
            double intensity = spectrum.it(iline);
            Console.WriteLine("Warning: ParallelRandomCylindricalLightSource does not use modulo yet");
            this.addTrace(new Scientrace.Trace(wavelength, this, line, env, intensity, intensity));
            //this.traces.Add(new Scientrace.Trace(wavelength*1.2, this, line, env));
            //this.traces.Add(new Scientrace.Trace(wavelength*1.4, this, line, env));
            }
        }
コード例 #3
0
        public void TestFailingRealIntersections()
        {
            Scientrace.Object3dEnvironment env = DummySources.dEnv();
            Scientrace.CylindricalBorder cb = new Scientrace.CylindricalBorder(new Scientrace.Location(0, -0.07, 0), new Scientrace.NonzeroVector(0, -0.57, 0), 0.5);
            Scientrace.ParabolicMirror pm = new Scientrace.ParabolicMirror(env
            , Scientrace.PerfectMirror.Instance, new Scientrace.Location(0.354861881099294, -0.57, 0.276718350209505)
            ,  new Scientrace.UnitVector(-0.343710964996787, 0.900014703397015, -0.268022958363946), 2, cb);
            Scientrace.Line tl = new Scientrace.Line(-0.184140645666577, -0.0383229578843359, -0.3, 0.343710966184079, -0.900014705907235, 0.268022948412108);

            //		pm.trf.transform(tl);
            //		Scientrace.IntersectionPoint[] tips = pm.realIntersections(tl);
            //Assert.AreEqual(new Scientrace.Location(0,0,0), tips[0].loc);

            Scientrace.VectorTransform trf = pm.trf;
            Scientrace.Line trfline = trf.transform(tl-pm.loc);
                    //transform location AND direction
            Scientrace.IntersectionPoint[] ips = pm.baseintersections(trfline);
            //Scientrace.IntersectionPoint tip;
            Scientrace.IntersectionPoint[] retips = new Scientrace.IntersectionPoint[2];
            for (int ipi = 0; ipi < ips.GetLength(0); ipi++) {
                if (ips[ipi] == null) {
                    retips[ipi] = null;
                    continue;
                }

                //check below removed for performance reasons
                if (!trfline.throughLocation(ips[ipi].loc, 0.00001)) {
                    string warning =@"ERROR: GOING DOWN! \n baseintersections "+trfline+" FAILED!";
                    throw new ArgumentOutOfRangeException(warning+ips[ipi].loc.trico() + " not in line " + trfline);
                }
            }
        }
コード例 #4
0
ファイル: SingleRaySource.cs プロジェクト: JoepBC/scientrace
 public SingleRaySource(Scientrace.Line rayline, int raycount, LightSpectrum spectrum, Scientrace.Object3dEnvironment env)
     : base(env)
 {
     this.weighted_intensity = spectrum.total_intensity;
     this.spectrum = spectrum;
     this.linecount = raycount;
     this.ray = rayline;
 }
コード例 #5
0
ファイル: TriangleTest.cs プロジェクト: JoepBC/scientrace
 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));
 }
コード例 #6
0
 public ParallelSquareLightSource(Scientrace.Object3dEnvironment env, Scientrace.Location cloc, Scientrace.UnitVector direction, Scientrace.NonzeroVector u, Scientrace.NonzeroVector v, int ucount, int vcount, double wavelength)
     : base(env)
 {
     Scientrace.Location loc = (cloc - ((u*(ucount-1)*0.5)+(v*(vcount-1)*0.5))).toLocation();
     for (int iu = 0; iu < ucount; iu++) {
     for (int iv = 0; iv < vcount; iv++) {
             //Console.WriteLine("New line at "+(loc+((u.toVector()*iu)+(v.toVector()*iv)).toLocation()).trico());
             Scientrace.Line line = new Scientrace.Line(loc+((u.toVector()*iu)+(v.toVector()*iv)).toLocation(), direction);
             this.addTrace(new Scientrace.Trace(wavelength, this, line, env,1,1));
     }
     }
 }
コード例 #7
0
ファイル: Line.cs プロジェクト: JoepBC/scientrace
        public Line reflectOnSurface(Scientrace.NonzeroVector norm, double offset)
        {
            //copy constructor
            Scientrace.Line retline = new Scientrace.Line(this);

            //the direction of the reflected line
            retline.direction = this.direction.reflectOnSurface(norm);

            //after reflecting "jump" wavelength ahead not to keep reflecting at same point.
            retline.startingpoint = (this.startingpoint+retline.direction.toVector()*offset).toLocation();

            return retline;
        }
コード例 #8
0
ファイル: IntersectionTest.cs プロジェクト: JoepBC/scientrace
 public void TestIntersectionByVectorArray3()
 {
     Scientrace.Object3dEnvironment env = new Scientrace.Object3dEnvironment(Scientrace.AirProperties.Instance, 100);
     Scientrace.Line beam = new Scientrace.Line(10, 10, 10, -1, -1, 0);
     Scientrace.LightSource light = new Scientrace.SingleRaySource(beam,
                                                                  10, new Scientrace.AM15Spectrum(1), env);
     Scientrace.Trace trace = new Scientrace.Trace(500.0E-9, light, beam, env,1,1);
     Console.WriteLine(trace.ToString());
     //Scientrace.Vector v = new Scientrace.Vector(10,10,10);
     Scientrace.IntersectionPoint[] ips = new Scientrace.IntersectionPoint[2];
     ips[0] = null;
     ips[1] = null;
     //Scientrace.Intersection intr = new Scientrace.Intersection(trace, ips);
     //Assert.IsFalse(intr.intersects);
 }
コード例 #9
0
        public RandomCircleLightSource(ShadowScientrace.ShadowLightSource shadowObject)
            : base(shadowObject)
        {
            int? random_seed = shadowObject.getNInt("random_seed");
            Scientrace.Location location = shadowObject.getLocation("location"); //corner
            Scientrace.UnitVector direction = shadowObject.getUnitVector("direction");
            Scientrace.UnitVector normal = shadowObject.getUnitVector("normal");
            // if normal is not defined, use the beam direction as the surface normal.
            if (normal == null) normal = direction;
            int ray_count = shadowObject.getInt("ray_count"); //linecount,
            this.distance = shadowObject.getDouble("distance", 0);//distance,

            //This line has been moved to the LightSource parent shadowconstructor
            //Scientrace.LightSpectrum spectrum = (Scientrace.LightSpectrum)shadowObject.getObject("spectrum"); //spectrum

            double radius = shadowObject.getDouble("radius");//urange,

            Random randNum;
            if (random_seed == null || random_seed== -1)
            randNum = new Random();
            else
            randNum = new Random((int)random_seed);

            Scientrace.Plane plane = Scientrace.Plane.newPlaneOrthogonalTo(location, normal);
            Scientrace.UnitVector urange, vrange;
            double r1, r2;
            urange = plane.u.toUnitVector();
            vrange = plane.v.toUnitVector();
            Scientrace.Line line;
            for (int iline = 0; iline < ray_count; iline++) {
            r1 = 1-randNum.NextDouble()*2;
            r2 = 1-randNum.NextDouble()*2;
            if (Math.Pow(r1,2)+Math.Pow(r2,2)<1) {
                line = new Scientrace.Line(location+((urange*r1*radius)+(vrange*r2*radius)).toLocation(),direction);
                // THIS IS BEING DONE BY THE PARENT LIGHTSOURCE CLASS ALREADY: line.startingpoint = line.startingpoint - (direction.toLocation()*distance);
                } else {
                iline--;
                continue;
                }
            double wavelength = spectrum.wl(iline);
            double intensity = spectrum.it(iline);
            Scientrace.Trace newtrace = new Scientrace.Trace(wavelength, this, line, env, intensity, intensity);
            newtrace.traceid = "RS"+(random_seed==null?"r":random_seed.ToString())+"-"+iline;
            this.addTrace(newtrace);
            }
        }
コード例 #10
0
        public void Testbaseintersection1()
        {
            Scientrace.Object3dEnvironment env = new Scientrace.Object3dEnvironment(Scientrace.AirProperties.Instance, 100);

            /*		Scientrace.CylindricalBorder cbord = new Scientrace.CylindricalBorder(
                                            new Scientrace.Location(0,0,0),
                                            new Scientrace.NonzeroVector(0,0,10), 20);*/
            Scientrace.CylindricalBorder cborder = new Scientrace.CylindricalBorder(
            new Scientrace.Location(-10,10,-10),
            new Scientrace.NonzeroVector(-1,-1,0),5);

            Scientrace.ParabolicMirror pm = new Scientrace.ParabolicMirror(env, Scientrace.PerfectMirror.Instance,
                                                                        new Scientrace.Location(0,1,0),
                                                                        new Scientrace.UnitVector(0,0,1),
                                                                        1, cborder);
            Scientrace.Line traceline = new Scientrace.Line(2,0,0,0,1,4);
            Scientrace.IntersectionPoint[] intr = pm.baseintersections(traceline);
            Assert.AreEqual(true, traceline.throughLocation(intr[0].loc, 0.0001));
            Assert.AreEqual(new Scientrace.Location(2,2,8) ,intr[0].loc);
        }
コード例 #11
0
        public RandomCircleLightSource(Scientrace.Object3dEnvironment env, Scientrace.Location center, Scientrace.UnitVector direction,
                                       Scientrace.Plane plane, double radius, int linecount, LightSpectrum spectrum) : base(env)
        {
            //this.direction = direction;
            Random randNum = new Random();

            Scientrace.UnitVector urange, vrange;
            double r1, r2;

            urange = plane.u.toUnitVector();
            vrange = plane.v.toUnitVector();
            Scientrace.Line line;
            for (int iline = 0; iline < linecount; iline++)
            {
                //Scientrace.Line line = new Scientrace.Line(loc+(urange*randNum.NextDouble()+(vrange*randNum.NextDouble())).toLocation(), direction);
                r1 = 1 - randNum.NextDouble() * 2;
                r2 = 1 - randNum.NextDouble() * 2;
                if (Math.Pow(r1, 2) + Math.Pow(r2, 2) < 1)
                {
                    line = new Scientrace.Line(center + ((urange * r1 * radius) + (vrange * r2 * radius)).toLocation(), direction);
                }
                else
                {
                    iline--;
                    continue;
                }
                //this.traces.Add(new Scientrace.Trace(wavelength*0.6, this, line, env));
                //this.traces.Add(new Scientrace.Trace(wavelength*0.8, this, line, env));
                //double wavelength = wlmin+(randNum.NextDouble()*(wlmax-wlmin));
                double wavelength = spectrum.wl(iline);
                double intensity  = spectrum.it(iline);
                Console.WriteLine("Warning: ParallelRandomCylindricalLightSource does not use modulo yet");
                this.addTrace(new Scientrace.Trace(wavelength, this, line, env, intensity, intensity));
                //this.traces.Add(new Scientrace.Trace(wavelength*1.2, this, line, env));
                //this.traces.Add(new Scientrace.Trace(wavelength*1.4, this, line, env));
            }
        }
コード例 #12
0
        public ParallelRandomSquareLightSource(ShadowScientrace.ShadowLightSource shadowObject) : base(shadowObject)
        {
            int?random_seed = shadowObject.getNInt("random_seed");

            Scientrace.Location   location  = shadowObject.getLocation("location"); //corner
            Scientrace.UnitVector direction = shadowObject.getUnitVector("direction");
            int ray_count = shadowObject.getInt("ray_count");                       //linecount,

            this.distance = shadowObject.getDouble("distance", 0);                  //distance,

            //This line has been moved to the LightSource parent shadowconstructor
            //Scientrace.LightSpectrum spectrum = (Scientrace.LightSpectrum)shadowObject.getObject("spectrum"); //spectrum

            Scientrace.Vector width  = shadowObject.getVector("width");   //urange,
            Scientrace.Vector height = shadowObject.getVector("height");  //vrange,

            Random randNum;

            if (random_seed == null || random_seed == -1)
            {
                randNum = new Random();
            }
            else
            {
                randNum = new Random((int)random_seed);
            }

            for (int iline = 0; iline < ray_count; iline++)
            {
                Scientrace.Line line = new Scientrace.Line(location + (width * randNum.NextDouble() + (height * randNum.NextDouble())).toLocation(), direction);
                // THIS IS BEING DONE BY THE PARENT LIGHTSOURCE CLASS ALREADY: line.startingpoint = line.startingpoint - (direction.toLocation()*distance);
                Scientrace.Trace newtrace = new Scientrace.Trace(spectrum.wl(iline), this, line, env, spectrum.it(iline), spectrum.it(iline));
                newtrace.traceid = "RS" + (random_seed == null?"r":random_seed.ToString()) + "-" + iline;
                this.addTrace(newtrace);
            }     //end for
        }         //end void oldParamInit
コード例 #13
0
        public RandomCircleLightSource(ShadowScientrace.ShadowLightSource shadowObject) : base(shadowObject)
        {
            int?random_seed = shadowObject.getNInt("random_seed");

            Scientrace.Location   location  = shadowObject.getLocation("location");  //corner
            Scientrace.UnitVector direction = shadowObject.getUnitVector("direction");
            Scientrace.UnitVector normal    = shadowObject.getUnitVector("normal");
            // if normal is not defined, use the beam direction as the surface normal.
            if (normal == null)
            {
                normal = direction;
            }
            int ray_count = shadowObject.getInt("ray_count");      //linecount,

            this.distance = shadowObject.getDouble("distance", 0); //distance,

            //This line has been moved to the LightSource parent shadowconstructor
            //Scientrace.LightSpectrum spectrum = (Scientrace.LightSpectrum)shadowObject.getObject("spectrum"); //spectrum

            double radius = shadowObject.getDouble("radius");    //urange,

            Random randNum;

            if (random_seed == null || random_seed == -1)
            {
                randNum = new Random();
            }
            else
            {
                randNum = new Random((int)random_seed);
            }


            Scientrace.Plane      plane = Scientrace.Plane.newPlaneOrthogonalTo(location, normal);
            Scientrace.UnitVector urange, vrange;
            double r1, r2;

            urange = plane.u.toUnitVector();
            vrange = plane.v.toUnitVector();
            Scientrace.Line line;
            for (int iline = 0; iline < ray_count; iline++)
            {
                r1 = 1 - randNum.NextDouble() * 2;
                r2 = 1 - randNum.NextDouble() * 2;
                if (Math.Pow(r1, 2) + Math.Pow(r2, 2) < 1)
                {
                    line = new Scientrace.Line(location + ((urange * r1 * radius) + (vrange * r2 * radius)).toLocation(), direction);
                    // THIS IS BEING DONE BY THE PARENT LIGHTSOURCE CLASS ALREADY: line.startingpoint = line.startingpoint - (direction.toLocation()*distance);
                }
                else
                {
                    iline--;
                    continue;
                }
                double           wavelength = spectrum.wl(iline);
                double           intensity  = spectrum.it(iline);
                Scientrace.Trace newtrace   = new Scientrace.Trace(wavelength, this, line, env, intensity, intensity);
                newtrace.traceid = "RS" + (random_seed == null?"r":random_seed.ToString()) + "-" + iline;
                this.addTrace(newtrace);
            }
        }
コード例 #14
0
        public Trace getRefractTrace(double offset)
        {
            // If the trace has ended due to total absorption, there's no either.
            if (this.total_absorption) return null;

            // At total internel reflection, there's no refraction either (statements split up for readability purposes).
            if (this.total_internal_reflection) return null;

            Scientrace.Line refract_line = new Scientrace.Line(this.interaction_loc + (this.dir_t.toVector()*offset), this.dir_t);

            double refr_intensity = (this.intensity_after_absorption/this.intensity_in) *
                        ((Math.Pow(this.amp_is,2) + Math.Pow(this.amp_ip,2))-(Math.Pow(this.amp_rs,2) + Math.Pow(this.amp_rp,2)) );

            Scientrace.Trace refract_trace =
                    trace_in.fork(refract_line, (this.dir_s.toVector()*this.amp_ts), (this.dir_tp.toVector()*this.amp_tp),
                                    refr_intensity, "_t");
            refract_trace.currentObject = this.object_to;

            // Don't bother with empty traces.
            if (refract_trace.isEmpty()) return null;

            return refract_trace;
        }
コード例 #15
0
        public Trace getReflectTrace(double offset)
        {
            // If the trace has ended due to total absorption, there's no reflection.
            if (this.total_absorption) return null;

            // Construct the new trace line
            Scientrace.Line reflect_line = new Scientrace.Line(this.interaction_loc + (this.dir_r.toVector()*offset), this.dir_r);

            double new_intensity = (this.intensity_after_absorption/this.intensity_in) *
                        (Math.Pow(this.amp_rs,2) + Math.Pow(this.amp_rp,2));

            // Sometimes, this new intensity is to small to care about. Return null.
            if (new_intensity <= MainClass.SIGNIFICANTLY_SMALL) {
                //Console.WriteLine("New intensity is: "+new_intensity+" is:"+this.amp_is+" ip:"+this.amp_ip+" ts:"+this.amp_ts+" tp:"+this.amp_tp);
                return null;
                }

            Scientrace.Trace reflect_trace =
                    trace_in.fork(reflect_line, (this.dir_s.toVector()*this.amp_rs), (this.dir_rp.toVector()*this.amp_rp),
                                    new_intensity, (this.total_internal_reflection?"_fr":"_r"));

            // Remain within the same object / space
            reflect_trace.currentObject = this.trace_in.currentObject;

            // Don't bother with empty traces.
            if (reflect_trace.isEmpty()) return null;

            return reflect_trace;
        }
コード例 #16
0
ファイル: PlanoConvexLens.cs プロジェクト: JoepBC/scientrace
 public Scientrace.Location planoCenterLoc()
 {
     Scientrace.Line sphereLine = new Scientrace.Line(this.sphereCenterLoc, this.lensPlane.getNormal());
     return this.lensPlane.intersectsAt(sphereLine);
 }
コード例 #17
0
        public List <LinePiece> getBorderEdges()
        {
            int AN_AWFUL_LOT_OF_BORDERS = 50;
            List <LinePiece> lpList     = new List <LinePiece>();

            if (this.borders.Count >= AN_AWFUL_LOT_OF_BORDERS)
            {
                Console.WriteLine("WARNING: Iterating through " + this.borders.Count + "^2 (=" + Math.Pow(this.borders.Count, 2) + ") borders");
                Console.Write("Parsing border: ");
            }
            // Iterate through all borders
            for (int iBorder = 0; iBorder < this.borders.Count; iBorder++)
            {
                if (this.borders.Count >= AN_AWFUL_LOT_OF_BORDERS)
                {
                    Console.Write(iBorder.ToString() + " - ");
                }
                // Find interactions with all remaining borders
                for (int iOtherBorder = iBorder; iOtherBorder < this.borders.Count; iOtherBorder++)
                {
                    // But only as long these borders are not parallel
                    if (this.borders[iBorder].isParallelTo(this.borders[iOtherBorder]))
                    {
                        continue;
                    }

                    // Calculate the line where both iterated border-planes intersect
                    Scientrace.Line sectLine = this.borders[iBorder].getIntersectionLineWith(this.borders[iOtherBorder]);
                    if (sectLine == null)
                    {
                        continue;
                    }
                    // Build a list of location nodes
                    List <Scientrace.Location> validNodes = new List <Scientrace.Location>();

                    // Find the edges
                    for (int iLimitBorder = 0; iLimitBorder < this.borders.Count; iLimitBorder++)
                    {
                        if ((iLimitBorder == iBorder) || (iLimitBorder == iOtherBorder))
                        {
                            continue;                     //planes can never limit a line that's within the plane
                        }
                        if (Math.Abs(this.borders[iLimitBorder].getNormal().dotProduct(sectLine.direction)) < MainClass.SIGNIFICANTLY_SMALL)
                        {
                            continue;                     // line is within the plane, does not intersect. Continue for iLimitBorder loop
                        }
                        Scientrace.Location node = this.borders[iLimitBorder].lineThroughPlane(sectLine);
                        if (node == null)
                        {
                            Console.WriteLine("WARNING, NODE=null: " + this.borders[iLimitBorder].ToString() + " vs. " + sectLine.ToString());
                            continue;                     // somehow the line didn't go through the plane in the end...
                        }
                        bool checkNode = true;
                        for (int iCheckNodeBorder = 0; iCheckNodeBorder < this.borders.Count; iCheckNodeBorder++)
                        {
                            if ((iCheckNodeBorder == iBorder) || (iCheckNodeBorder == iOtherBorder) || (iCheckNodeBorder == iLimitBorder))
                            {
                                continue;
                            }
                            if (!this.borders[iCheckNodeBorder].contains(node, MainClass.SIGNIFICANTLY_SMALL))
                            {
                                checkNode = false;
                            }
                        }                         // end for iCheckNodeBorder
                        if (checkNode)
                        {
                            node.addToListIfNew(validNodes);
                        }
                    }                     // end for iLimitBorder
                    if (validNodes.Count == 2)
                    {
                        lpList.Add(new LinePiece(validNodes[0], validNodes[1]));
                    }
                    // else //SHH this one, an enclosedvolume can also exist from parallel borders, e.g. a cube.
                    if (validNodes.Count > 2)
                    {
                        Console.WriteLine("WARNING: " + validNodes.Count + " validNodes found." + MainClass.SIGNIFICANTLY_SMALL);
                        foreach (Location aNode in validNodes)
                        {
                            Console.WriteLine("anode: " + aNode.ToString());
                        }
                    }
                }         // end for iOtherBorder
            }             // end for iBorder
            return(lpList);
        }
コード例 #18
0
        public override string exportX3D(Scientrace.Object3dEnvironment env)
        {
            int steps = this.exportX3Dgridsteps;

            Scientrace.AbstractGridBorder cborder = this.cborder;
//		Scientrace.VectorTransform cbordertrf = cborder.getTransform();
            //Generate a rotating grid!
            Scientrace.VectorTransform cbordertrf = cborder.getGridTransform(this.zaxis);
            //Console.WriteLine("CBTRFcp: "+cbordertrf.ToCompactString());

            /*
             * stloc: starting location actually representing the center of the border,
             * from there in the orthonormal direction of this border the collision points with
             * the parabolic mirror will be found (from -radius to +radius in both transform-directions
             */
            Scientrace.Location            stloc = cborder.getOrthoStartCenterLoc();// - cborder.getOthoDirection();
            Scientrace.IntersectionPoint[] iparr, iparre, iparrs;
            Scientrace.Intersection        cintr, eintr, sintr;

            /*
             * eloc is the location "east" of the current node, sloc "south" for drawing a grid
             * of course are terms east and south symbolic
             */
            Scientrace.Location eloc, sloc;
            Scientrace.Line     cline, eline, sline;
            //double r = cborder.getRadius();
            double r1 = cborder.getURadius();
            double r2 = cborder.getVRadius();

            Scientrace.Vector v1     = cbordertrf.u.tryToUnitVector().toVector();
            Scientrace.Vector v2     = cbordertrf.v.tryToUnitVector().toVector();;
            string            retstr = "";

            Scientrace.X3DGridPoint concentrationpoint = new Scientrace.X3DGridPoint(env, this.getConcentrationPoint(), null, null);
            retstr  = concentrationpoint.x3DSphere(env.radius / 1000, "1 0 1", 0.5);
            retstr += concentrationpoint.x3DLineTo(this.loc, "1 0 1 1");
            for (double ix = 0.5; ix < steps; ix++)
            {
                for (double iy = 0.5; iy <= steps; iy++)
                {
                    /* Drawing a grid of lines in direction "border.orthodirection" to ParabolicMirror,
                     * at every intersection a gridpoint is located. "cline" are those ortho-dir lines */
                    cline = new Scientrace.Line(((stloc - (v1 * r1) - (v2 * r2)) + (v1 * (r1 * 2 * (ix / steps))) + (v2 * (r2 * 2 * (iy / steps)))).toLocation(),
                                                cborder.getOrthoDirection());
//											cborder.directionlength.toUnitVector());

                    /* USE THE "checkborder = false" function below to always
                     * show the grid-points, also outside borders
                     * iparr is the IntersectionPoint at the Parabolic Mirror for the current ix/iy iteration */
                    iparr = this.realIntersections(cline, true);

/* DEBUG INFO	foreach (IntersectionPoint ip in iparr) {
 *                                      if (ip!=null) {
 *                                              Console.WriteLine("IP AT: "+ip.ToString());
 *                                              } else {
 *                                              Console.WriteLine("NO IP FROM: "+((stloc-(v1*r)-(v2*r))+(v1*(r*2*(ix/steps)))+(v2*(r*2*(iy/steps))))
 +" AND "+cborder.getOrthoDirection());
 *                                              }
 *                                      }*/
                    eline = new Scientrace.Line(((stloc - (v1 * r1) - (v2 * r2)) + (v1 * (r1 * 2 * ((ix + 1) / steps))) + (v2 * (r2 * 2 * (iy / steps)))).toLocation(),
                                                cborder.getOrthoDirection());
//											cborder.directionlength.toUnitVector());
                    iparre = this.realIntersections(eline, true);
                    //defining "east" neighbour
                    eintr = new Intersection(eline, iparre, this);
                    if (eintr.intersects)
                    {
                        eloc = eintr.enter.loc;
                    }
                    else
                    {
                        eloc = null;
                    }
                    sline = new Scientrace.Line(((stloc - (v1 * r1) - (v2 * r2)) + (v1 * (r1 * 2 * ((ix) / steps))) + (v2 * (r2 * 2 * ((iy + 1) / steps)))).toLocation(),
                                                cborder.getOrthoDirection());
//											cborder.directionlength.toUnitVector());
                    iparrs = this.realIntersections(sline, true);
                    //defining "south" neighbour
                    sintr = new Intersection(sline, iparrs, this);
                    if (sintr.intersects)
                    {
                        sloc = sintr.enter.loc;
                    }
                    else
                    {
                        sloc = null;
                    }

                    /* "central" point
                     * where does line "cline" with intersections "iparr" intersect this object?
                     */
                    cintr = new Intersection(cline, iparr, this, true);
                    if (cintr.intersects)               //add existing gridpoints
                    {
                        if (this.x3dgridspheres)
                        {
                            retstr = retstr + new X3DGridPoint(env, cintr.enter.loc, eloc, sloc).exportX3D();
                        }
                        else
                        {
                            retstr = retstr + new X3DGridPoint(env, cintr.enter.loc, eloc, sloc).exportX3DnosphereRGBA("0 0 1 1");
                        }
                    }
                }
            }
            //Console.WriteLine("!!!"+retstr);
            return(retstr + cborder.exportX3D(env));
        }
コード例 #19
0
        /// <summary>
        /// "line" has to be transformed so it encounters the 2nd order polynominal with
        /// its base at 0,0,0 and orientation in 0,0,1 (z-direction)
        /// </summary>
        /// <param name="line">
        /// A <see cref="Scientrace.Line"/>
        /// </param>
        public IntersectionPoint[] baseintersections(Scientrace.Line line)
        {
            // location = line.loc * (d * line.dir);
            // keep formulae readable
            double d1, d2, dx, dy, dz, c, lx, ly, lz;
            double ABCa, ABCb, ABCc, discr;

            Scientrace.Vector v1, v2;
            Scientrace.IntersectionPoint[] ip;
            c  = this.c;
            dx = line.direction.x;
            dy = line.direction.y;
            dz = line.direction.z;
            lx = line.startingpoint.x;
            ly = line.startingpoint.y;
            lz = line.startingpoint.z;

            ABCa = c * (Math.Pow(dy, 2) + Math.Pow(dx, 2));
            ABCb = (2 * c * (dy * ly + dx * lx)) - dz;
            ABCc = (c * (Math.Pow(ly, 2) + Math.Pow(lx, 2))) - lz;

            /*if ((dx*dy) == 0) {
             *      ip = new Scientrace.IntersectionPoint[1];
             *      v1 = new Vector(lx, ly, c*(Math.Pow(lx, 2)+Math.Pow(ly, 2)));
             *      ip[0] = new IntersectionPoint(v1.toLocation(), this.intersectionPlane(v1.x, v1.y));
             *      //ip[1] = null;
             *      return ip;
             * }*/
//		if ((Math.Pow(ABCa,2)) < 1E-56) { // <-- used to be
//		if ((Math.Pow(ABCa,2)) < 1E-31) { // <-- used to be
            if ((Math.Pow(ABCa, 2)) < 1E-31)      // <-- now, so no (/less) significance errors do occur any longer in results
            //Console.WriteLine("ABCa is SMALL"+ABCa.ToString());
            {
                ip    = new Scientrace.IntersectionPoint[1];
                d1    = -ABCc / ABCb;
                v1    = (line.direction.toVector() * d1) + line.startingpoint.toVector();
                ip[0] = new IntersectionPoint(v1.toLocation(), this.baseIntersectionShape(v1.x, v1.y));
                return(ip);
            }
            //Console.WriteLine("ABCa is large enough "+ABCa.ToString());

            //d1,2 => lambda 1,2 at http://amswiki.jbos.eu/wiki/index.php/Parabolic_Collision#Quadratic_formula
            //derived from the quadratic formula, note the +/- sign before the Sqrt.
            discr = Math.Pow(ABCb, 2) - (4 * ABCa * ABCc);
            if (discr < 0)
            {
                //Console.WriteLine("Negative discriminant : "+discr);
                ip = new Scientrace.IntersectionPoint[0];
                //ip[0] = null;
                //ip[1] = null;
                return(ip);
            }
            if (discr == 0)
            {
                ip    = new Scientrace.IntersectionPoint[1];
                d1    = ((-ABCb) + Math.Sqrt(Math.Pow(ABCb, 2) - (4 * ABCa * ABCc))) / (2 * ABCa);
                v1    = (line.direction.toVector() * d1) + line.startingpoint.toVector();
                ip[0] = new IntersectionPoint(v1.toLocation(), this.baseIntersectionShape(v1.x, v1.y));
                return(ip);
            }
            //still here? two results!

            /*d1 = ((-ABCb)+Math.Sqrt(Math.Pow(ABCb, 2)-(4*ABCa*ABCc)))/(2*ABCa);
            *  d2 = ((-ABCb)-Math.Sqrt(Math.Pow(ABCb, 2)-(4*ABCa*ABCc)))/(2*ABCa);*/
            d1 = ((-ABCb) + Math.Sqrt(discr)) / (2.0 * ABCa);
            d2 = ((-ABCb) - Math.Sqrt(discr)) / (2.0 * ABCa);
            v1 = (line.direction.toVector() * d1) + line.startingpoint.toVector();
            v2 = (line.direction.toVector() * d2) + line.startingpoint.toVector();


            //Console.WriteLine("discr: "+discr+" ABCa: "+ABCa+" ABCb: "+ABCb+" ABCc: "+ABCc);
            //FOR BETTER PERFORMANCE REMOVE CHECKS BELOW

            /* //This was removed at 20160222
             * if ((v1 != null) && (!line.throughLocation(v1.toLocation(), 0.00001))) {
             *      throw new Exception("TRFd line 1 "+v1.trico()+" avoids "+line.ToString());
             *      }
             * if ((v2 != null) && (!line.throughLocation(v2.toLocation(), 0.00001))) {
             *      v2 = v1;
             * //			Console.WriteLine("discr: "+discr);
             * //			throw new Exception("TRFd line 2 "+v1.trico()+" avoids "+line.ToString()+" contrairy to "+v1.trico());
             *      }
             */
            ip    = new Scientrace.IntersectionPoint[2];
            ip[0] = (v1 == null ?
                     null :
                     new IntersectionPoint(v1.toLocation(), this.baseIntersectionShape(v1.x, v1.y))
                     );
            ip[1] = (v2 == null ?
                     null :
                     new IntersectionPoint(v2.toLocation(), this.baseIntersectionShape(v2.x, v2.y))
                     );
            return(ip);
        }
コード例 #20
0
 public void initNewIntersection(Scientrace.Line traceline, Scientrace.IntersectionPoint[] ips, Scientrace.Object3d object3d, bool bothdirections)
 {
     this.object3d = object3d;
     //Console.WriteLine("New Intersection with "+ips.Length+" IP's - "+object3d.hasParent());
     this.intersects = false;
     //Console.WriteLine("FALSE");
     foreach (Scientrace.IntersectionPoint ip in ips)
     {
         if (ip == null)
         {
             //Console.WriteLine("<NULL>");
             continue;
         }
         //if bothdirections == true the Intersection does not nessicarily have to be away (in direction "direction")
         // from the startingpoint.
         if (!bothdirections)
         {
             //check if ip is in the line of the trace from its startingpoint
             if (traceline.direction.dotProduct(ip.loc - traceline.startingpoint) <= 1E-9)
             {
                 //Console.WriteLine("WARNING: Intersectionpoint "+ip.loc.ToString()+" lies in the past @ "+traceline.startingpoint);
                 continue;
             }
         }
         if (this.intersects == false)
         {
             //Console.WriteLine("TRUE");
             this.intersects = true;
             this.enter      = ip;
             this.exit       = null;       // new IntersectionPoint(null, null); CHANGED (BUGFIX?) BY JBC @ 20131205
             continue;
         }
         if (this.enter.loc.distanceTo(traceline.startingpoint) > ip.loc.distanceTo(traceline.startingpoint))
         {
             //this intersectionpoint is closer than the "enterpoint so far"
             // this condition is wrong right? if (this.exit==null) {
             this.exit = this.enter;
             // this is wrong right?     }
             this.enter = ip;
             continue;
         }
         else
         {
             if (this.exit == null)
             {
                 this.exit = ip;
                 continue;
             }
             else
             {
                 //this intersectionpoint is further from beam than enterpoint. New exitpoint defined.
                 if (this.exit.loc.distanceTo(traceline.startingpoint) > ip.loc.distanceTo(traceline.startingpoint))
                 {
                     //intersectionpoint is closer than old exitpoint
                     this.exit = ip;
                     continue;
                 }
             }
             continue;             // <-- existing exitpoint is closer than new IP: do nothing.
         }
     }
 }
コード例 #21
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));
 }
コード例 #22
0
ファイル: Shape2d.cs プロジェクト: xiaohuangyu/scientrace
 public virtual Scientrace.Location atPath(Scientrace.Line line)
 {
     throw new SubclassResponsibilityException("atpath not available @ Plane class");
 }
コード例 #23
0
ファイル: Shape2d.cs プロジェクト: xiaohuangyu/scientrace
 public bool inPath(Scientrace.Line line)
 {
     return(this.atPath(line) != null);
 }
コード例 #24
0
 public Trace(double wlengthmeters, LightSource lsource, Scientrace.Line traceline,
              Scientrace.Object3d currentObject, double intensity, double original_intensity)
 {
     this.init(wlengthmeters, lsource, traceline, currentObject, intensity, original_intensity);
 }
コード例 #25
0
        public Scientrace.IntersectionPoint[] realIntersections(Scientrace.Line traceline, bool checkBorder)
        {
//			Scientrace.Line line = traceline-this.loc;	//substract loc value from traceline location,
            //leave direction unchanged
            //Console.WriteLine("In untransformed world: traceline -> "+traceline.ToString());
            //default value should be checkBorder = true;
            Scientrace.VectorTransform trf     = this.trf;
            Scientrace.Line            trfline = trf.transform(traceline - this.loc);
            //transform location AND direction
            Scientrace.IntersectionPoint[] ips = this.baseintersections(trfline);
            Scientrace.IntersectionPoint   tip;
            Scientrace.IntersectionPoint[] retips = new Scientrace.IntersectionPoint[2];
            for (int ipi = 0; ipi < ips.GetLength(0); ipi++)
            {
                if (ips[ipi] == null)
                {
                    retips[ipi] = null;
                    continue;
                }
                //Console.WriteLine("$$$$$$$$$$$$$$$$$"+ips[ipi].loc+"in?:"+trfline);
                //Console.WriteLine("___1");

                //check below removed for performance reasons

                /*if (!trfline.throughLocation(ips[ipi].loc, 0.00001)) {
                 *      string warning =@"ERROR: GOING DOWN! \n baseintersections "+trfline+" FAILED!";
                 *      throw new ArgumentOutOfRangeException(warning+ips[ipi].loc.trico() + " not in line " + trfline);
                 * } *///This was removed at 20160222

                /* else {
                 *      Scientrace.Line reflline = trfline.reflectAt(this.baseIntersectionPlane(ips[ipi].loc.x, ips[ipi].loc.y),0);
                 * //Console.WriteLine("___2");
                 *      /*if (!reflline.throughLocation(this.getBaseConcentrationPoint(), 0.000001)) {
                 *              //throw new ArgumentOutOfRangeException("CONCENTREER EENS!");
                 *              }*/
                //	} end of removed check
                //throw new AccessViolationException("FOO");
                //Console.WriteLine("ips["+ipi.ToString()+"]:"+ips[ipi].ToString());

                //tip = trf.transformback(ips[ipi])+this.loc;

                tip                 = ips[ipi].copy();
                tip.loc             = trf.transformback(ips[ipi].loc) + this.loc;
                tip.flatshape.plane = trf.transformback(tip.flatshape.plane);

                //Console.WriteLine("___3");

                /*if (!traceline.throughLocation(tip.loc, 0.0001)) {
                 *      throw new ArgumentOutOfRangeException(tip.loc.trico() + " (transformed) not in line " + traceline);
                 * } else {
                 *      }*/

                if (this.cborder.contains(tip.loc) || !checkBorder)          //is this location within the borders between which the
                //parabolic mirror exists?
                {
                    retips[ipi] = tip;

/*					//below for debug purposes only
 *                                      retips[ipi] = new IntersectionPoint(traceline.startingpoint+
 *                                                                          traceline.direction.toLocation()*(traceline.direction.dotProduct(tip.loc-traceline.startingpoint))
 *                                                                                                            , tip.plane);*/
                }
                else
                {
                    //Console.WriteLine(tip.loc.ToString() + " is NOT within the cborder range-> "+this.cborder);
                    retips[ipi] = null;
                    continue;
                }

                //Console.WriteLine("trf: "+trf.ToString());
                //Console.WriteLine("retips["+ipi.ToString()+"]:"+retips[ipi].ToString());
            }
            return(retips);
        }
コード例 #26
0
 public Scientrace.Location planoCenterLoc()
 {
     Scientrace.Line sphereLine = new Scientrace.Line(this.sphereCenterLoc, this.lensPlane.getNormal());
     return(this.lensPlane.intersectsAt(sphereLine));
 }
コード例 #27
0
 public Scientrace.Line modify(Scientrace.Line aLine, double nodenumber, double nodetotal)
 {
     Scientrace.Line retLine = aLine.copy();
     retLine.direction = this.modify(retLine.direction, nodenumber, nodetotal).toUnitVector();
     return(retLine);
 }
コード例 #28
0
 public void TestFailingRealIntersectionsForloop()
 {
     Scientrace.Object3dEnvironment env = DummySources.dEnv();
     Scientrace.CylindricalBorder cb = new Scientrace.CylindricalBorder(new Scientrace.Location(0, -0.07, 0), new Scientrace.NonzeroVector(0, -0.57, 0), 0.5);
     Scientrace.ParabolicMirror pm = new Scientrace.ParabolicMirror(env
     , Scientrace.PerfectMirror.Instance, new Scientrace.Location(0.354861881099294, -0.57, 0.276718350209505)
     ,  new Scientrace.UnitVector(-0.343710964996787, 0.900014703397015, -0.268022958363946), 2, cb);
     for (double a = -0.184140645666577; a >= -0.5; a = a-0.01) {
     Scientrace.Line tl = new Scientrace.Line(a, -0.0383229578843359, -0.3, 0.343710966184079, -0.900014705907235, 0.268022948412108);
     //		Scientrace.Line tl = new Scientrace.Line(-0.284140645666577, -0.0383229578843359, -0.3, 0.343710966184079, -0.900014705907235, 0.268022948412108);
     try {
     pm.realIntersections(tl, false);
     } catch {
     throw new Exception(a + " is f****d");
     }
     }
     //Assert.AreEqual(new Scientrace.Location(0,0,0), tips[0].loc);
 }
コード例 #29
0
 public Scientrace.Line transformback(Scientrace.Line aLine)
 {
     return(new Scientrace.Line(this.transformback(aLine.startingpoint).toLocation(),
                                this.transformback(aLine.direction).tryToUnitVector()));
 }
コード例 #30
0
 public Line reflectLineAbout(Scientrace.Line line, Scientrace.NonzeroVector norm)
 {
     return(line.reflectOnSurface(norm, this.interactionoffset));
 }
コード例 #31
0
 public Intersection(Scientrace.Line traceline, Scientrace.IntersectionPoint[] ips, Scientrace.Object3d object3d, bool bothdirections)
 {
     this.initNewIntersection(traceline, ips, object3d, bothdirections);
     this.checkObject();    //<- DEBUGGING:
 }
コード例 #32
0
        //public DoubleConvexLens(ShadowScientrace.ShadowObject3d shadowObject): base(shadowObject) {
        public override void createStartTraces()
        {
            //Console.WriteLine("CENTER AT: "+center.trico());

            Scientrace.UnitVector urange, vrange;
            urange = this.spiral_plane.u.toUnitVector();
            vrange = this.spiral_plane.v.toUnitVector();
            if (urange.dotProduct(vrange)>0.01) { Console.WriteLine("**WARNING: plane vectors far from orthogonal"); }
            Scientrace.Line line;
            Scientrace.Location loc;
            for (int n = 1; n <= linecount; n++) {
            double phi = Math.Sqrt(((double)n-0.5)/linecount);

            loc = this.center +
                    urange.toLocation()*(this.radius*phi*
                        Math.Sin(2*Math.PI*this.loops*phi)) +
                    vrange.toLocation()*(this.radius*phi*
                        Math.Cos(2*Math.PI*this.loops*phi));

            line = new Scientrace.Line(loc,this.direction);
            // DISTANCE NOW MOVED TO ADDTRACE METHOD. line = new Scientrace.Line(loc+(this.direction.negative().toVector()*this.distance),this.direction);
            //Console.WriteLine("New line: "+line.ToString());
            if (spectrum.it(n)==0) {
                continue;
                }
            Scientrace.Trace ttrace = new Scientrace.Trace(spectrum.wl(n),
                                            this, line, env, spectrum.it(n),  spectrum.it(n));

            ttrace.traceid = "spiral_"+n.ToString();
            //this.traces.Add(ttrace);
            this.addTrace(ttrace);
            }
        }