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());
 }
 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);
 }
Example #3
0
        private Scientrace.NonzeroVector calcTriangleHeightVector(ShadowObject3d sho3d)
        {
            Scientrace.Vector length    = sho3d.getVector("length");
            Scientrace.Vector width     = sho3d.getVector("width");
            Scientrace.Vector heightdir = sho3d.getVector("heightdir");

            double angle = sho3d.getDouble("angle");

            //create a vector orthogonal to length en width in the same binary direction as heightdir.
            Scientrace.UnitVector owl = (width.crossProduct(length) *
                                         Math.Sign(width.crossProduct(length).dotProduct(heightdir))).tryToUnitVector();

            Scientrace.NonzeroVector bdir = (     //calculate the direction of the short side of the prism
                owl * Math.Sin(angle) +
                width.tryToUnitVector() * Math.Cos(angle)
                ).tryToNonzeroVector();
            if ((bdir.length < 0.99999) || (bdir.length > 1.00001))
            {
                throw new ArgumentOutOfRangeException("bdir.length", bdir.length, "!= 1");
            }

            Scientrace.VectorTransform trf = new Scientrace.VectorTransform(
                width.tryToNonzeroVector(), owl.tryToNonzeroVector(), length.tryToNonzeroVector());
            Scientrace.NonzeroVector hdirtrf   = trf.transform(heightdir).tryToNonzeroVector();
            Scientrace.Vector        hprimetrf = new Scientrace.Vector(hdirtrf.x, hdirtrf.y, 0); //eliminate "length" component of heightdir in hprime
            //Console.WriteLine("HPRIMTRF:"+hprimetrf.trico());
            Scientrace.NonzeroVector hprimedir = trf.transformback(hprimetrf).tryToNonzeroVector().normalized();

            /*       ^
             *      /C\
             *     /   \
             *  h'/     \ b
             *   /       \
             *  /B_______A\
             *     width
             * angle = A; beta = B; gamma = C.
             */
            //sine rule: hprimelen / sin A = width.length() / sin C = blen / sin B
            double beta, gamma;

            beta  = Math.Acos(hprimedir.normalized().dotProduct(width.tryToNonzeroVector().normalized()));
            gamma = Math.PI - (angle + beta);
            double hprimelen;
            double sinruleconstant = width.length / Math.Sin(gamma);

            hprimelen = sinruleconstant * Math.Sin(angle);
            Scientrace.NonzeroVector hprime = hprimedir * hprimelen;

            // check: (trf.transform(hprime).x / hdirtrf.x) == (trf.transform(hprime).y / hdirtrf.y)
            double xycoeff = ((trf.transform(hprime).x / hdirtrf.x) / (trf.transform(hprime).y / hdirtrf.y));

            if (Math.Abs(1 - xycoeff) > 0.00001)   //doesn't do anything if .x/.x = NaN, but that's OK for now.
            {
                throw new ArgumentOutOfRangeException("xycoeff", xycoeff, "!=1");
            }

            try {
                Scientrace.NonzeroVector h = ((Math.Abs(hdirtrf.x) > Math.Abs(hdirtrf.y)) ? // Preventing .x or .y denominator == 0 errors.
                                              trf.transformback(hdirtrf * (trf.transform(hprime).x / hdirtrf.x)) :
                                              trf.transformback(hdirtrf * (trf.transform(hprime).y / hdirtrf.y))
                                              ).tryToNonzeroVector();

                return(h);
            } catch (Scientrace.ZeroNonzeroVectorException zne)     {
                Console.WriteLine("ERROR: calculated height for triangularprism has length zero!");
                throw (zne);
            }
        }         //end calcTriangleHeightVector
Example #4
0
 /// <summary>
 /// If a vector 1,0,0 would be transformed back by vectortransform trf this would be its length
 /// </summary>
 /// <param name="trf">
 /// A <see cref="Scientrace.VectorTransform"/>
 /// </param>
 /// <returns>
 /// A <see cref="System.Double"/> the length of the backtransform of 1,0,0
 /// </returns>
 public static double x1trbl(Scientrace.VectorTransform trf)
 {
     return(trf.transformback(Scientrace.Vector.x1vector()).length);
 }
        private Scientrace.NonzeroVector calcTriangleHeightVector(ShadowObject3d sho3d)
        {
            Scientrace.Vector length = sho3d.getVector("length");
            Scientrace.Vector width = sho3d.getVector("width");
            Scientrace.Vector heightdir = sho3d.getVector("heightdir");

            double angle = sho3d.getDouble("angle");

            //create a vector orthogonal to length en width in the same binary direction as heightdir.
            Scientrace.UnitVector owl = (width.crossProduct(length) *
                    Math.Sign(width.crossProduct(length).dotProduct(heightdir))).tryToUnitVector();

            Scientrace.NonzeroVector bdir = ( //calculate the direction of the short side of the prism
                                        owl*Math.Sin(angle) +
                                        width.tryToUnitVector()*Math.Cos(angle)
                                            ).tryToNonzeroVector();
            if ((bdir.length < 0.99999) || (bdir.length > 1.00001)) {
                throw new ArgumentOutOfRangeException("bdir.length", bdir.length, "!= 1");
                }

            Scientrace.VectorTransform trf = new Scientrace.VectorTransform(
            width.tryToNonzeroVector(), owl.tryToNonzeroVector(), length.tryToNonzeroVector());
            Scientrace.NonzeroVector hdirtrf = trf.transform(heightdir).tryToNonzeroVector();
            Scientrace.Vector hprimetrf = new Scientrace.Vector(hdirtrf.x, hdirtrf.y, 0); //eliminate "length" component of heightdir in hprime
            //Console.WriteLine("HPRIMTRF:"+hprimetrf.trico());
            Scientrace.NonzeroVector hprimedir = trf.transformback(hprimetrf).tryToNonzeroVector().normalized();
            /*       ^
             *      /C\
             *     /   \
             *  h'/     \ b
             *   /       \
             *  /B_______A\
             *     width
             * angle = A; beta = B; gamma = C.
             */
            //sine rule: hprimelen / sin A = width.length() / sin C = blen / sin B
            double beta, gamma;
            beta = Math.Acos(hprimedir.normalized().dotProduct(width.tryToNonzeroVector().normalized()));
            gamma = Math.PI - (angle + beta);
            double hprimelen;
            double sinruleconstant = width.length / Math.Sin(gamma);
            hprimelen = sinruleconstant*Math.Sin(angle);
            Scientrace.NonzeroVector hprime = hprimedir*hprimelen;

            // check: (trf.transform(hprime).x / hdirtrf.x) == (trf.transform(hprime).y / hdirtrf.y)
            double xycoeff = ((trf.transform(hprime).x / hdirtrf.x) / (trf.transform(hprime).y / hdirtrf.y));
            if (Math.Abs(1-xycoeff)>0.00001) { //doesn't do anything if .x/.x = NaN, but that's OK for now.
                throw new ArgumentOutOfRangeException("xycoeff", xycoeff, "!=1");
                }

            try {
            Scientrace.NonzeroVector h = ((Math.Abs(hdirtrf.x)>Math.Abs(hdirtrf.y)) ? // Preventing .x or .y denominator == 0 errors.
                trf.transformback(hdirtrf*(trf.transform(hprime).x / hdirtrf.x)) :
                trf.transformback(hdirtrf*(trf.transform(hprime).y / hdirtrf.y))
                ).tryToNonzeroVector();

            return h;
            } catch (Scientrace.ZeroNonzeroVectorException zne)	{
            Console.WriteLine("ERROR: calculated height for triangularprism has length zero!");
            throw (zne);
            }
        }
        public Scientrace.IntersectionPoint[] realIntersections(Scientrace.Line traceline, bool checkBorder)
        {
//			Scientrace.Line line = traceline-this.loc;	//substract loc value from traceline location,
            //leave direction unchanged
            //Console.WriteLine("In untransformed world: traceline -> "+traceline.ToString());
            //default value should be checkBorder = true;
            Scientrace.VectorTransform trf     = this.trf;
            Scientrace.Line            trfline = trf.transform(traceline - this.loc);
            //transform location AND direction
            Scientrace.IntersectionPoint[] ips = this.baseintersections(trfline);
            Scientrace.IntersectionPoint   tip;
            Scientrace.IntersectionPoint[] retips = new Scientrace.IntersectionPoint[2];
            for (int ipi = 0; ipi < ips.GetLength(0); ipi++)
            {
                if (ips[ipi] == null)
                {
                    retips[ipi] = null;
                    continue;
                }
                //Console.WriteLine("$$$$$$$$$$$$$$$$$"+ips[ipi].loc+"in?:"+trfline);
                //Console.WriteLine("___1");

                //check below removed for performance reasons

                /*if (!trfline.throughLocation(ips[ipi].loc, 0.00001)) {
                 *      string warning =@"ERROR: GOING DOWN! \n baseintersections "+trfline+" FAILED!";
                 *      throw new ArgumentOutOfRangeException(warning+ips[ipi].loc.trico() + " not in line " + trfline);
                 * } *///This was removed at 20160222

                /* else {
                 *      Scientrace.Line reflline = trfline.reflectAt(this.baseIntersectionPlane(ips[ipi].loc.x, ips[ipi].loc.y),0);
                 * //Console.WriteLine("___2");
                 *      /*if (!reflline.throughLocation(this.getBaseConcentrationPoint(), 0.000001)) {
                 *              //throw new ArgumentOutOfRangeException("CONCENTREER EENS!");
                 *              }*/
                //	} end of removed check
                //throw new AccessViolationException("FOO");
                //Console.WriteLine("ips["+ipi.ToString()+"]:"+ips[ipi].ToString());

                //tip = trf.transformback(ips[ipi])+this.loc;

                tip                 = ips[ipi].copy();
                tip.loc             = trf.transformback(ips[ipi].loc) + this.loc;
                tip.flatshape.plane = trf.transformback(tip.flatshape.plane);

                //Console.WriteLine("___3");

                /*if (!traceline.throughLocation(tip.loc, 0.0001)) {
                 *      throw new ArgumentOutOfRangeException(tip.loc.trico() + " (transformed) not in line " + traceline);
                 * } else {
                 *      }*/

                if (this.cborder.contains(tip.loc) || !checkBorder)          //is this location within the borders between which the
                //parabolic mirror exists?
                {
                    retips[ipi] = tip;

/*					//below for debug purposes only
 *                                      retips[ipi] = new IntersectionPoint(traceline.startingpoint+
 *                                                                          traceline.direction.toLocation()*(traceline.direction.dotProduct(tip.loc-traceline.startingpoint))
 *                                                                                                            , tip.plane);*/
                }
                else
                {
                    //Console.WriteLine(tip.loc.ToString() + " is NOT within the cborder range-> "+this.cborder);
                    retips[ipi] = null;
                    continue;
                }

                //Console.WriteLine("trf: "+trf.ToString());
                //Console.WriteLine("retips["+ipi.ToString()+"]:"+retips[ipi].ToString());
            }
            return(retips);
        }