コード例 #1
0
        public Scientrace.SingleRaySource setSingleRayFromXData(XElement xlight, List <Scientrace.UniformTraceModifier> utms,
                                                                Scientrace.Object3dEnvironment env)
        {
            double distance     = this.X.getXDouble(xlight.Attribute("Distance"), 0);
            int    beamcount    = this.X.getXInt(xlight.Attribute("RayCount"), this.X.getXInt(xlight.Attribute("BeamCount"), 1));
            double minintensity = this.X.getXDouble(xlight, "MinIntensity", 0.01);             //default minimum intensity for tracing set to 1%

            Scientrace.NonzeroVector light_direction = this.X.getXNzVector(xlight.Element("Direction"));
            Scientrace.Location      centerloc       = this.X.getXVector(xlight.Element("Location")).toLocation();
            Scientrace.Location      locoffset       = (light_direction.toVector().negative() * distance).toLocation(); //distance cm above surface
            Scientrace.Location      loc             = locoffset + centerloc;
            XMLSpectrumParser        xsp             = new XMLSpectrumParser();

            Scientrace.LightSpectrum spectrum = xsp.parseLightSpectrum(xlight.Element("Spectrum"));
            if (spectrum == null)
            {
                throw new Exception("LightSpectrum " + xlight.Element("Spectrum").ToString() + " unknown");
            }

            Scientrace.SingleRaySource retlight = new Scientrace.SingleRaySource(new Scientrace.Line(loc, light_direction.toUnitVector()),
                                                                                 beamcount, spectrum, env);

            retlight.minimum_intensity_fraction = minintensity;
            retlight.lightsource_modifiers.AddRange(utms);
            retlight.init();
            return(retlight);
        }
コード例 #2
0
 public static void readCameraSettings(XElement x3d_or_xenv_element)
 {
     CustomXMLDocumentOperations X = new CustomXMLDocumentOperations();
     Scientrace.Vector cameraviewpoint = Scientrace.TraceJournal.Instance.cameraviewpoint;
     Scientrace.Vector camrotationvec = Scientrace.TraceJournal.Instance.camrotationvector;
     Scientrace.TraceJournal.Instance.labelaxes = X.getXBool(x3d_or_xenv_element, "DrawAxes", Scientrace.TraceJournal.Instance.labelaxes);
     double camrotationangle = Scientrace.TraceJournal.Instance.camrotationangle;
     XElement camfrom = (x3d_or_xenv_element == null? null:x3d_or_xenv_element.Element("CameraFrom"));
     XElement camrot = (x3d_or_xenv_element == null? null:x3d_or_xenv_element.Element("CameraRotation"));
     if (camfrom !=null) {
     cameraviewpoint = X.getXNzVector(camfrom);
     Scientrace.Vector camdirvec = cameraviewpoint.negative();
     Scientrace.NonzeroVector defvec = new Scientrace.NonzeroVector(0,0,-1);
     camrotationangle = defvec.angleWith(camdirvec);
     camrotationvec = defvec.crossProduct(camdirvec);
     }
     if (camrot != null) {
     camrotationvec = X.getXVectorByName(camrot, "Vector");
     camrotationangle = X.getXAngleByName(camrot, "Angle");
     }
     Scientrace.TraceJournal.Instance.cameraviewpoint = X.getXVectorByName(x3d_or_xenv_element, "CameraViewpoint", cameraviewpoint);
     Scientrace.TraceJournal.Instance.camrotationangle = camrotationangle;
     if (camrotationvec != null)
     Scientrace.TraceJournal.Instance.camrotationvector = camrotationvec;
 }
コード例 #3
0
        public void PGramDiagonalSurfacePerformanceTest()
        {
            DateTime startTime = DateTime.Now;
            double   x1, x2, y1, y2, z1, z2, foo = 1;

            for (x1 = 0; x1 < 10000; x1++)
            {
                x2 = -3;
                y1 = 56;
                y2 = 12;
                z1 = -2;
                z2 = 23;
                Scientrace.NonzeroVector nzv1 = new Scientrace.NonzeroVector(x1, y1, z1);
                Scientrace.NonzeroVector nzv2 = new Scientrace.NonzeroVector(x2, y2, z2);
                Scientrace.Parallelogram a    = new Scientrace.Parallelogram(new Scientrace.Location(1, 2, 3), nzv1, nzv2);
                //comparing surface calculated by sine of the angle between vectors and multiplication with their lengths with the lenght of the outproduct
                if (Math.Sin(Math.Acos(nzv1.toUnitVector().dotProduct(nzv2.toUnitVector()))) * nzv1.length * nzv2.length != a.getSurfaceSize())
                {
                    //Assert.AreEqual(Math.Sin(Math.Acos(nzv1.toUnitVector().dotProduct(nzv2.toUnitVector())))*nzv1.length*nzv2.length, a.getSurface(), 1e-10);
                    foo++;
                }
            }
            DateTime stopTime = DateTime.Now;
            TimeSpan duration = stopTime - startTime;

            Console.WriteLine(foo.ToString() + " siginificance failures");
            //making sure these 10 000 dotproducts and crossproducts comparisons can be executed within 60 milliseconds
            Assert.Less(duration.Milliseconds, 60);
        }
コード例 #4
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;
 }
コード例 #5
0
        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");
        }
コード例 #6
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);
 }
コード例 #7
0
 public void PGramDiagonalSurfacePerformanceTest()
 {
     DateTime startTime = DateTime.Now;
     double x1, x2, y1, y2, z1, z2, foo = 1;
     for (x1 = 0; x1 < 10000; x1++) {
     x2 = -3;
     y1 = 56;
     y2 = 12;
     z1 = -2;
     z2 = 23;
     Scientrace.NonzeroVector nzv1 = new Scientrace.NonzeroVector(x1, y1, z1);
     Scientrace.NonzeroVector nzv2 = new Scientrace.NonzeroVector(x2, y2, z2);
     Scientrace.Parallelogram a = new Scientrace.Parallelogram(new Scientrace.Location(1, 2, 3), nzv1, nzv2);
     //comparing surface calculated by sine of the angle between vectors and multiplication with their lengths with the lenght of the outproduct
     if (Math.Sin(Math.Acos(nzv1.toUnitVector().dotProduct(nzv2.toUnitVector())))*nzv1.length*nzv2.length != a.getSurfaceSize()) {
         //Assert.AreEqual(Math.Sin(Math.Acos(nzv1.toUnitVector().dotProduct(nzv2.toUnitVector())))*nzv1.length*nzv2.length, a.getSurface(), 1e-10);
         foo++;
     }
     }
     DateTime stopTime = DateTime.Now;
     TimeSpan duration = stopTime-startTime;
     Console.WriteLine(foo.ToString()+" siginificance failures");
     //making sure these 10 000 dotproducts and crossproducts comparisons can be executed within 60 milliseconds
     Assert.Less(duration.Milliseconds, 60);
 }
コード例 #8
0
        public static void readCameraSettings(XElement x3d_or_xenv_element)
        {
            CustomXMLDocumentOperations X = new CustomXMLDocumentOperations();

            Scientrace.Vector cameraviewpoint = Scientrace.TraceJournal.Instance.cameraviewpoint;
            Scientrace.Vector camrotationvec  = Scientrace.TraceJournal.Instance.camrotationvector;
            Scientrace.TraceJournal.Instance.labelaxes = X.getXBool(x3d_or_xenv_element, "DrawAxes", Scientrace.TraceJournal.Instance.labelaxes);
            double   camrotationangle = Scientrace.TraceJournal.Instance.camrotationangle;
            XElement camfrom          = (x3d_or_xenv_element == null? null:x3d_or_xenv_element.Element("CameraFrom"));
            XElement camrot           = (x3d_or_xenv_element == null? null:x3d_or_xenv_element.Element("CameraRotation"));

            if (camfrom != null)
            {
                cameraviewpoint = X.getXNzVector(camfrom);
                Scientrace.Vector        camdirvec = cameraviewpoint.negative();
                Scientrace.NonzeroVector defvec    = new Scientrace.NonzeroVector(0, 0, -1);
                camrotationangle = defvec.angleWith(camdirvec);
                camrotationvec   = defvec.crossProduct(camdirvec);
            }
            if (camrot != null)
            {
                camrotationvec   = X.getXVectorByName(camrot, "Vector");
                camrotationangle = X.getXAngleByName(camrot, "Angle");
            }
            Scientrace.TraceJournal.Instance.cameraviewpoint  = X.getXVectorByName(x3d_or_xenv_element, "CameraViewpoint", cameraviewpoint);
            Scientrace.TraceJournal.Instance.camrotationangle = camrotationangle;
            if (camrotationvec != null)
            {
                Scientrace.TraceJournal.Instance.camrotationvector = camrotationvec;
            }
        }
コード例 #9
0
        /* END CONSTRUCTORS */

        public override bool directedTowardsObjectside(Scientrace.SurfaceSide side, Trace aTrace)
        {
            Scientrace.NonzeroVector traceline_direction = aTrace.traceline.direction;
            switch (side)
            {
            case Scientrace.SurfaceSide.Back:             // == SurfaceSide.Inside
                // Vector is directed TOWARDS (so in the contrary direction) of the surface normal
//				if (aVector.dotProduct(this.front_normal_direction)>0)

                /*Console.WriteLine(aTrace.traceid+" analysing: "+traceline_direction.tricon()+" from: "+aTrace.traceline.startingpoint.tricon()+
                 *      aTrace.parent.intensityFraction()+" = intensity \n"+
                 *      " DISTANCE: "+(aTrace.endloc-aTrace.traceline.startingpoint).length +" direction along: "+this.front_normal_direction.trico()+ " @"+aTrace.currentObject.GetType()); */
                return(traceline_direction.dotProduct(this.front_normal_direction) > 0);

            //break;
            case Scientrace.SurfaceSide.Front:
                // Vector is directed AWAY FROM (so along the direction) of the surface normal
                return(traceline_direction.dotProduct(this.front_normal_direction) < 0);

            //break;
            case Scientrace.SurfaceSide.Both:
                return(true);

            //break;
            default:
                throw new NotImplementedException("Side " + side.ToString() + " not implemented");
                //break;
            }
        }
コード例 #10
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;
 }
コード例 #11
0
ファイル: VectorTest.cs プロジェクト: xiaohuangyu/scientrace
 public void TestNormalizing()
 {
     Scientrace.NonzeroVector v1 = new Scientrace.NonzeroVector(1, 2, 3);
     Scientrace.NonzeroVector v2 = v1.copy().tryToNonzeroVector();
     v2.normalize();
     Assert.AreEqual(v1.normalized(), v2);
 }
コード例 #12
0
 protected void init_Loc_width_height(Scientrace.Location loc, Scientrace.NonzeroVector u, Scientrace.NonzeroVector v)
 {
     this.parallelogram          = new Scientrace.Parallelogram(loc, u, v);
     this.front_normal_direction = u.crossProduct(v).tryToUnitVector();
     this.preserveSVGRatio();
     this.addSurfaceMarkers();
 }
コード例 #13
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
 }
コード例 #14
0
ファイル: CircularPrism.cs プロジェクト: JoepBC/scientrace
 //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;
 }
コード例 #15
0
 public void rotateAboutY(double angle, Scientrace.Location center)
 {
     this.loc    = ((this.loc - center).rotateAboutY(angle)).toLocation() + center;
     this.width  = this.width.rotateAboutY(angle);
     this.length = this.length.rotateAboutY(angle);
     this.height = this.height.rotateAboutY(angle);
     this.trf    = null;
 }
コード例 #16
0
ファイル: RectangularPrism.cs プロジェクト: JoepBC/scientrace
 //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;
 }
コード例 #17
0
 public void PGramAngleTest2()
 {
     Scientrace.Location loc = new Scientrace.Location(1, 2, 3);
     Scientrace.NonzeroVector v1 = new Scientrace.NonzeroVector(-1, 1, 0);
     Scientrace.NonzeroVector v2 = new Scientrace.NonzeroVector(-1, 0, 1);
     Scientrace.NonzeroVector v3 = new Scientrace.NonzeroVector(1, 1, 1);
     Scientrace.Parallelogram pg = new Scientrace.Parallelogram(loc, v1, v2);
     Assert.AreEqual(pg.angleOnSurface(v3), 0, 1E-15);
 }
コード例 #18
0
ファイル: PlaneBorder.cs プロジェクト: xiaohuangyu/scientrace
 public PlaneBorder(Scientrace.Location loc, Scientrace.NonzeroVector allowedDirectionSurfaceNormal)
 {
     this.loc = loc;
     this.allowedDirNormal = allowedDirectionSurfaceNormal;
     this.radius           = allowedDirectionSurfaceNormal.length;
     this.allowedDirNormal.fillOrtogonalVectors(ref this.planeBaseVec1, ref this.planeBaseVec2);
     this.trf    = this.createNewTransform();
     this.tPlane = new Scientrace.Plane(this.loc, this.planeBaseVec1, this.planeBaseVec2);
 }
コード例 #19
0
 public void PGramAngleTest2()
 {
     Scientrace.Location      loc = new Scientrace.Location(1, 2, 3);
     Scientrace.NonzeroVector v1  = new Scientrace.NonzeroVector(-1, 1, 0);
     Scientrace.NonzeroVector v2  = new Scientrace.NonzeroVector(-1, 0, 1);
     Scientrace.NonzeroVector v3  = new Scientrace.NonzeroVector(1, 1, 1);
     Scientrace.Parallelogram pg  = new Scientrace.Parallelogram(loc, v1, v2);
     Assert.AreEqual(pg.angleOnSurface(v3), 0, 1E-15);
 }
コード例 #20
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));
 }
コード例 #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
 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));
 }
コード例 #23
0
        public Scientrace.CylindricalBorder getCylindricalBorder(XElement xborder)
        {
            Scientrace.Location      loc    = this.X.getXLocation(xborder.Element("Location"));
            Scientrace.NonzeroVector dirlen = this.X.getXNzVector(xborder.Element("DirectionLength"));
            double radius = this.X.getXDouble(xborder.Attribute("Radius"));

            Scientrace.CylindricalBorder retcyl = new Scientrace.CylindricalBorder(loc, dirlen, radius);
            return(retcyl);
        }
コード例 #24
0
ファイル: PlaneBorder.cs プロジェクト: JoepBC/scientrace
 public PlaneBorder(Scientrace.Location loc, Scientrace.NonzeroVector allowedDirectionSurfaceNormal)
 {
     this.loc = loc;
     this.allowedDirNormal = allowedDirectionSurfaceNormal;
     this.radius = allowedDirectionSurfaceNormal.length;
     this.allowedDirNormal.fillOrtogonalVectors(ref this.planeBaseVec1, ref this.planeBaseVec2);
     this.trf = this.createNewTransform();
     this.tPlane = new Scientrace.Plane(this.loc, this.planeBaseVec1, this.planeBaseVec2);
 }
コード例 #25
0
        /// <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_Loc_width_height(ShadowScientrace.ShadowObject3d shadowObject)
        {
            //User values(s)
            Scientrace.Location      corner_location = shadowObject.getLocation("corner_location");
            Scientrace.NonzeroVector width           = shadowObject.getNzVector("width");
            Scientrace.NonzeroVector height          = shadowObject.getNzVector("height");

            //construct!
            this.init_Loc_width_height(corner_location, width, height);
        }
コード例 #26
0
 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();
 }
コード例 #27
0
        /* LINEAR MODIFIER METHODS >>> */

        public Scientrace.Plane linearModify(Scientrace.Plane aPlane)
        {
            Scientrace.NonzeroVector aSurfaceNormal = aPlane.getNorm();
            Scientrace.NonzeroVector newNormal      =
                this.modify(aSurfaceNormal,
                            this.random_modification_select ? this.getRandomNodeNumber() : this.getNextNodeNumber(),
                            this.modify_traces_count);
            return(Scientrace.Plane.newPlaneOrthogonalTo(aPlane.loc,
                                                         newNormal, aPlane.u, aPlane.v));
        }
コード例 #28
0
 public VectorTransformOrthonormal(Scientrace.NonzeroVector u, Scientrace.NonzeroVector v, int swapz) : base(u, v, swapz)
 {
     //built in margin of 1E-15 on orthogonal-dotproduct-mismatch for an orthonormal base
     if (Math.Abs(this.u.dotProduct(this.v)) + Math.Abs(this.v.dotProduct(this.w)) + Math.Abs(this.w.dotProduct(this.u)) > 1E-15)
     {
         Console.Write(this.ToString());
         throw new Exception("Vectors not orthogonal" + Math.Abs(this.u.dotProduct(this.v)) + "v" + Math.Abs(this.v.dotProduct(this.w)) + "w" + Math.Abs(this.w.dotProduct(this.u)));
     }
     this.normalize();
 }
コード例 #29
0
 public void TransformMatrixTest()
 {
     Scientrace.NonzeroVector u, v;
     u = new Scientrace.NonzeroVector(2, 3, 4);
     v = new Scientrace.NonzeroVector(1, 2, 3);
     Scientrace.VectorTransform foo  = new Scientrace.VectorTransform(u, v);
     Scientrace.Vector          tvec = foo.transform(new Scientrace.Vector(1, 1.5, 2));
     Assert.AreEqual(tvec.x, 0.5);
     Assert.AreEqual(tvec.y, 0, 1E-15);
     Assert.AreEqual(tvec.z, 0, 1E-15);
 }
コード例 #30
0
 public void TransformMatrixAndBackToStringTest()
 {
     Scientrace.NonzeroVector u, v;
     u = new Scientrace.NonzeroVector(5, 2, 4);
     v = new Scientrace.NonzeroVector(3, 2, 3);
     Scientrace.VectorTransform foo      = new Scientrace.VectorTransform(u, v);
     Scientrace.Vector          orivec   = new Scientrace.Vector(5, 1, 2);
     Scientrace.Vector          tvec     = foo.transform(orivec);
     Scientrace.Vector          tbackvec = foo.transformback(tvec);
     Assert.AreEqual(orivec.ToCompactString(), tbackvec.ToCompactString());
 }
コード例 #31
0
ファイル: Sphere.cs プロジェクト: xiaohuangyu/scientrace
 public Location getSphericalLoc(Scientrace.NonzeroVector xvec, Scientrace.NonzeroVector yvec,
                                 Scientrace.NonzeroVector zvec,
                                 Scientrace.Vector sphereCenter, double sphereRadius,
                                 double theta, double phi)
 {
     return(this.getEllipsoidLoc(
                xvec.normalizedVector() * sphereRadius,
                yvec.normalizedVector() * sphereRadius,
                zvec.normalizedVector() * sphereRadius,
                sphereCenter, theta, phi));
 }
コード例 #32
0
ファイル: Sphere.cs プロジェクト: xiaohuangyu/scientrace
 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();
 }
コード例 #33
0
 public void TransformMatrixAndBackTest2()
 {
     Scientrace.NonzeroVector u, v;
     u = new Scientrace.NonzeroVector(2.3, 3.2, 4.23);
     v = new Scientrace.NonzeroVector(3.14, 2.12, 3);
     Scientrace.VectorTransform foo      = new Scientrace.VectorTransform(u, v);
     Scientrace.Vector          tvec     = foo.transform(new Scientrace.Vector(6, 3, 8));
     Scientrace.Vector          tbackvec = foo.transformback(tvec);
     Assert.AreEqual(tbackvec.x, 6, 1E-14);
     Assert.AreEqual(tbackvec.y, 3, 1E-14);
     Assert.AreEqual(tbackvec.z, 8, 1E-14);
 }
コード例 #34
0
 protected void paramInit(Scientrace.Location loc, Scientrace.NonzeroVector width, Scientrace.NonzeroVector height,
                          Scientrace.NonzeroVector length)
 {
     if ((loc.x == Double.NaN) || (loc.y == Double.NaN) || (loc.z == Double.NaN))
     {
         throw new ArgumentNullException("Location must be numerical!");
     }
     this.loc    = loc;
     this.width  = width;
     this.length = length;
     this.height = height;
 }
コード例 #35
0
        /// <summary>
        /// Required parameters:
        /// (Location)lens_center
        /// (NonzeroVector)optical_axis
        /// (double)lens_diameter
        /// (double)sphere1_radius
        /// (double)sphere2_radius
        /// </summary>
        /// <param name='shadowObject'>
        /// Shadow object containing parameters from summary.
        /// </param>
        protected void shadowFac_TwoRadii_and_Diameter(ShadowScientrace.ShadowObject3d shadowObject)
        {
            //User values(s)
            Scientrace.Location      lensCenter  = (Scientrace.Location)shadowObject.getObject("lens_center");
            Scientrace.NonzeroVector opticalAxis = (Scientrace.NonzeroVector)shadowObject.getObject("optical_axis");

            double lensDiameter  = (double)shadowObject.getObject("lens_diameter");
            double sphere1Radius = (double)shadowObject.getObject("sphere1_radius");
            double sphere2Radius = (double)shadowObject.getObject("sphere2_radius");

            this.initWithLensDiameter(lensCenter, opticalAxis, lensDiameter, sphere1Radius, sphere2Radius);
        }
コード例 #36
0
 public void PGramLineIntersects()
 {
     Scientrace.Location      loc = new Scientrace.Location(1, 2, 3);
     Scientrace.NonzeroVector v1  = new Scientrace.NonzeroVector(1, 0, 0);
     Scientrace.NonzeroVector v2  = new Scientrace.NonzeroVector(0, 1, 0);
     Scientrace.Parallelogram pg  = new Scientrace.Parallelogram(loc, v1, v2);
     //this line intersects the defined plane at (5,5,3)
     Scientrace.Vector intersection = pg.plane.lineThroughPlane(new Scientrace.Line(1, 1, -1, 2, 2, 2));
     Assert.AreEqual(intersection.x, 5);
     Assert.AreEqual(intersection.y, 5);
     Assert.AreEqual(intersection.z, 3);
 }
コード例 #37
0
        public string getX3DRotationTag(Scientrace.NonzeroVector fromVector, Scientrace.NonzeroVector toVector)
        {
            Scientrace.Vector r     = fromVector.crossProduct(toVector);
            double            angle =
                Math.Acos(toVector.normalized().dotProduct(fromVector.normalized()))         // the angle to be rotated
                * Math.Sign(r.crossProduct(fromVector).dotProduct(toVector));

            try {
                return("<Transform rotation='" + r.tryToUnitVector().trico() + " " + angle + "' >");
            } catch {                  // if fromVector has the same direction as toVector, the crossProduct is a zerovector which cannot be normalized.
                return("<Transform>"); //no transformation, just open so it can be closed afterwards
            }
        }
コード例 #38
0
ファイル: BoxBorder.cs プロジェクト: JoepBC/scientrace
        /*	public Scientrace.Object3d parentObject;*/
        public BoxBorder(Scientrace.Location loc, Scientrace.NonzeroVector width, Scientrace.NonzeroVector height, Scientrace.NonzeroVector length /*, Scientrace.Object3d parentObject*/)
        {
            this.loc = loc;
            this.width = width;
            this.length = length;
            this.height = height;
            /*		this.parentObject = parentObject; */

            //defining the sides of the box
            this.pgrams.Add(new Parallelogram(loc, width, height));
            this.pgrams.Add(new Parallelogram(loc+length, width, height));
            this.pgrams.Add(new Parallelogram(loc, height, length));
            this.pgrams.Add(new Parallelogram(loc+width, height, length));
            this.pgrams.Add(new Parallelogram(loc, width, length));
            this.pgrams.Add(new Parallelogram(loc+height, width, length));
        }
コード例 #39
0
 public void PGramIntersectionAtBaseVectors2()
 {
     Scientrace.Location loc = new Scientrace.Location(1, 2, 3);
     Scientrace.NonzeroVector v1 = new Scientrace.NonzeroVector(2, 5, 7);
     Scientrace.NonzeroVector v2 = new Scientrace.NonzeroVector(3, 2, 0);
     Scientrace.Parallelogram pg = new Scientrace.Parallelogram(loc, v1, v2);
     Scientrace.Vector intersection = pg.plane.lineThroughPlane(new Scientrace.Line(1, 1, -1, 2, 2, 2));
     Scientrace.VectorTransform trf = pg.plane.getTransform();
     Scientrace.Vector tintersection = trf.transform(intersection-loc);
     /* when the pgram-plane is shifted through 0,0,0, a transformation of any location in this plane to
      * the base vectors e1 and e2 (based on v1 and v2) should leave a 3rd coordinate set to zero. */
     Assert.AreEqual(tintersection.z, 0, 1E-14);
 }
コード例 #40
0
ファイル: TriangularPrism.cs プロジェクト: JoepBC/scientrace
        protected void paramInit(Scientrace.Location loc, Scientrace.NonzeroVector width, Scientrace.NonzeroVector height, 
		Scientrace.NonzeroVector length)
        {
            if ((loc.x == Double.NaN) || (loc.y == Double.NaN) || (loc.z == Double.NaN) ){
            throw new ArgumentNullException("Location must be numerical!");
            }
            this.loc = loc;
            this.width = width;
            this.length = length;
            this.height = height;
        }
コード例 #41
0
 public void PGramLineIntersects()
 {
     Scientrace.Location loc = new Scientrace.Location(1, 2, 3);
     Scientrace.NonzeroVector v1 = new Scientrace.NonzeroVector(1, 0, 0);
     Scientrace.NonzeroVector v2 = new Scientrace.NonzeroVector(0, 1, 0);
     Scientrace.Parallelogram pg = new Scientrace.Parallelogram(loc, v1, v2);
     //this line intersects the defined plane at (5,5,3)
     Scientrace.Vector intersection = pg.plane.lineThroughPlane(new Scientrace.Line(1, 1, -1, 2, 2, 2));
     Assert.AreEqual(intersection.x, 5);
     Assert.AreEqual(intersection.y, 5);
     Assert.AreEqual(intersection.z, 3);
 }
コード例 #42
0
 public CylindricalBorder(Scientrace.Location loc, Scientrace.NonzeroVector directionlength, double radius)
 {
     this.radius = radius;
     this.loc = loc;
     this.directionlength = directionlength;
 }
コード例 #43
0
 public void PGramDiagonalSurfaceTest2()
 {
     double x1, x2, y1, y2, z1, z2;
     x1 = 4;
     x2 = -3;
     y1 = 56;
     y2 = 12;
     z1 = -2;
     z2 = 23;
     Scientrace.NonzeroVector nzv1 = new Scientrace.NonzeroVector(x1, y1, z1);
     Scientrace.NonzeroVector nzv2 = new Scientrace.NonzeroVector(x2, y2, z2);
     Scientrace.Parallelogram a = new Scientrace.Parallelogram(new Scientrace.Location(1, 2, 3), nzv1, nzv2);
     //comparing surface calculated by sine of the angle between vectors and multiplication with their lengths with the lenght of the outproduct
     Assert.AreEqual(
     Math.Sin(Math.Acos(nzv1.toUnitVector().dotProduct(nzv2.toUnitVector())))*nzv1.length*nzv2.length,
     a.getSurfaceSize(),
     1E-12);
 }
コード例 #44
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));
 }
コード例 #45
0
ファイル: VectorTest.cs プロジェクト: JoepBC/scientrace
 public void TestNormalizing()
 {
     Scientrace.NonzeroVector v1 = new Scientrace.NonzeroVector(1,2,3);
     Scientrace.NonzeroVector v2 = v1.copy().tryToNonzeroVector();
     v2.normalize();
     Assert.AreEqual(v1.normalized(), v2);
 }
コード例 #46
0
ファイル: Plane.cs プロジェクト: JoepBC/scientrace
 public Plane(Scientrace.Location loc, Scientrace.NonzeroVector u, Scientrace.NonzeroVector v)
 {
     this.loc = loc;
     this.u = u;
     this.v = v;
 }
コード例 #47
0
ファイル: Plane.cs プロジェクト: JoepBC/scientrace
 /// <summary>
 /// Copy Constructor Initializes a new instance of the <see cref="Scientrace.Plane"/> class.
 /// </summary>
 /// <param name='aPlane'>
 /// A plane instance with the same (copied) values (yet different instances) as parameters.
 /// </param>
 public Plane(Scientrace.Plane aPlane)
 {
     this.loc = aPlane.loc.copy();
     this.u = aPlane.u.copy();
     this.v = aPlane.v.copy();
 }
コード例 #48
0
ファイル: BoxBorder.cs プロジェクト: JoepBC/scientrace
 public void rotateAboutY(double angle, Scientrace.Location center)
 {
     this.loc = ((this.loc - center).rotateAboutY(angle)).toLocation()+center;
     this.width = this.width.rotateAboutY(angle);
     this.length = this.length.rotateAboutY(angle);
     this.height = this.height.rotateAboutY(angle);
     this.trf = null;
 }