示例#1
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();
 }
        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");
        }
示例#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
        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();
        }
        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);
        }
 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);
 }
 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));
 }
示例#8
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);
 }
示例#9
0
 public DistributionSquare getDistributionSquare(Scientrace.PhysicalObject3d anObject, int order)
 {
     Scientrace.Parallelogram      surface = anObject.getDistributionSurface();
     Scientrace.DistributionSquare ds      = new Scientrace.DistributionSquare(0, order, surface.plane.loc, surface.plane.u, surface.plane.v);
     foreach (Scientrace.Spot aSpot in this.spots)
     {
         ds.addSpot(aSpot.loc);
     }
     return(ds);
 }
示例#10
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);
 }
示例#11
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);
        }
示例#12
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);
        }
示例#13
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);
 }
示例#14
0
 public void PGramDiagonalSurfaceTest1()
 {
     Scientrace.Parallelogram a = new Scientrace.Parallelogram(new Scientrace.Location(1, 2, 3), new Scientrace.NonzeroVector(3, 4, 5), new Scientrace.NonzeroVector(3, 4, 0));
     Assert.AreEqual(25, a.getSurfaceSize());
 }
示例#15
0
 public void PGramDiagonalSurfaceTest1()
 {
     Scientrace.Parallelogram a = new Scientrace.Parallelogram(new Scientrace.Location(1, 2, 3), new Scientrace.NonzeroVector(3, 4, 5), new Scientrace.NonzeroVector(3, 4, 0));
     Assert.AreEqual(25, a.getSurfaceSize());
 }
示例#16
0
 public void PGramSquareSurfaceTest()
 {
     Scientrace.Parallelogram a = new Scientrace.Parallelogram(new Scientrace.Location(10, 10, 10), new Scientrace.NonzeroVector(3, 4, 0), new Scientrace.NonzeroVector(0, 0, 5));
     Assert.AreEqual(25, a.getSurfaceSize());
 }
示例#17
0
 public void PGramSquareSurfaceTest()
 {
     Scientrace.Parallelogram a = new Scientrace.Parallelogram(new Scientrace.Location(10, 10, 10), new Scientrace.NonzeroVector(3, 4, 0), new Scientrace.NonzeroVector(0, 0, 5));
     Assert.AreEqual(25, a.getSurfaceSize());
 }
示例#18
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);
 }
示例#19
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));
 }
示例#20
0
 public Scientrace.Location intersects(Scientrace.Parallelogram par)
 {
     return(par.atPath(this));
 }
示例#21
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);
 }