public void TestDotProduct2() { Scientrace.Vector v1, v2; v1 = new Scientrace.UnitVector(1, 1, 1); v2 = new Scientrace.UnitVector(-1, -1, -1); Assert.AreEqual(-1, v1.dotProduct(v2), 1E-15); }
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); }
// return type changed from single Scientrace.Trace instance to List<Scientrace.Trace> newTraces in order to better facilitate the splitting of traces. public List <Scientrace.Trace> redirect_without_polarisation(Scientrace.Object3d toObject, Scientrace.Intersection intersection) { List <Scientrace.Trace> newTraces = new List <Trace>(); //what objects are acting here? Scientrace.Object3d fromObject = this.currentObject; /* The "normal" vector should always point towards the incoming beam when * using the Snellius-approach as described by figure 15 in * "Optical simulation of the SunCycle concentrator using Scientrace" * by Joep Bos-Coenraad (2013) */ Scientrace.UnitVector normal = intersection.enter.flatshape.plane.getNorm() .orientedAgainst(this.traceline.direction) .tryToUnitVector(); //Does full internal reflection occur? if (this.fullInternalReflects(normal, fromObject, toObject)) { //construct reflectedTrace Trace internalReflectedTrace = this.createFullInternalReflectedTraceFork(intersection); newTraces.Add(internalReflectedTrace); // in case of full internal reflection, no other "effects" occur, so return the newTraces collection here. return(newTraces); } newTraces.AddRange(this.partialReflectRefract(fromObject, toObject, intersection, normal)); // HERE USED TO BE CODE THAT CHECKED WHETHER (based on alphadirection) the direction of the incoming beam was altered at all. return(newTraces); } // end func. redirect
/// <summary> /// Required parameters: /// (Location) lens_plano_center, /// (double) lens_sphere_radius /// (double) lens_sphere_radians_min /// (double) lens_sphere_radians_max /// (UnitVector) orientation_from_sphere_center /// </summary> /// <param name='shadowObject'> /// Shadow object containing parameters from summary. /// </param> protected void shadowFac_PlanoCenter_And_Radians(ShadowScientrace.ShadowObject3d shadowObject) { //User values(s) Scientrace.Location lens_plano_center = (Scientrace.Location)shadowObject.getObject("lens_plano_center"); double lens_sphere_radius = (double)shadowObject.getObject("lens_sphere_radius"); double lens_sphere_radians_min = (double)shadowObject.getObject("lens_sphere_radians_min"); double lens_sphere_radians_max = (double)shadowObject.getObject("lens_sphere_radians_max"); Scientrace.UnitVector orientation_from_sphere_center = (Scientrace.UnitVector)shadowObject.getObject("orientation_from_sphere_center"); bool double_convex_ring = shadowObject.getNBool("double_convex") == true; //Derived value(s) Scientrace.Location lens_sphere_location = lens_plano_center - (orientation_from_sphere_center * lens_sphere_radius * Math.Cos(lens_sphere_radians_max)); /*double rmin = Math.Sin(lens_sphere_radians_min)*lens_sphere_radius; * double rmax = Math.Sin(lens_sphere_radians_max)*lens_sphere_radius; * Console.WriteLine("Ring got radius "+lens_sphere_radius+" at"+lens_sphere_location+" radmin/max:{"+lens_sphere_radians_min+"}/{"+lens_sphere_radians_max+"}."); * Console.WriteLine("Ring got rmin/rmax "+rmin+" / "+rmax); */ //Console.WriteLine("Lens sphere: "+lens_sphere_location.tricon()+" Plano center: "+lens_plano_center.trico()); //construct! this.paramInit(lens_sphere_location, lens_sphere_radius, lens_sphere_radians_min, lens_sphere_radians_max, orientation_from_sphere_center, double_convex_ring); }
public void paramInit( Scientrace.Location lens_sphere_location, double lens_sphere_radius, double lens_sphere_radians_min, double lens_sphere_radians_max, Scientrace.UnitVector orientation_from_sphere_center, bool double_convex_ring) { this.sphereLoc = lens_sphere_location; this.sphereRadius = lens_sphere_radius; //Console.WriteLine("Sphere radius: "+sphereRadius); this.radiansMin = lens_sphere_radians_min; this.radiansMax = lens_sphere_radians_max; this.orientation = orientation_from_sphere_center; this.doubleConvexRing = double_convex_ring; if (lens_sphere_radians_min > 0) { this.innerVoid = new InfiniteCylinderBorder(null, null, lens_sphere_location, orientation_from_sphere_center, lens_sphere_radius * Math.Sin(lens_sphere_radians_min) ); this.innerVoid.enclosesInside = false; } this.lensSphere = new Sphere(null, null, lens_sphere_location, lens_sphere_radius); this.initBottom(); }
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; }
public double absorpByObject(Scientrace.Object3d anObject3d, Scientrace.UnitVector norm, Object3d previousObject) { double oldintensity = this.intensity; double oldintensityfraction = this.intensityFraction(); //EXTENDED 20150706 double absorption_fraction = anObject3d.materialproperties.absorption(this, norm, previousObject.materialproperties); double absorption = absorption_fraction * oldintensity; double absorptionIntensityFraction = absorption_fraction * oldintensityfraction; this.intensity = oldintensity - absorption; if (absorption > MainClass.SIGNIFICANTLY_SMALL) //don't write a spot at ~0 absorption. { TraceJournal.Instance.recordSpot(new Scientrace.Spot(this.traceline.startingpoint, anObject3d, absorption, absorptionIntensityFraction, this)); } if (this.intensityFraction() <= this.lightsource.minimum_intensity_fraction) { //Console.WriteLine("INTENSITY TOO LOW"+anObject3d.ToString()+"/"+anObject3d.materialproperties.absorption(this)); this.perish(this.traceline.startingpoint); } return(absorption_fraction); }
protected void init_Center_and_Sidelength(Scientrace.Location cellcenterloc, Scientrace.Location pointingto, Scientrace.UnitVector orthogonaldirection, double sidelength) { //Check whether cellcenterloc and pointingto values are different if (cellcenterloc.distanceTo(pointingto) == 0) { throw new ZeroNonzeroVectorException("The location (" + cellcenterloc.ToCompactString() + ") of a Rectangle instance may not be equal to the direction (" + pointingto.ToCompactString() + ") it is pointed towards"); } NonzeroVector cellu, cellv, cellc; //define top-cell vector orthogonal to orthogonaldirection and the vectorpoint. Scientrace.UnitVector focusdir = (pointingto.toVector() - cellcenterloc.toVector()).tryToUnitVector(); //Console.WriteLine("POINTINGTO: "+pointingto.trico()+ " focusdir: "+focusdir.trico()); this.front_normal_direction = focusdir.copy(); cellu = orthogonaldirection.crossProduct(focusdir).tryToNonzeroVector(); cellu.normalize(); //UPDATE 20151102: added "negative" to conserve surface direction after crossproduct operation. cellv = cellu.crossProduct(focusdir.negative()).tryToNonzeroVector(); cellv.normalize(); cellu = cellu * sidelength; //surface of cell eq: sidelength * sidelength cellv = cellv * sidelength; cellc = (cellu + cellv) * 0.5; this.parallelogram = new Scientrace.Parallelogram(cellcenterloc - cellc.toLocation(), cellu, cellv); this.preserveSVGRatio(); this.addSurfaceMarkers(); }
} // end func partialReflectRefract 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 }
/******************** 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 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 override void write(Scientrace.PhysicalObject3d anObject) { Scientrace.UnitVector normvec = anObject.getSurfaceNormal(); this.fillPlaneVectors(normvec); this.write2dHistogramForPlane(anObject, "A = ref x norm", this.plane_a_vecs[normvec]); this.write2dHistogramForPlane(anObject, "B = norm x A", this.plane_b_vecs[normvec]); this.write2dHistogramForPlane(anObject, "1D histogram", null); }
public void fillOrtogonalVectors(ref Scientrace.NonzeroVector refVec1, ref Scientrace.NonzeroVector refVec2) { Scientrace.UnitVector tRefvec = Scientrace.UnitVector.x1vector(); if (Math.Abs(this.toUnitVector().dotProduct(tRefvec)) > 0.8) { tRefvec = Scientrace.UnitVector.y1vector(); } refVec1 = tRefvec.crossProduct(this).tryToUnitVector(); refVec2 = refVec1.crossProduct(this).tryToUnitVector(); }
public Line reflectLine(Scientrace.Line line, Scientrace.Plane plane) { Scientrace.UnitVector norm = plane.getNorm(); /*ADDED and removed 20131030 make surface normal in direction of incoming beam * if (line.direction.dotProduct(norm) > 0) { * norm.negated(); * }*/ return(this.reflectLineAbout(line, norm)); }
/// <summary> /// Required parameters: /// (Location)center_location /// (Location)pointing_towards /// (UnitVector)orthogonal_direction /// (double)side_length /// </summary> /// <param name='shadowObject'> /// Shadow object containing parameters from summary. /// </param> protected void shadowFac_Center_and_Sidelength(ShadowScientrace.ShadowObject3d shadowObject) { //User values(s) Scientrace.Location center_location = shadowObject.getLocation("center_location"); Scientrace.Location pointing_towards = shadowObject.getLocation("pointing_towards"); Scientrace.UnitVector orthogonal_direction = shadowObject.getUnitVector("orthogonal_direction"); double side_length = shadowObject.getDouble("side_length"); //construct! this.init_Center_and_Sidelength(center_location, pointing_towards, orthogonal_direction, side_length); }
public void CreateOrtho3rdVector() { Scientrace.UnitVector u, v; u = new Scientrace.UnitVector(2, 3, 4); v = new Scientrace.UnitVector(1, 2, 3); Scientrace.VectorTransform foo = new Scientrace.VectorTransform(u, v); Assert.AreNotEqual(0, u.dotProduct(v)); //, 1E-15); Assert.AreEqual(0, u.dotProduct(foo.w), 1E-15); Assert.AreEqual(0, v.dotProduct(foo.w), 1E-15); }
public void setRefAxis(Scientrace.NonzeroVector refVec) { if (refVec == null) { return; } this.refVecZ = refVec.toUnitVector(); Scientrace.Plane tPlane = Plane.newPlaneOrthogonalTo(new Scientrace.Location(0, 0, 0), refVec); this.refVecX = tPlane.u.toUnitVector(); this.refVecY = tPlane.v.toUnitVector(); }
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 void fillPlaneVectors(Scientrace.UnitVector surface_normal) { //"A = ref x norm" if (!this.plane_a_vecs.ContainsKey(surface_normal)) { this.plane_a_vecs.Add(surface_normal, this.referenceVector.safeNormalisedCrossProduct(surface_normal)); } //"B = norm x A" if (!this.plane_b_vecs.ContainsKey(surface_normal)) { this.plane_b_vecs.Add(surface_normal, surface_normal.safeNormalisedCrossProduct(this.plane_a_vecs[surface_normal])); } }
public double angleOnSurface(Scientrace.UnitVector aUnitVector) { double projection = aUnitVector.dotProduct(this.plane.getNorm()); if (Math.Abs(projection) > 1) { if ((Math.Abs(projection) - 1) < 1E-14) { //this 1.00[...]00x value is probably an error due to rounding. Cos 0 = 1, so return 0. return(0); } } return(Math.Acos(projection)); }
/// <summary> /// Required parameters: /// (Location) lens_sphere_location, /// (double) lens_sphere_radius /// (double) lens_sphere_radians_min /// (double) lens_sphere_radians_max /// (UnitVector) orientation_from_sphere_center /// </summary> /// <param name='shadowObject'> /// Shadow object containing parameters from summary. /// </param> protected void shadowFac_SphereCenter_And_Radians(ShadowScientrace.ShadowObject3d shadowObject) { //User values(s) Scientrace.Location lens_sphere_location = (Scientrace.Location)shadowObject.getObject("lens_sphere_location"); double lens_sphere_radius = (double)shadowObject.getObject("lens_sphere_radius"); double lens_sphere_radians_min = (double)shadowObject.getObject("lens_sphere_radians_min"); double lens_sphere_radians_max = (double)shadowObject.getObject("lens_sphere_radians_max"); Scientrace.UnitVector orientation_from_sphere_center = (Scientrace.UnitVector)shadowObject.getObject("orientation_from_sphere_center"); bool double_convex_ring = shadowObject.getNBool("double_convex") == true; //construct! this.paramInit(lens_sphere_location, lens_sphere_radius, lens_sphere_radians_min, lens_sphere_radians_max, orientation_from_sphere_center, double_convex_ring); }
public void write2dHistogramForPlane(Scientrace.PhysicalObject3d anObject, string plane_descr, Scientrace.UnitVector plane_vector) { Scientrace.UnitVector normvec = anObject.getSurfaceNormal(); Dictionary <string, double> angle_histogram = this.getHistogramTemplate(); foreach (Scientrace.Spot casualty in this.tj.spots) { //only count casualties for current object. if (casualty.object3d != anObject) { continue; } if (casualty == null) { Console.WriteLine("Error: Casualty is null when writing angle histogram2d for {" + anObject.ToString() + "} plane {" + plane_descr + "}..."); continue; } double angle_rad; if (plane_vector == null) { angle_rad = anObject.getSurfaceNormal().negative().angleWith(casualty.trace.traceline.direction); } else { //2d unraveling Scientrace.Vector vecOnPlane = casualty.trace.traceline.direction.projectOnPlaneWithNormal(plane_vector); //The angle on which the histogram bin is based. angle_rad = normvec.negative().angleWith(vecOnPlane); } string bin = this.radiansToRoundedDegString(angle_rad); double reweigh_factor = (this.lightsource_weigh_intensity) ? (casualty.trace.lightsource.weighted_intensity / casualty.trace.lightsource.total_lightsource_intensity) : 1; //Console.WriteLine("Line: "+casualty.trace.traceline.direction.trico()+" becomes: "+vecOnPlane.trico()+" angle:"+angle_rad+" / "+bin); this.addToBin(angle_histogram, bin, casualty.intensity * reweigh_factor, true); } string angle_histogram_csv_filename = this.tj.exportpath + this.angle_histogram_csv_filename.Replace("%o", anObject.tag).Replace("%t", this.tag).Replace("%s", plane_descr.Replace(" ", "_")); this.addHist2dConfigVars(normvec, plane_descr); //this.extra_exportable_config_vars.Add(plane_description, plane_vector); this.appendWriteWithConfigVariables(angle_histogram_csv_filename, angle_histogram); }
public StringBuilder drawSphereSlice(Scientrace.Object3d drawnObject3d, double lateral_circles, double meridians, Scientrace.Sphere sphere, double from_radians, double to_radians, Scientrace.UnitVector sliceAlongDirection) { System.Text.StringBuilder retx3d = new System.Text.StringBuilder(1024); //"<!-- DOUBLECONVEXLENS GRID start -->"); double pi2 = Math.PI * 2; NonzeroVector orthoBaseVec1 = null; NonzeroVector orthoBaseVec2 = null; sliceAlongDirection.fillOrtogonalVectors(ref orthoBaseVec1, ref orthoBaseVec2); for (double iSphereCircle = 2 * lateral_circles; iSphereCircle > 0; iSphereCircle--) // the rings/parallels along the sliceAlongDirection axis { double lateral_radians = (to_radians * (iSphereCircle / (2 * lateral_circles))); double circle2DRadius = sphere.radius * Math.Sin(lateral_radians); double circle2DDistance = sphere.radius * Math.Cos(lateral_radians); retx3d.Append(this.drawCircle(sphere.loc + (sliceAlongDirection * circle2DDistance).toLocation(), circle2DRadius, sliceAlongDirection)); for (double iSphereMerid = 0.5; iSphereMerid < 2 * meridians; iSphereMerid++) // meridians connect the rings/circles on the spherical surface { Scientrace.Location tNodeLoc = sphere.getSphericalLoc( orthoBaseVec1, orthoBaseVec2, sliceAlongDirection, to_radians * (iSphereCircle / (2 * lateral_circles)), // lat_angle = theta pi2 * (iSphereMerid / (2 * meridians)) // mer_angle = phi ); if (!tNodeLoc.isValid()) { throw new NullReferenceException("Cannot calculate base gridpoint at @ " + drawnObject3d.tag); } Scientrace.Location tLatConnectLoc = sphere.getSphericalLoc( orthoBaseVec1, orthoBaseVec2, sliceAlongDirection, to_radians * ((iSphereCircle - 1) / (2 * lateral_circles)), // lat_angle = theta pi2 * ((iSphereMerid) / (2 * meridians)) // mer_angle = phi ); if (!tLatConnectLoc.isValid()) { throw new NullReferenceException("Cannot calculate lateral gridpoint at @ " + drawnObject3d.tag); } Scientrace.X3DGridPoint tGridPoint = new Scientrace.X3DGridPoint(0, tNodeLoc, null, tLatConnectLoc); retx3d.AppendLine(tGridPoint.exportX3DnosphereRGB(this.primaryRGB)); } } // end for iSphereCircle / iSphereMerid return(retx3d); }
} // 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 SpiralLightSource(Scientrace.Object3dEnvironment env, Scientrace.Location center, Scientrace.UnitVector direction, Scientrace.Plane plane, int linecount, double radius, double loops, double distance, LightSpectrum spectrum) : base(env) { /*Scientrace.UniformTraceModifier utm = * //new UniformTraceModifier(DistributionPattern.PeriodicSingleCircle, SpatialDistribution.UniformAngles); * new UniformTraceModifier(DistributionPattern.SquareGrid, SpatialDistribution.UniformProjections); * utm.add_self = false; * utm.setMaxAngleDeg(0.5); * utm.modify_traces_count = 16; * utm.randomSeed = 1; * this.modifiers.Add(utm); */ //this.init_findmultip(env, center, direction, plane, linecount, radius, loops, spectrum); this.paramInit(center, direction, plane, linecount, radius, loops, distance); }
public void paramInit(Scientrace.Location center, Scientrace.UnitVector direction, Scientrace.Plane plane, int linecount, double radius, double loops, double distance) { this.loops = loops; this.radius = radius; this.center = center; //direction had been commented out. WHY? Re-enabled. this.direction = direction; this.spiral_plane = plane; this.tag = String.Format("{0:0.###}", loops) + "LoopSpiral"; this.distance = distance; //added later: this.linecount = linecount; //and removed again: //this.spectrum = spectrum; }
private void addHist2dConfigVars(Scientrace.UnitVector surface_normal, string plane_description) { this.extra_exportable_config_vars = new Dictionary <string, string>(); this.extra_exportable_config_vars.Add("norm x", surface_normal.x.ToString()); this.extra_exportable_config_vars.Add("norm y", surface_normal.y.ToString()); this.extra_exportable_config_vars.Add("norm z", surface_normal.z.ToString()); this.extra_exportable_config_vars.Add("ref x", this.referenceVector.x.ToString()); this.extra_exportable_config_vars.Add("ref y", this.referenceVector.y.ToString()); this.extra_exportable_config_vars.Add("ref z", this.referenceVector.z.ToString()); this.fillPlaneVectors(surface_normal); this.extra_exportable_config_vars.Add("A = ref x norm", this.plane_a_vecs[surface_normal].trico()); this.extra_exportable_config_vars.Add("B = norm x A", this.plane_b_vecs[surface_normal].trico()); this.extra_exportable_config_vars.Add("Plane", plane_description); }
public string x3dRotationTransform(Scientrace.Vector orivec) { //the Circle2D objects will normally be drawn in the x,y plane (perpendicular to 0,0,1) so it has to //rotated out of that plane as follows. Scientrace.UnitVector oriunivec = orivec.tryToUnitVector(); Scientrace.UnitVector uxv = (this.u.crossProduct(this.v).tryToUnitVector()); if (uxv == oriunivec) { return("<Transform rotation='0 0 0 0'>"); // throw new ArithmeticException("Plane vectors uxv ("+uxv.trico()+") & oriunivec ("+oriunivec.trico()+") are equal"); } try { Scientrace.UnitVector rotaxis = (oriunivec).crossProduct(uxv).tryToUnitVector(); return("<Transform rotation='" + rotaxis.trico() + " " + (oriunivec.angleWith(rotaxis)).ToString() + "'>"); } catch // possible error: zerovector after cross product (rounding error at first comparison), return zero rotation tag. { return("<Transform rotation='0 0 0 0'>"); } }
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); }
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 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 static Scientrace.Plane newPlaneOrthogonalTo(Scientrace.Location loc, Scientrace.NonzeroVector normalVec, Scientrace.NonzeroVector helpVec1, Scientrace.NonzeroVector helpVec2) { Scientrace.UnitVector unitvec = normalVec.toUnitVector(); Scientrace.UnitVector h1 = helpVec1.toUnitVector(); Scientrace.UnitVector h2 = helpVec2.toUnitVector(); if (h1.dotProduct(h2) >= 1) { throw new Scientrace.ParallelVectorException(h1, h2, " in newPlaneOrthogonalTo(3) factory method."); } Scientrace.UnitVector refvec = ( (Math.Abs(unitvec.dotProduct(h1)) < 0.8) ? h1 : h2 ); Scientrace.NonzeroVector u = unitvec.crossProduct(refvec).tryToUnitVector(); Scientrace.NonzeroVector v = unitvec.crossProduct(u).tryToUnitVector(); return(new Scientrace.Plane(loc, u, v)); }
public void setRefAxis(Scientrace.NonzeroVector refVec) { if (refVec==null) {return;} this.refVecZ = refVec.toUnitVector(); Scientrace.Plane tPlane = Plane.newPlaneOrthogonalTo(new Scientrace.Location(0,0,0), refVec); this.refVecX = tPlane.u.toUnitVector(); this.refVecY = tPlane.v.toUnitVector(); }
public Line(Line copyLine) { this.startingpoint = new Location(copyLine.startingpoint); this.direction = new UnitVector(copyLine.direction); }
public Line(double x, double y, double z, double dirx, double diry, double dirz) { this.startingpoint = new Scientrace.Location(x, y, z); this.direction = new Scientrace.UnitVector(dirx, diry, dirz); }
public void TestVectorProjection() { Scientrace.Vector aVec = new Scientrace.Vector(0.2, 0.3, 0.4); Scientrace.UnitVector normal = new Scientrace.UnitVector(0,0,-1); Assert.AreEqual(aVec.projectOnPlaneWithNormal(normal), new Scientrace.Vector(0.2, 0.3, 0)); }
public void paramInit(Scientrace.Location center, Scientrace.UnitVector direction, Scientrace.Plane plane, int linecount, double radius, double loops, double distance) { this.loops = loops; this.radius = radius; this.center = center; //direction had been commented out. WHY? Re-enabled. this.direction = direction; this.spiral_plane = plane; this.tag = String.Format("{0:0.###}",loops)+"LoopSpiral"; this.distance = distance; //added later: this.linecount = linecount; //and removed again: //this.spectrum = spectrum; }