public void addTrace(Scientrace.Trace aTrace) { List <Scientrace.Trace> inTraces = new List <Scientrace.Trace>(); List <Scientrace.Trace> outTraces = new List <Scientrace.Trace>(); // No modifiers present? Add normal trace if (this.lightsource_modifiers.Count < 1) { aTrace.traceline.rewind(this.distance); this.traces.Add(aTrace); return; } // Modifiers present! Add (only) modified traces. inTraces.Add(aTrace); foreach (Scientrace.UniformTraceModifier aModifier in this.lightsource_modifiers) { outTraces.AddRange(this.modifiedTraces(inTraces, aModifier)); } foreach (Scientrace.Trace tTrace in outTraces) { tTrace.traceline.rewind(this.distance); } this.traces.AddRange(outTraces); }
public virtual double enterReflection(Scientrace.Trace trace, Scientrace.UnitVector norm, MaterialProperties previousMaterial) { double ti = trace.traceline.direction.angleWith(norm.negative()); double sti = Math.Sin(ti); double cti = Math.Cos(ti); /*debug Console.WriteLine("reflecting prev.: "+ previousObject.GetType()); Console.WriteLine("reflecting prev. material: "+ previousObject.materialproperties.GetType());*/ double n1 = previousMaterial.refractiveindex(trace); double n2 = this.refractiveindex(trace); //Fresnel Equations on a 50/50 distribution of parallel and perpendicular to the plane polarization double Rs = Math.Pow( ((n1 * cti) - (n2 * Math.Sqrt(1.0 - Math.Pow((n1 / n2) * sti, 2.0)))) / ((n1 * cti) + (n2 * Math.Sqrt(1.0 - Math.Pow((n1 / n2) * sti, 2.0)))) , 2.0); double Rp = Math.Pow( ((n1 * Math.Sqrt(1.0 - Math.Pow((n1 / n2) * sti, 2.0))) - (n2 * cti)) / ((n1 * Math.Sqrt(1.0 - Math.Pow((n1 / n2) * sti, 2.0))) + (n2 * cti)) , 2.0); double R = (Rs + Rp) / 2.0; // Console.WriteLine("Reflection (n1/n2) = ("+n1+"/"+n2+") for angle "+ti+" is ("+Rs+"+"+Rp+")/2 ="+R); // Console.WriteLine("Reflection "+trace.traceline.direction.trico()+"->"+norm.trico()+" for angle "+ti+" is ("+Rs+"+"+Rp+")/2 ="+R); if (!((R >= 0) && (R < 1))) { Console.WriteLine("R==null(" + R + ", Rs:" + Rs + " Rp:" + Rp + " n1:" + n1 + " n2:" + n2 + " ti:" + ti + " rpnoem:" + ((n1 / n2) * sti) + ") where " + this.ToString() + " and " + previousMaterial.ToString()); } /*StackTrace stackTrace = new StackTrace(); * MethodBase methodBase = stackTrace.GetFrame(1).GetMethod(); * Console.WriteLine(methodBase.Name); // e.g. */ return(R); }
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 }
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; }
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; }
/******************** INSTANCE METHODS *****************/ public virtual double absorption(Scientrace.Trace trace, Scientrace.UnitVector norm, MaterialProperties previousMaterial) { if (previousMaterial.dominantOnLeave) { return(previousMaterial.enterAbsorption(trace, norm, this)); } return(this.enterAbsorption(trace, norm, previousMaterial)); }
public Scientrace.Trace fork(Scientrace.Line newLine, Vector pol_vec_1, Vector pol_vec_2, double new_intensity, string fork_tag) { Scientrace.Trace retTrace = this.fork(fork_tag); retTrace.traceline = newLine; retTrace.intensity = new_intensity; retTrace.setCircularPolarisation(pol_vec_1, pol_vec_2); return(retTrace); }
public static Scientrace.Trace getParentRoot(Scientrace.Trace aTrace) { Scientrace.Trace tTrace = aTrace; while (tTrace.parent != null) { tTrace = tTrace.parent; } return(tTrace); }
/// <summary> /// For this trace, which means to clone it, to increase its parents fork-counter, modify the trace-id by adding "fork_tag" to it. /// </summary> /// <param name="fork_tag">A tag that is added to the trace-id of the created fork. The "#" char will be replaced by the this objects forkedcount value.</param> public Scientrace.Trace fork(string fork_tag) { Scientrace.Trace ttrace = this.clone(); this.forkedcount++; //ttrace.traceid = ttrace.traceid+"_"+this.forkedcount.ToString(); ttrace.traceid = ttrace.traceid + fork_tag.Replace("#", this.forkedcount.ToString()); ttrace.nodecount++; return(ttrace); }
public Scientrace.Trace createFullInternalReflectedTraceFork(Scientrace.Intersection intersection) { Scientrace.Trace fullReflectTrace = this.fork("_fR"); fullReflectTrace.traceline = fullReflectTrace.reflectAt(intersection.enter.flatshape.plane); fullReflectTrace.traceid = fullReflectTrace.traceid + "r"; fullReflectTrace.traceline.startingpoint = intersection.enter.loc; fullReflectTrace.nodecount++; //Console.WriteLine("INTERNAL REFLECTION! direction = "+newtrace.traceline.direction.trico()+this.currentObject.GetType()); return(fullReflectTrace); }
/// <summary> /// Prolong the trace to the specified Object3d instance (toObject3d) at location as specified in intersection. /// Prolonging does NOT increase the nodecounter. Attached objects count as 1 node alltogether. /// </summary> /// <param name='toObject3d'> /// The Object3d instance of interaction with the current Object3d at the surface. /// </param> /// <param name='intersection'> /// The intersection instance that describes the intersection that is calculated to occur. /// </param> public List <Scientrace.Trace> prolong(Scientrace.Object3d toObject3d, Scientrace.Intersection intersection) { Scientrace.Trace newtrace = this.clone(); List <Scientrace.Trace> newTraces = new List <Scientrace.Trace>(); newtrace.currentObject = toObject3d; newtrace.traceline.startingpoint = intersection.enter.loc; newtrace.traceline.direction = this.traceline.direction; newTraces.Add(newtrace); return(newTraces); }
/* public SingleRaySource(Scientrace.Line ray, double[] wavelengths, Scientrace.Object3dEnvironment env) :base(env){ this.ray = ray; this.wls = wavelengths; this.init(); }*/ public void init() { for (int n = 1; n <= linecount; n++) { if (spectrum.it(n)==0) { continue; } Scientrace.Trace ttrace = new Scientrace.Trace(spectrum.wl(n), this, this.ray, env, spectrum.it(n), spectrum.it(n)); ttrace.traceid = "singleray_"+n.ToString(); this.addTrace(ttrace); } }
public void addRecursiveModifiedTrace(Scientrace.Trace aTrace) { List <Scientrace.Trace> tTraces = new List <Scientrace.Trace>(); tTraces.Add(aTrace); foreach (Scientrace.UniformTraceModifier aModifier in this.lightsource_modifiers) { tTraces = this.modifiedTraces(tTraces, aModifier); } this.traces.AddRange(tTraces); }
public Scientrace.Intersection realIntersections(Scientrace.Trace trace, bool checkborder) { // check whether trace goes through cborder first for performance reasons Scientrace.Intersection intr; //if (this.cborder.crosses(trace)) { Scientrace.IntersectionPoint[] tips = this.realIntersections(trace.traceline, checkborder); intr = new Scientrace.Intersection(trace, tips, this); //}/ else { // intr = new Intersection(false, this); //} return(intr); }
public Scientrace.Trace shiftclone(Scientrace.Location loc) { Scientrace.Trace rettrace = new Scientrace.Trace(this.wavelenght, this.lightsource, this.traceline + loc, this.currentObject, this.intensity, this.original_intensity); rettrace.nodecount = this.nodecount; rettrace.traceid = this.traceid; rettrace.parent = this; if (this.nodecount > this.lightsource.max_interactions) { Console.WriteLine("WARNING!: " + this.nodecount.ToString() + " has reached the maximum nodecount! Should die."); } return(rettrace); }
/* public SingleRaySource(Scientrace.Line ray, double[] wavelengths, Scientrace.Object3dEnvironment env) :base(env){ * this.ray = ray; * this.wls = wavelengths; * this.init(); * }*/ public void init() { for (int n = 1; n <= linecount; n++) { if (spectrum.it(n) == 0) { continue; } Scientrace.Trace ttrace = new Scientrace.Trace(spectrum.wl(n), this, this.ray, env, spectrum.it(n), spectrum.it(n)); ttrace.traceid = "singleray_" + n.ToString(); this.addTrace(ttrace); } }
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); }
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); }
} // end func. redirect public List <Scientrace.Trace> partialReflectRefract(Scientrace.Object3d fromObject3d, Scientrace.Object3d toObject3d, Scientrace.Intersection intersection, UnitVector surfaceNormal) { /*double oldrefindex = fromObject3d.materialproperties.refractiveindex(this); * double newrefindex = toObject3d.materialproperties.refractiveindex(this);*/ List <Scientrace.Trace> newTraces = new List <Trace>(); Scientrace.Trace refractTrace = this.fork("_pr"); refractTrace.currentObject = toObject3d; refractTrace.traceline.startingpoint = intersection.enter.loc; Scientrace.UnitVector normal = intersection.enter.flatshape.plane.getNorm() .orientedAgainst(this.traceline.direction) .tryToUnitVector(); // Evaluate absorption by toObject3d refractTrace.absorpByObject(toObject3d, normal, fromObject3d); if (refractTrace.isEmpty()) { newTraces.Add(refractTrace); return(newTraces); } // CHECK whether (partial) reflection occurs... if ((toObject3d.materialproperties.reflects) || ((intersection.leaving) && (fromObject3d.materialproperties.reflects))) { //double refcoef = toObject3d.materialproperties.reflection(refractTrace, surfaceNormal, this.currentObject); double refcoef = toObject3d.materialproperties.reflection(refractTrace, surfaceNormal, fromObject3d.materialproperties); Scientrace.Trace reflectTrace = refractTrace.fork("_R"); //.clone(); reflectrace.nodecount++; reflectTrace.intensity = refractTrace.intensity * refcoef; //intensity shouldn't spawn nor disappear here refractTrace.intensity = refractTrace.intensity - reflectTrace.intensity; //Scientrace.Spot normspot = new Scientrace.Spot(norm.toLocation()+intersection.enter.loc, null, 1); //CHANGED 20131030 //reflectrace.traceline = newtrace.reflectAt(intersection.enter.flatshape.plane); reflectTrace.traceline = refractTrace.reflectLineAbout(reflectTrace.traceline, surfaceNormal); //ADDED @ 20130122: the parial internal reflected trace should have the current object as oldobject. reflectTrace.currentObject = this.currentObject; //CURRENT OBJECT DOES NOT CHANGE FOR (partial)INTERNAL REFLECTION! newTraces.Add(reflectTrace); } this.initCreatedRefractTrace(refractTrace, surfaceNormal, fromObject3d, toObject3d); newTraces.Add(refractTrace); return(newTraces); } // end func partialReflectRefract
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); } }
public Scientrace.Location traceLeavesEnvironment(Scientrace.Trace trace) { trace.currentObject = this; Scientrace.Line line = trace.traceline; UnitVector dir = line.direction; dir.check(); Vector loc = line.startingpoint; /* find locations where line leaves a sphere of radius this.radius around 0,0,0 * derivation: * r^2 = |l*dir + loc|^2 * hence: * 0 = l^2 * |dir|^2 + 2*l*|dir.loc| + |loc|^2 - r^2 //the "." represents a dotproduct * Solve ABC formula for l: * a = |dir|^2 * b = 2 * (loc . dir) * c = |loc|^2 - r^2 */ double a = Math.Pow(dir.x, 2) + Math.Pow(dir.y, 2) + Math.Pow(dir.z, 2); double b = 2 * (loc.x * dir.x + loc.y * dir.y + loc.z * dir.z); double c = Math.Pow(loc.x, 2) + Math.Pow(loc.y, 2) + Math.Pow(loc.z, 2) - (Math.Pow(this.radius, 2)); double discriminant = Math.Pow(b, 2) - 4 * a * c; if (discriminant < 0) { throw new ArgumentOutOfRangeException("Trace leaves environment from within environment. Are the boundaries of your environment perhaps smaller than your objects?\n Environment radius: " + this.radius + "\n Trace data:" + trace.ToString()); } //ABC formula double ans1 = (-b + Math.Sqrt(discriminant)) / (2 * a); double ans2 = (-b - Math.Sqrt(discriminant)) / (2 * a); double ans = Math.Max(ans1, ans2); //Console.WriteLine("\n"+ans.ToString()+" * "+dir.trico()+"( = "+(dir*ans).trico()+") +"+loc.trico()+" = "+((dir*ans)+loc).toLocation().ToCompactString()+" is ..."); // throw new AccessViolationException(); //Console.WriteLine("IT ENDS HERE: "+((dir*Math.Max(ans1,ans2))+loc).toLocation().ToString()); Scientrace.Location leavelocation = (dir * ans + loc).toLocation(); /* Console.WriteLine("Direction: "+dir.trico()+ * "ABS ANS: "+(Math.Pow(b,2) - 4* a*c)+ * "Location: "+loc.trico());*/ trace.perish(leavelocation); return(leavelocation); }
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); }
public override Intersection intersects(Scientrace.Trace aTrace) { Scientrace.Vector c = this.loc; Scientrace.Vector o = aTrace.traceline.startingpoint; Scientrace.Vector l = aTrace.traceline.direction; Scientrace.Vector y = o - c; double r = this.radius; double ABCa = l.dotProduct(l); double ABCb = l.dotProduct(y) * 2; double ABCc = y.dotProduct(y) - (r * r); QuadraticEquation qe = new QuadraticEquation(ABCa, ABCb, ABCc); // if the trace doesn't hit the sphere, return a "false Intersection" if (!qe.hasAnswers) { return(new Intersection(false, this)); } Scientrace.IntersectionPoint[] ips = new Scientrace.IntersectionPoint[2]; switch (qe.answerCount) { case 2: Scientrace.Location minLoc = ((l * qe.minVal) + o).toLocation(); Scientrace.NonzeroVector minNorm = (minLoc - c).tryToNonzeroVector(); ips[0] = Scientrace.IntersectionPoint.locAtSurfaceNormal(minLoc, minNorm); Scientrace.Location plusLoc = ((l * qe.plusVal) + o).toLocation(); Scientrace.NonzeroVector plusNorm = (plusLoc - c).tryToNonzeroVector(); ips[1] = Scientrace.IntersectionPoint.locAtSurfaceNormal(plusLoc, plusNorm); return(new Intersection(aTrace, ips, this)); //goto case 1; //continue to case 1 case 1: Scientrace.Location loc = ((l * qe.plusVal) + o).toLocation(); Scientrace.NonzeroVector norm = (loc - c).tryToNonzeroVector(); ips[0] = Scientrace.IntersectionPoint.locAtSurfaceNormal(loc, norm); ips[1] = null; return(new Intersection(aTrace, ips, this)); default: throw new IndexOutOfRangeException("eq.answerCount is not allowed to be " + qe.answerCount.ToString() + "in Shpere.intersects(..)"); } //end switch(qe.answerCount) }
public virtual bool directedTowardsObjectside(Scientrace.SurfaceSide side, Scientrace.Trace aTrace) { switch (side) { case Scientrace.SurfaceSide.Back: // == SurfaceSide.Inside throw new NotImplementedException("Side " + side.ToString() + " not implemented for class" + this.GetType().ToString()); //break; case Scientrace.SurfaceSide.Front: throw new NotImplementedException("Side " + side.ToString() + " not implemented for class" + this.GetType().ToString()); //break; case Scientrace.SurfaceSide.Both: return(true); //break; default: throw new NotImplementedException("Side " + side.ToString() + " not implemented"); //break; } }
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; }
//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); } }
public override Intersection intersects(Scientrace.Trace aTrace) { // Finding intersectionpoints at sphere Scientrace.Intersection sphereIntersections = this.dummySphere.intersects(aTrace); /* If the PlanoConvexLens doesn't even pass the surface of the sphere, the intersection * of the lens does not exist. */ if (!sphereIntersections.intersects) { //return sphereIntersections; return(Intersection.notIntersect(this)); } Scientrace.Location planoLoc = this.lensPlane.lineThroughPlane(aTrace.traceline); Scientrace.IntersectionPoint planoIP; if ((!this.dummySphere.contains(planoLoc)) || (planoLoc == null)) { planoIP = null; } else { planoIP = new Scientrace.IntersectionPoint(planoLoc, this.lensPlane.planeToFlatShape2d()); } Scientrace.IntersectionPoint[] ips = new Scientrace.IntersectionPoint[3]; ips[0] = planoIP; ips[1] = this.lensPlane.filterOutsideBorder(sphereIntersections.enter); ips[2] = this.lensPlane.filterOutsideBorder(sphereIntersections.exit); Scientrace.Intersection lensIntersection = new Scientrace.Intersection(aTrace, ips, this); // when currently inside the lens, intersection from here must mean leaving. lensIntersection.leaving = this.contains(aTrace.traceline.startingpoint); //return created new intersection return(lensIntersection); }
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
//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); } }
public Intersection(Scientrace.Trace trace, Scientrace.IntersectionPoint[] ips, Scientrace.Object3d object3d) { this.initNewIntersection(trace.traceline, ips, object3d, false); this.checkObject(); //<- DEBUGGING: }
public Scientrace.Intersection intersectplanesforobject(Scientrace.Object3d anObject, List <Scientrace.FlatShape2d> pgrams) { Scientrace.Trace trace = this; Scientrace.Location firstloc = null; Scientrace.FlatShape2d enterplane = null; Scientrace.Location lastloc = null; double?firstdistance = null; double?lastdistance = null; Scientrace.Location tloc; double tdistance; foreach (Scientrace.FlatShape2d pgram in pgrams) { tloc = pgram.atPath(trace.traceline); if (tloc == null) { continue; } if (((tloc - trace.traceline.startingpoint).dotProduct(trace.traceline.direction)) < trace.getMinDistinctionLength()) { continue; //the location (even if increased with one wavelength) is "behind" the trace } tdistance = tloc.distanceTo(trace.traceline.startingpoint); if (firstdistance == null) { //assign first and last to first item in collection firstdistance = tdistance; firstloc = tloc; enterplane = pgram; lastdistance = tdistance; lastloc = tloc; } if (tdistance < firstdistance) { //Console.WriteLine(tdistance.ToString()+"<"+firstdistance.ToString()); firstdistance = tdistance; firstloc = tloc; enterplane = pgram; } if (tdistance > lastdistance) { //Console.WriteLine("We have a large distance gentlemen"); lastdistance = tdistance; lastloc = tloc; } } //end of pgrams-for-loop if (firstdistance == null) { //when no side of the paralellogram has been intersected return(new Scientrace.Intersection(false, anObject)); } if (firstdistance == lastdistance) { lastdistance = null; lastloc = null; } if (lastdistance == null) { //Console.WriteLine("I have no ending"); } else { //Console.WriteLine("I from "+trace.currentObject.GetType()+" @ "+trace.traceline.startingpoint.trico()+" pass through an object"); } Scientrace.Intersection intrs = new Scientrace.Intersection(true, anObject, firstloc, enterplane, lastloc); intrs.leaving = (lastloc == null); return(intrs); }
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(); }
public void recordTrace(Scientrace.Trace trace) { this.trace_sema.WaitOne(); this.traces.Add(trace); this.trace_sema.Release(); }
public override double enterReflection(Scientrace.Trace trace, Scientrace.UnitVector norm, Scientrace.MaterialProperties previousMaterial) { return(1); }
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); } }