コード例 #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));
            }
        }
コード例 #2
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));
        }
コード例 #3
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);
        }