Example #1
0
 public bool containsExclude(Scientrace.Location aLocation, double excludedMargin)
 {
     if (aLocation == null) { return false; }
     Scientrace.Location sLoc = (aLocation-this.loc); //shifted location based on plane origin
     Scientrace.Location tLoc = this.trf.transform(sLoc); //transformed location based on the plane basevectors and its normal
     return (tLoc.z >= excludedMargin);
 }
Example #2
0
        //length inherited from Prism
        public TriangularPrism(Scientrace.Object3dCollection parent, Scientrace.MaterialProperties mprops, 
			Scientrace.Location loc, Scientrace.NonzeroVector width, Scientrace.NonzeroVector height, 
			Scientrace.NonzeroVector length)
            : base(parent, mprops)
        {
            this.paramInit(loc, width, height, length);
        }
Example #3
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;
        }
        public void initCreatedRefractTrace(Trace refractTrace, UnitVector surfaceNormal, Scientrace.Object3d fromObject3d, Scientrace.Object3d toObject3d)
        {
            double oldrefindex = fromObject3d.materialproperties.refractiveindex(this);
            double newrefindex = toObject3d.materialproperties.refractiveindex(this);
            //for definitions on the parameters below, check fullInternalReflects function.

            UnitVector incoming_trace_direction = this.traceline.direction;
            if (incoming_trace_direction.dotProduct(surfaceNormal) > 0) {
            surfaceNormal = surfaceNormal.negative();
            }

            Scientrace.UnitVector nnorm = surfaceNormal.negative();
            Scientrace.Vector incoming_normal_projection = nnorm*(incoming_trace_direction.dotProduct(nnorm));
            Vector L1 = incoming_trace_direction-incoming_normal_projection;
            double L2 = (oldrefindex/newrefindex)*L1.length;

            if (incoming_trace_direction == incoming_normal_projection) {
            //in case of normal incident light: do not refract.
            refractTrace.traceline.direction = incoming_trace_direction;
            return;
            }

            try {
            refractTrace.traceline.direction = ((nnorm*Math.Sqrt(1 - Math.Pow(L2,2)))
                    +(L1.tryToUnitVector()*L2)).tryToUnitVector();
            } catch (ZeroNonzeroVectorException) {
                Console.WriteLine("WARNING: cannot define direction for refraction trace. Using surface normal instead. (L1: "+incoming_trace_direction.trico()+", L2:"+incoming_normal_projection.trico()+").");
                refractTrace.traceline.direction = nnorm;
            } //end try/catch
        }
Example #5
0
 public PhysicalObject3d(Object3dCollection parent, Scientrace.MaterialProperties materialproperties)
     : base(parent, materialproperties)
 {
     this.surface_sides = new HashSet<SurfaceSide>() {Scientrace.SurfaceSide.Both};
     //this.surface_sides.Add(Scientrace.SurfaceSide.Both);
     //this.materialproperties = materialproperties;
 }
        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));
            }
        }
Example #7
0
        public override string exportX3D(Scientrace.Object3dEnvironment env)
        {
            System.Text.StringBuilder retx3d = new System.Text.StringBuilder("<!-- SPHERE GRID start -->", 10000);

            Scientrace.Location tNodeLoc;
            Scientrace.Location tMerConnectLoc;
            Scientrace.Location tLatConnectLoc;
            Scientrace.X3DGridPoint tGridPoint;

            for (int ic = 0; ic <= this.x3d_circles_of_latitude; ic++) { //0-pi
            for (int im = 0; im < this.x3d_meridians; im++) { //0-2pi

                tNodeLoc = this.getNodeLoc(ic, im);
                tMerConnectLoc =
                    (ic > 0 && ic < this.x3d_meridians) ? // do not connect "points" located at north and south pole
                        this.getNodeLoc(ic, (im+1)%this.x3d_meridians)
                        : null;
                tLatConnectLoc = this.getNodeLoc(ic+1, im);

                // a gridpoint has a location and two neighbour location to which to connect to
                tGridPoint = new Scientrace.X3DGridPoint(env, tNodeLoc,
                    tMerConnectLoc, tLatConnectLoc);
                retx3d.AppendLine(tGridPoint.exportX3DnosphereRGBA("0.4 0.8 0 1"));
                }}
            retx3d.Append("<!-- Sphere grid end -->");
            return retx3d.ToString();
        }
Example #8
0
        public Intersection(bool intersects, Scientrace.Object3d object3d)
        {
            this.intersects = intersects;
            this.object3d = object3d;

            this.checkObject();//<- DEBUGGING:
        }
        /* TO IMPLEMENT: Class="RandomToSurface"
        <LightSource BeamCount="N" Class="RandomToSurface" Seed="1">
        <Surface Class="circle" Radius="r" />
        <Center xyz="LENSXYZ" />
        <Normal xyz="DIRXYZ" />
        </Surface>
        </LightSource>

        */
        public Scientrace.LightSource constructLightSource(XElement xel, Scientrace.Object3dEnvironment env)
        {
            /* //Special property removed at 20151021
            XElement xspec = xel.Element("Spectrum");
            Scientrace.LightSpectrum aSpectrum = null;
            if (xspec == null) {
            //throw new XMLException("No Spectrum element found for: "+xel.ToString());
            } else {
            XMLSpectrumParser xsp = new XMLSpectrumParser();
            aSpectrum = xsp.parseLightSpectrum(xspec);
            }
            */

            //modified at 20150707
            //ShadowScientrace.ShadowLightSource shadowLS =
            //		new ShadowScientrace.ShadowLightSource(typeof(Scientrace.SpiralLightSource), env, aSpectrum);
            ShadowScientrace.ShadowLightSource shadowLS =
                new ShadowScientrace.ShadowLightSource(null, env);

            this.setClassInfo(xel, shadowLS);

            this.setLightSourceConstructorParams(shadowLS, xel);
            this.setLightSourceSettings(shadowLS, xel);

            return shadowLS.factory("no id");
        }
Example #10
0
        public string exportX3D(Scientrace.Object3dEnvironment env)
        {
            Scientrace.Vector a, b, c, d;
            //square
            a = Vector.ZeroVector();
            b = this.plane.u;
            c = this.plane.u+this.plane.v;
            d = this.plane.v;

            string colstr = "0.5 0.5 0.5 0.2";
            return @"<!-- Start Parallelogram instance -->\n <Transform translation='"+this.plane.loc.trico()+@"'>
            <Shape>
            <!-- Coordinate prism sequence (matches coordIndex actually) 0 1 2 3 0 -->
            <LineSet vertexCount='5'>
            <Coordinate point='
            "+a.tricon()+b.tricon()+c.tricon()+d.tricon()+a.tricon()+"'/>" +

            /*@"<ColorRGBA color='0 1 0 1 0 1 0 1
            0 1 0 1 0 1 0 1
            0 1 0 1 0 1 0 1
            0 1 0 1 0 1 0 1' />
            </LineSet>" + */
            @"<ColorRGBA color='"+colstr +" "+colstr +" "+colstr +" "+colstr +" "+colstr +" "+colstr +" "+colstr +" "+colstr +@"' />
            </LineSet>" +
            @"      </Shape>" +
            @"    </Transform>\n<!-- End Parallelogram instance -->";
        }
        public List<Scientrace.Trace> getCustomTracesListFromXData(XElement xlight,
												Scientrace.Object3dEnvironment env)
        {
            string traces_filename = (this.X.getXStringByName(xlight, "Filename", null));
            if (traces_filename != null)
                if (System.IO.File.Exists(traces_filename)) {
                    XDocument xd = XDocument.Load(traces_filename);
                    return this.getCustomTracesListFromXData(xd.Element("LightSource"), env);
                    } else throw new System.IO.FileNotFoundException("CustomTraces filename ("+traces_filename+") does not exist.");
            // If there aren't any Trace sub-Elements, you might as well stop here (return null)
            if (!xlight.Elements("Trace").Any())
                        return null;
            List <Scientrace.Trace> customtraces = new List<Scientrace.Trace>();
            foreach (XElement xtrace in xlight.Elements("Trace")) {
                double wavelength = this.X.getXDouble(xtrace, "Wavelength",
                                        (this.X.getXDouble(xtrace, "m",
                                            ((this.X.getXDouble(xtrace, "nm", -1))*1E-9))
                                            )
                                        );
                if (wavelength <= 0) {
                    throw new XMLException("Error parsing wavelength from CustomTraces Lightsource. XML Source: \n"+
                        xtrace.ToString());
                    }
                double intensity = this.X.getXDouble(xtrace, "Intensity", 1);
                Scientrace.Location loc = this.X.getXLocation(xtrace, "Location");
                Scientrace.UnitVector dir = this.X.getXNzVectorByName(xtrace, "Direction").toUnitVector();
                customtraces.Add(
                                 new Scientrace.Trace(wavelength, null, new Scientrace.Line(loc, dir),
                                                      env, intensity, intensity)
                                 );
                }
            return customtraces;
        }
Example #12
0
 public new UnitVector orientedAgainst(Scientrace.Vector aVector)
 {
     if (aVector.dotProduct(this) > 0) {
     return this.negative();
     }
     return this;
 }
 public Scientrace.Vector formulaVector(Scientrace.Vector aVector, XElement xformula)
 {
     string f_x = "x";
     string f_y = "y";
     string f_z = "z";
     if (xformula.Attribute("xyz") != null) {
     try {
         string xyz = xformula.Attribute("xyz").Value;
         char[] delimiterChars = { ';', '\t' };
         string[] elements = xyz.Split(delimiterChars);
         if (elements.Length !=3) {
             throw new XMLException("Element "+xformula.ToString()+" has \""+elements.Length+ "\" != 3 valid vector elements. ");
             }
         f_x=elements[0];
         f_y=elements[1];
         f_z=elements[2];
         } catch { throw new XMLException("Formula "+xformula.ToString()+" does not have proper parameters for {xyz} attribute (can't parse {"+xformula.Attribute("xyz").Value.ToString()+"}. Perhaps incorrect use of PreProcess variables or decimal separators?)."); }
     } // attribute "xyz"
     f_x = this.getXStringByName(xformula, "x", f_x);
     f_y = this.getXStringByName(xformula, "y", f_y);
     f_z = this.getXStringByName(xformula, "z", f_z);
     Dictionary<string, object> replace_vectors = new Dictionary<string, object>(){{"x", (decimal)aVector.x}, {"y", (decimal)aVector.y}, {"z", (decimal)aVector.z} };
     return new Scientrace.Vector(
     Scientrace.MathStrings.solveString(f_x, replace_vectors),
     Scientrace.MathStrings.solveString(f_y, replace_vectors),
     Scientrace.MathStrings.solveString(f_z, replace_vectors)
     );
 }
Example #14
0
 public Scientrace.RGBColor getColorFromHTML(string varname, Scientrace.RGBColor defval)
 {
     Scientrace.RGBColor retval;
     retval = Scientrace.RGBColor.FromHTML(this.getString(varname));
     if (retval == null) return defval;
     return retval;
 }
        public string angleToRGB(Scientrace.Spot aCasualty, PhysicalObject3d physObj)
        {
            UnitVector inAngle = aCasualty.trace.traceline.direction;
            Scientrace.Parallelogram pg = physObj.getDistributionSurface();
            Scientrace.NonzeroVector norm = physObj.getSurfaceNormal();

            UnitVector y = pg.plane.v.toUnitVector();
            UnitVector x = null;
            try {
            x = norm.crossProduct(y).tryToUnitVector();
            } catch { throw new ZeroNonzeroVectorException("The vertical vector (plane.v) is parallel to the unit normal.");
            }
            double dx = x.dotProduct(inAngle);
            double dy = y.dotProduct(inAngle);

            double lengthFraction = Math.Sqrt((dx*dx)+(dy*dy));
            //Console.WriteLine("Length: "+lengthFraction+ " vs: "+((x*dx)+(y*dy)).length);

            double angle = Math.Atan2(dy, dx);

            return this.angleToHTML(angle, 2*Math.Asin(lengthFraction)/Math.PI);

            //physObj.getSurfaceNormal()
            //aCasualty.object3d.
            //		throw new Exception("Not yet implemented");
        }
Example #16
0
 public Angle(Scientrace.Trace fromTrace, Scientrace.Trace toTrace, Scientrace.Intersection intersection)
 {
     this.fromTrace = fromTrace;
     this.toTrace = toTrace;
     this.radians = fromTrace.traceline.direction.angleWith(toTrace.traceline.direction);
     this.intersection = intersection;
 }
Example #17
0
        public override string exportX3D(Scientrace.Object3dEnvironment env)
        {
            // prev after Transform      <Viewpoint description='	LineSet cube close up' position='0 0 5'/>
            //TODO: try to transform to indexedlineset
            Scientrace.Vector a, b, c, d, e, f, g, h;

            a = Vector.ZeroVector();
            //front square
            b = this.width;
            c = this.height+this.width;
            d = this.height;
            e = this.length;
            //back square
            f = this.length+this.width;
            g = this.length+this.width+this.height;
            h = this.length+this.height;

            //front square

            //back square

            //connecting squares

            return "<!-- Start RectangularPrism instance -->\n<Transform translation='"+this.loc.trico()+
                "'>\r\n      <Shape>\r\n        <!-- Coordinate rectangprism sequence (matches coordIndex actually) 0 1 2 3 0, 4 5 6 7 4, 0 4, 1 5, 2 6, 3 7 -->\r\n"+
                "        <LineSet vertexCount='5 5 2 2 2 2'>\r\n          <Coordinate point='\r\n"+
                a.tricon()+b.tricon()+c.tricon()+d.tricon()+a.tricon()+e.tricon()+f.tricon()+g.tricon()+h.tricon()+e.tricon()+a.tricon()+e.tricon()+b.tricon()+f.tricon()+c.tricon()+g.tricon()+d.tricon()+h.tricon()+
                "'/>\r\n"+
                "<ColorRGBA color='"+string.Concat(Enumerable.Repeat("0.5 0.5 0.5 1 ", 18))+"' />"+ // 18 due to 12 lines in 6 blocks produces 12+6=18, anyway this works?
                "        </LineSet>\r\n      </Shape>\r\n    </Transform>\n<!-- End RectangularPrism instance -->";
            //          <Color color='1 0 0 1 0.5 0 1 1 0 0 1 0 1 0 0 0 0 1 0.8 0 0.8 0.3 0 0.3 1 1 1 0 0 1 1 0 0 0 0 1 1 0.5 0 0.8 0 0.8 1 1 0 0.3 0 0.3 0 1 0 1 1 1'/>
        }
Example #18
0
 public void addLightSourceTag(Scientrace.LightSource anObject, XElement xel)
 {
     XAttribute tag = xel.Attribute("Tag");
     if (tag != null) {
         anObject.tag = tag.Value;
         }
 }
Example #19
0
 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;
 }
        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 #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 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 #23
0
 //length inherited from Prism
 public RectangularPrism(Scientrace.Object3dCollection parent, Scientrace.MaterialProperties mprops, Scientrace.Location loc, Scientrace.NonzeroVector width, Scientrace.NonzeroVector height, Scientrace.NonzeroVector length)
     : base(parent, mprops)
 {
     this.loc = loc;
     this.width = width;
     this.length = length;
     this.height = height;
 }
 public bool contains(Scientrace.Location aLocation)
 {
     bool retbool = false;
     foreach (PlaneBorderEnclosedVolume aSubVolume in subVolumes) {
     retbool = retbool || aSubVolume.contains(aLocation);
     }
     return retbool;
 }
Example #25
0
        public FlatSurfaceObject3d(Scientrace.Object3dCollection parent, Scientrace.MaterialProperties mprops)
            : base(parent, mprops)
        {
            //this.surface_sides = new HashSet<SurfaceSide>() {Scientrace.SurfaceSide.Both, Scientrace.SurfaceSide.Front, Scientrace.SurfaceSide.Back};

            //only front surface by default:
            this.surface_sides = new HashSet<SurfaceSide>() {Scientrace.SurfaceSide.Front};
        }
Example #26
0
        public static Scientrace.SurfaceProperties NewSurfaceModifiedObject(Scientrace.Object3d anObject,
			List<Scientrace.UniformTraceModifier> surface_normal_modifiers)
        {
            Scientrace.SurfaceProperties retSurf = new Scientrace.SurfaceProperties();
            retSurf.materialproperties = anObject.materialproperties;
            retSurf.addSurfaceModifiers(surface_normal_modifiers);
            return retSurf;
        }
Example #27
0
        public Sphere(Scientrace.Object3dCollection parent, Scientrace.MaterialProperties mprops,
		Scientrace.Location aLocation, double sphereRadius
		)
            : base(parent, mprops)
        {
            this.loc = aLocation;
            this.radius = sphereRadius;
        }
Example #28
0
 //length inherited from Prism
 public CircularPrism(Scientrace.Object3dCollection parent, Scientrace.MaterialProperties mprops, Scientrace.Location loc, Scientrace.NonzeroVector width, Scientrace.NonzeroVector height, Scientrace.NonzeroVector length)
     : base(parent, mprops)
 {
     this.loc = loc;
     this.width = width;
     this.height = (height.tryToUnitVector())*width.length;
     this.length = length;
 }
Example #29
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();
 }
 public DistributionSquare getDistributionSquare(Scientrace.PhysicalObject3d anObject, int order)
 {
     Scientrace.Parallelogram surface = anObject.getDistributionSurface();
     Scientrace.DistributionSquare ds = new Scientrace.DistributionSquare(0, order, surface.plane.loc, surface.plane.u, surface.plane.v);
     foreach(Scientrace.Spot aSpot in this.spots) {
     ds.addSpot(aSpot.loc);
     }
     return ds;
 }