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); }
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 float getRefractiveIndex(Scientrace.Trace trace) { throw new SubclassResponsibilityException("Implementation required of getRefractiveIndex(trace) function required at" + this.GetType().ToString() + trace.ToString()); }