Exemplo n.º 1
0
 public new UnitVector orientedAgainst(Scientrace.Vector aVector)
 {
     if (aVector.dotProduct(this) > 0)
     {
         return(this.negative());
     }
     return(this);
 }
Exemplo n.º 2
0
//.tryToUnitVector()

        public Vector orientedAlong(Scientrace.Vector aVector)
        {
            if (aVector.dotProduct(this) < 0)
            {
                return(this.negative());
            }
            return(this);
        }
Exemplo n.º 3
0
        public override Intersection intersects(Scientrace.Trace aTrace)
        {
            Scientrace.Vector c    = this.loc;
            Scientrace.Vector o    = aTrace.traceline.startingpoint;
            Scientrace.Vector l    = aTrace.traceline.direction;
            Scientrace.Vector y    = o - c;
            double            r    = this.radius;
            double            ABCa = l.dotProduct(l);
            double            ABCb = l.dotProduct(y) * 2;
            double            ABCc = y.dotProduct(y) - (r * r);
            QuadraticEquation qe   = new QuadraticEquation(ABCa, ABCb, ABCc);

            // if the trace doesn't hit the sphere, return a "false Intersection"
            if (!qe.hasAnswers)
            {
                return(new Intersection(false, this));
            }
            Scientrace.IntersectionPoint[] ips = new Scientrace.IntersectionPoint[2];
            switch (qe.answerCount)
            {
            case 2:
                Scientrace.Location      minLoc  = ((l * qe.minVal) + o).toLocation();
                Scientrace.NonzeroVector minNorm = (minLoc - c).tryToNonzeroVector();
                ips[0] = Scientrace.IntersectionPoint.locAtSurfaceNormal(minLoc, minNorm);
                Scientrace.Location      plusLoc  = ((l * qe.plusVal) + o).toLocation();
                Scientrace.NonzeroVector plusNorm = (plusLoc - c).tryToNonzeroVector();
                ips[1] = Scientrace.IntersectionPoint.locAtSurfaceNormal(plusLoc, plusNorm);
                return(new Intersection(aTrace, ips, this));

            //goto case 1;	//continue to case 1
            case 1:
                Scientrace.Location      loc  = ((l * qe.plusVal) + o).toLocation();
                Scientrace.NonzeroVector norm = (loc - c).tryToNonzeroVector();
                ips[0] = Scientrace.IntersectionPoint.locAtSurfaceNormal(loc, norm);
                ips[1] = null;
                return(new Intersection(aTrace, ips, this));

            default:
                throw new IndexOutOfRangeException("eq.answerCount is not allowed to be " + qe.answerCount.ToString() + "in Shpere.intersects(..)");
            }             //end switch(qe.answerCount)
        }
Exemplo n.º 4
0
        public Vector reflectOnSurface(Scientrace.NonzeroVector norm)
        {
            Scientrace.Vector negdir = this.negative();

            // Relative mirrorpoint: disregard the location of the line, just the orientations.
            Scientrace.Vector rel_mirrorpoint = (norm.toVector() * negdir.dotProduct(norm));

            //the distance from the surface normal to the direction vector (in the opposite direction) of the incoming line
            Scientrace.Vector distance_to_normal = (negdir - rel_mirrorpoint);

            //the direction of the reflected line
            return(rel_mirrorpoint - distance_to_normal);
        }