Beispiel #1
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));
        }
Beispiel #2
0
 /// <summary>
 /// calculate a pixels to world lenght.
 /// </summary>
 /// <param name="P">a refrence point, which is needed in case of perspective representation.</param>
 /// <param name="Pixels">Number of pixels</param>
 /// <returns></returns>
 public double PixelToWorld(Drawing3d.xyz P, int Pixels)
 {
     if (ProjectMatrixInvalid)
     {
         ProjectMatrixInvert = ProjectionMatrix.invert();
     }
     ProjectMatrixInvalid = false;
     if (FieldOfView > 0.01)
     {
         xyz    q = ProjectionMatrix * P;
         xyz    A = ProjectMatrixInvert * (new xyz(0, 0, q.z));
         xyz    B = ProjectMatrixInvert * (new xyz(1, 0, q.z));
         double d = A.dist(B);
         return(Pixels * d / (ViewPort.Width / 2));
     }
     else
     {
         return((ProjectMatrixInvert.multaffin(new xyz((float)Pixels / (float)(ViewPort.Width / 2), 0, 0))).length());
     }
 }
Beispiel #3
0
        /// <summary>
        /// crosses two triangles <b>t1</b> and <b>t2</b>
        /// </summary>
        /// <param name="t1"></param>
        /// <param name="t2"></param>
        /// <param name="Lam"></param>
        /// <param name="Mue"></param>
        /// <param name="P"></param>
        /// <param name="Q"></param>
        /// <returns></returns>
        public static bool Cross(TriangleF t1, TriangleF t2, out double Lam, out double Mue, out xyz P, out xyz Q)
        {
            xyzArray A = new xyzArray();
            xyzArray B = new xyzArray();

            A.data = new xyz[] { t1.A.Toxyz(), t1.B.Toxyz(), t1.C.Toxyz(), t1.A.Toxyz() };
            B.data = new xyz[] { t2.A.Toxyz(), t2.B.Toxyz(), t2.C.Toxyz(), t2.A.Toxyz() };
            Lam    = -1;
            Mue    = -1;
            P      = new Drawing3d.xyz(0, 0, 0);
            Q      = new Drawing3d.xyz(0, 0, 0);

            double d = (A.Distance(B, 1e10, out Lam, out Mue));

            if (d < 2)

            {
                P = A.Value(Lam);
                Q = B.Value(Mue);
                return(true);
            }
            return(false);
        }