Exemple #1
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));
            }
        }
Exemple #2
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));
 }
Exemple #3
0
        /// <summary>
        /// Calculates the relative coordinates from point.
        /// The base is assumed to be normalized
        /// The invert method is <see cref="Absolut"/>.
        /// </summary>
        /// <param name="P">Point</param>
        /// <returns>returns the coordinates relative to the base</returns>
        public xyz Relativ(xyz P)
        {
            if ((System.Math.Abs(BaseX * BaseY) < double.Epsilon) && (System.Math.Abs(BaseX * BaseZ) < double.Epsilon) && (System.Math.Abs(BaseZ * BaseY) < double.Epsilon)
                ) // Orthogonal
            {
                xyz d = P.sub(BaseO);

                return(new xyz(d.Scalarproduct(BaseX.normalized()), d.Scalarproduct(BaseY.normalized()), d.Scalarproduct(BaseZ.normalized())));
            }

            P = P - BaseO;
            double Det = xyz.dot(BaseX, BaseY, BaseZ);

            if (System.Math.Abs(Det) < 0.0000000000000000001)
            {
                xyz d = P.sub(BaseO);
                return(new xyz(d.Scalarproduct(BaseX), d.Scalarproduct(BaseY), d.Scalarproduct(BaseZ)));
            }
            else
            {
            }
            return(new xyz(xyz.dot(P, BaseY, BaseZ) / Det, xyz.dot(BaseX, P, BaseZ) / Det, xyz.dot(BaseX, BaseY, P) / Det));
        }
Exemple #4
0
        /// <summary>
        /// Checks intersecting of a not bounded Line with the Triangle
        /// </summary>
        /// <param name="L">Not bounded Line</param>
        /// <returns></returns>
        public bool Intersect(LineType L)
        {
            double Lam = -1;

            xyz   Pkt = new Drawing3d.xyz(0, 0, 0);
            Plane P   = new Plane(A, B, C);

            P.Cross(L, out Lam, out Pkt);
            xyz Dummy = new xyz(0, 0, 0);

            xyz      SA = A.sub(Pkt);
            xyz      SB = B.sub(Pkt);
            xyz      SC = C.sub(Pkt);
            LineType LL = new LineType(A, (B - A).normalized());
            double   bb = LL.Distance(Pkt, out Lam, out Dummy);

            if (bb < 0.1)
            {
            }
            LL = new LineType(B, (C - B).normalized());
            bb = LL.Distance(Pkt, out Lam, out Dummy);
            if (bb < 0.1)
            {
            }
            LL = new LineType(C, (C - A).normalized());
            bb = LL.Distance(Pkt, out Lam, out Dummy);
            if (bb < 0.1)
            {
            }
            //double D1 = Utils.Spat(SA, SB, L.Direction);
            //double D2 = Utils.Spat(SB, SC, L.Direction);
            //double D3 = Utils.Spat(SC, SA, L.Direction);
            double D1 = Utils.Spat(SA, SB, SC);

            return(true);
            //if (Utils.Less(0, D1))
            //{
            //    return (Utils.Less(0, D2) && Utils.Less(0, D3));
            //}
            //else
            //    return (Utils.Less(D2, 0)) && (Utils.Less(D3, 0));
        }
Exemple #5
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);
        }