Пример #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
        //public override void Compile(OpenGlDevice Device)
        //{
        //    bool Inverted = false;
        //    base.Compile(Device);
        //    if (Inverted) BoundedCurves.Invert();
        //}
        /// <summary>
        /// is a constructor, which has thre points of the plane.
        /// </summary>
        /// <param name="A">the first point.</param>
        /// <param name="B">the second point.</param>
        /// <param name="C">the third point.</param>
        public PlaneSurface(xyz A, xyz B, xyz C)
        {
            xyz BA    = B - A;
            xyz CA    = C - A;
            xyz BaseZ = BA & CA;

            BaseZ = BaseZ.normalized();
            if (BaseZ.length() < 0.000001)
            {
                Base BB = Base.UnitBase;
                BB.BaseO = A;
                Base     = BB;
                return;
            }
            xyz BaseX = (CA & BaseZ).normalized();
            xyz BaseY = BaseZ & BaseX;

            Base __Base = new Base();

            __Base.BaseO = A;
            __Base.BaseX = BaseX;
            __Base.BaseY = BaseY;
            __Base.BaseZ = BaseZ;
            Base         = __Base;
        }
Пример #3
0
        /// <summary>
        /// Transforms the plane with a transformation matrix
        /// </summary>
        /// <param name="T"></param>
        public void Transform(Matrix T)
        {
            P = T * P;
            double l = NormalUnit.length();

            NormalUnit = T * NormalUnit - T * new xyz(0, 0, 0);
            l          = NormalUnit.length();
        }
Пример #4
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)));
 }
Пример #5
0
        /// <summary>
        /// Produce an orthogonal base with Origin a z-axis,the x-axis and a y-axis, which is normal to XAxis cross YVector
        /// </summary>
        /// <param name="Origin">The origin</param>
        /// <param name="XAxis">the x axis</param>
        /// <param name="YVector">the x axis is normal to XAxis cross YVector</param>
        /// <returns>orthogonal base</returns>
        public static Base DoComplete(xyz Origin, xyz XAxis, xyz YVector)
        {
            Base Result = new Base();

            if (YVector.length() == 0)
            {
                YVector = XAxis & new xyz(0, 0, 1);
                if (YVector.length() == 0)
                {
                    YVector = XAxis & new xyz(0, 1, 0);
                }
                if (YVector.length() == 0)
                {
                    YVector = XAxis & new xyz(1, 0, 0);
                }
            }
            Result.BaseO = Origin;
            Result.BaseX = XAxis.normalized();
            Result.BaseZ = (XAxis & YVector).normalized();

            Result.BaseY = Result.BaseZ & Result.BaseX;

            return(Result);
        }
Пример #6
0
        /// <summary>
        /// calculates the barycentric coordinates, which wil be returned.
        /// The point A*result.x +B*result.y+C*result.z is the normalprojection of P to
        /// the plane spanned by A,B and C. If A,B and C are in a line 0,0,0 wil be returned.
        /// </summary>
        /// <param name="A">Edge point of the triangle</param>
        /// <param name="B">Edge point of the triangle</param>
        /// <param name="C">Edge point of the triangle</param>
        /// <param name="P">Base point in the ABC plane </param>
        /// <returns></returns>
        public static xyz BaryCentric(xyz A, xyz B, xyz C, xyz P)
        {
            xyz F = (B - A) & (C - A);

            if (F.length() < 0.000000001)
            {
                return(new xyz(0, 0, 0));
            }
            xyz    N     = F.normalized();
            double TrABC = F * N;
            double TrCAP = ((C - P) & (A - P)) * N;
            double TrABP = ((A - P) & (B - P)) * N;
            double TrBCP = ((B - P) & (C - P)) * N;

            return(new xyz(TrBCP / TrABC, TrCAP / TrABC, TrABP / TrABC));
        }
Пример #7
0
        /// <summary>
        /// Overrides the method <see cref="Surface.getCross"/> and implements a method for get the crosspoint with a Line <b>L</b>, which is
        /// nearer to L.Q.
        /// </summary>
        /// <param name="L">The line, which will be crossed with the sphere</param>
        /// <param name="u">gets the u parameter of the cross point</param>
        /// <param name="v">gets the v parameter of the cross point</param>
        /// <returns>false if there is no cross point.</returns>
        public override bool getCross(LineType L, ref double u, ref double v)
        {
            xyz Direction  = L.Direction.normalized();
            xyz P          = Base.Relativ(L.P);
            xyz NDirection = ((Direction & P) & (Direction));

            double bb = NDirection.length();
            xyz    S  = new xyz(0, 0, 0);

            if (Radius > bb)
            {
                S = NDirection - Direction * System.Math.Sqrt(Radius * Radius - bb * bb);
            }
            else
            {
                return(false);
            }
            xy Param = this.ProjectPoint(Base.Absolut(S));

            u = Param.x;
            v = Param.Y;
            return(true);
        }