Esempio n. 1
0
 /// <summary>
 /// This method calculates the distance to a point Pt.
 /// The parameter Lam can be used to calculate the nearest point of the LineType, which is
 /// also returned by the outvalue Nearest
 /// </summary>
 /// <param name="Pt">Point to calculate the distance to the LineType</param>
 /// <param name="Lam">Parameter to calculate the nearest point</param>
 /// <param name="Nearest">Point on the Line, with the lowest distance to Pt</param>
 /// <returns>Returns the distance from the line to the point Pt</returns>
 public double Distance(xyz Pt, out double Lam, out xyz Nearest)
 {
     if (Utils.Equals(Direction.length(), 0))
     {
         Lam     = 0;
         Nearest = P;
         return(Pt.dist(P));
     }
     Lam     = Direction.normalized().Scalarproduct(Pt.sub(P)) / Direction.length();
     Nearest = P.add(Direction.mul(Lam));
     return(Nearest.dist(Pt));
 }
Esempio n. 2
0
        /// <summary>
        /// The base will be transformed by the Matrix m.
        /// </summary>
        /// <param name="m">m holds the transform matrix which will be applied to the base</param>
        /// <returns></returns>
        public Base mul(Matrix m)
        {
            Base result = new Base();

            result.BaseO = BaseO.mul(m);
            xyz InHomogen = m * new xyz(0, 0, 0);

            result.BaseX = BaseX.mul(m) - InHomogen;
            result.BaseY = BaseY.mul(m) - InHomogen;
            result.BaseZ = BaseZ.mul(m) - InHomogen;
            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// This method calculates the distance to a Line L
        /// The parameter Lam1 can be taken to calculate the point, which has the lowest distance to
        /// the other Line L . Nearest1 = Value(Lam1).
        /// The parameter Lam2 can be taken to calculate the point of L , which has the lowest distance to
        /// the Linetype this. Nearest2 = L.Value(Lam2).
        /// </summary>
        /// <param name="L">The other LineType</param>
        /// <param name="Lam1">Paramter which belongs to this line : Nearest1 = Value(Lam1)</param>
        /// <param name="Lam2">Paramter which belongs to the Line L: Nearest2 = L.Value(Lam2)</param>
        /// <param name="Nearest1">The point on the Line, which has the smallest distance to the Line L</param>
        /// <param name="Nearest2">The point on the Line L, which has the smallest distance </param>
        /// <returns>Returns the distance to the line L</returns>

        public double Distance(LineType L, out double Lam1, out double Lam2, out xyz Nearest1, out xyz Nearest2)
        {
            xyz    PQ  = L.P.sub(P);
            double PQV = PQ.Scalarproduct(Direction);
            double PQW = PQ.Scalarproduct(L.Direction);
            double vv  = Direction.Scalarproduct(Direction);
            double ww  = L.Direction.Scalarproduct(L.Direction);
            double vw  = L.Direction.Scalarproduct(Direction);
            double Det = vv * ww - vw * vw;

            if (Det == 0)// parallele
            {
                xyz    n      = PQ.cross(Direction).cross(Direction).normalized();
                double result = PQ.Scalarproduct(n);
                Nearest2 = P.add(n.mul(result));
                Nearest1 = P;
                Lam1     = 0;
                Lam2     = L.Direction.normalized().Scalarproduct(Nearest2.sub(L.P));
                return(System.Math.Abs(result));
            }
            else
            {
                Lam1     = (PQV * ww - PQW * vw) / Det;
                Lam2     = -(PQW * vv - PQV * vw) / Det;
                Nearest1 = P.add(Direction.mul(Lam1));
                Nearest2 = L.P.add(L.Direction.mul(Lam2));

                return(Nearest1.dist(Nearest2));
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Calculate the cross point with a line.
        /// </summary>
        /// <param name="aLine">A line which intersects the plane</param>
        /// <param name="Lam">Is a parameter, which determines the crosspoint</param>
        /// <param name="pt">Is the cross point</param>
        /// <returns>returns true, if there is a crosspoint.</returns>
        /// <example><code>
        /// //the following snippet shows the meaning of lam
        /// Plane p = new Plane( new xyz(0, 0, 0), new xyz(1, 5, 5));
        /// LineType l = new LineType( new xyz (3,-1,3), new xyz(2, 1, 5));
        /// if (p.Cross(l, out Lam, out pt))
        ///		{
        ///		// you can also get p through the following
        ///		pt = l.P + l.Direction*lam;
        ///		}
        /// </code></example>


        public bool Cross(LineType aLine, out double Lam, out xyz pt)
        {
            pt  = aLine.P;
            Lam = -1;

            xyz    Direction = aLine.Direction.normalized();
            double En        = Direction.Scalarproduct(NormalUnit);

            if (System.Math.Abs(En) < Utils.epsilon)
            {
                return(false);
            }
            xyz OP = aLine.P;

            OP = OP.sub(P);

            Lam  = -OP.Scalarproduct(NormalUnit) / En;
            pt   = pt.add(Direction.mul(Lam));
            Lam /= (aLine.P - aLine.Q).length();

            return(true);
        }