示例#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));
 }
示例#2
0
 /// <summary>
 /// Calculates the absolute coordinates of the point, whose coordinates are related to the Base.
 /// The base is assumed to be normalized.
 /// The invert method is <see cref="Relativ"/>.
 /// </summary>
 /// <param name="pt">Point</param>
 /// <returns>returns the absolut coordinates in a worldbase</returns>
 public xyz Absolut(xyz pt)
 {
     //xyz d=pt.sub(BaseO);
     if ((!Utils.Equals(BaseX.length(), 1f)) || (!Utils.Equals(BaseY.length(), 1f)) || (!Utils.Equals(BaseZ.length(), 1f)))
     {
     }
     return(BaseO.add(BaseX.mul(pt.x)).add(BaseY.mul(pt.y)).add(BaseZ.mul(pt.z)));
 }
示例#3
0
        /// <summary>
        /// Calculates the cross product over all xyzArray by adding the cross products.
        /// If the Loxyz is plane then cross is a normal of this plane?
        /// </summary>
        /// <returns>Return the cross product over all xyzArrays contained in it</returns>
        public xyz cross()
        {
            xyz result = new xyz(0, 0, 0);

            for (int i = 0; i < Count; i++)
            {
                result = result.add(this[i].cross());
            }
            return(result);
        }
示例#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);
        }