Example #1
0
        bool intersectPlaneWithLine(SnapItem Plane, SnapItem Line, xyzArray LineArray, ref double Lam, ref xyz Result)
        {
            TriangleF T = Plane.GetTriangle();

            if (T == null)
            {
                return(false);
            }
            xyz N1 = ((T.B - T.A) & (T.C - T.A)).Toxyz();

            if (LineArray == null)
            {
            }
            xyz N2 = LineArray.cross();

            if ((N1 & N2).length() < 0.00001)   // Parallel
            {
                xyzArray A = Plane.getxyzArray();
                if (A != null)
                {
                    xyzArray         B = LineArray;
                    List <CrossTag1> L = CrossTag1.GetCrossList(A, B);

                    for (int i = 0; i < L.Count; i++)
                    {
                        if (A.Value(L[i].Lam1).dist(Plane.Point) <= SnapItem.Snapdist)
                        {
                            Lam = L[i].Lam1;

                            Result = A.Value(L[i].Lam1);
                            return(true);
                        }
                    }
                }
            }

            int Object = StoredSnapItems.IndexOf(Plane);
            int siz    = SnapDistance * 2 + 1;

            //  int siz = SnapDistance;
            Drawing3d.PrimIdObj[,] P = SubArray(Device.MousePos.X - siz / 2, (int)Device.ViewPort.Height - Device.MousePos.Y - siz / 2, siz, siz);
            List <TriangleF> LT = GetTriangles(P, Object);

            Lam = -1;



            bool R = Cross(LT, LineArray, ref Lam, ref Result);

            return(R);
        }
Example #2
0
        void IntersectPlaneWithLine(SnapItem Plane, SnapItem Line, LineType ViewLine)
        {
            double Lam    = -1;
            xyz    Result = new xyz(0, 0, 0);

            if (intersectPlaneWithLine(Plane, Line, Line.getxyzArray(), ref Lam, ref Result))
            {
                if (Result.dist(Plane.Point) <= SnapItem.Snapdist)
                {
                    Plane.Point   = Result;
                    Line.Point    = Plane.Point;
                    Line.Crossed  = true;
                    Plane.Crossed = true;
                }
            }
        }
Example #3
0
        bool IntersectLineWithLine(SnapItem Line1, SnapItem Line2, LineType ViewLine)
        {
            xyzArray A  = Line1.getxyzArray();
            int      h  = A.Count;
            xyzArray B  = Line2.getxyzArray();
            double   d1 = 1e10;
            int      i1 = -1;
            double   d2 = 1e10;
            int      i2 = -1;

            for (int i = 0; i < A.Count; i++)
            {
                double d = Line1.Point.dist(A[i]);
                if (d < d1)
                {
                    d1 = d;
                    i1 = i;
                }
            }
            for (int i = 0; i < B.Count; i++)
            {
                double d = Line1.Point.dist(B[i]);
                if (d < d2)
                {
                    d2 = d;
                    i2 = i;
                }
            }
            if ((A == null) || (B == null))
            {
                return(false);
            }
            xyz CrossPoint = new xyz(0, 0, 0);

            if (IntersectLines(A, B, Line1.Point, ref CrossPoint))
            {
                Line1.Point   = CrossPoint;
                Line2.Point   = CrossPoint;
                Line1.Crossed = true;
                Line2.Crossed = true;
                return(true);
            }

            return(false);
        }
Example #4
0
        public bool IntersectPlaneWithPlane(SnapItem Plane1, SnapItem Plane2, LineType ViewLine)
        {
            int Object1 = StoredSnapItems.IndexOf(Plane1);
            int Object2 = StoredSnapItems.IndexOf(Plane2);
            int siz     = 2 * SnapDistance + 1;

            PrimIdObj[,] P   = SubArray(Device.MousePos.X - siz / 2, (int)Device.ViewPort.Height - Device.MousePos.Y - siz / 2, siz, siz);
            ListOfTriangles1 = GetTriangles(P, Object1);
            ListOfTriangles1.Clear();
            Matrix M = Plane1.ModelMatrix;

            for (int i = 0; i < Plane1.TriangleInfo.Indices.Length; i++)
            {
                TriangleInfo TI = Plane1.TriangleInfo;
                TriangleF    T  = new TriangleF(M * TI.Points[TI.Indices[i]], M * TI.Points[TI.Indices[i + 1]], M * TI.Points[TI.Indices[i + 2]]);
                i = i + 2;
                //   if (T.Inside(ViewLine.P.toXYZF()))
                ListOfTriangles1.Add(T);
            }
            for (int i = 0; i < ListOfTriangles1.Count; i++)
            {
                if (ListOfTriangles1[i].Inside(ViewLine.P.toXYZF()))
                {
                    TriangleF F = ListOfTriangles1[i];
                    ListOfTriangles1.RemoveAt(i);
                    ListOfTriangles1.Insert(0, F);
                }
            }
            ListOfTriangles2 = GetTriangles(P, Object2);
            ListOfTriangles2.Clear();
            M = Plane2.ModelMatrix;
            for (int i = 0; i < Plane2.TriangleInfo.Indices.Length; i++)
            {
                TriangleInfo TI = Plane2.TriangleInfo;
                TriangleF    T  = new TriangleF(M * TI.Points[TI.Indices[i]], M * TI.Points[TI.Indices[i + 1]], M * TI.Points[TI.Indices[i + 2]]);
                i = i + 2;
                //  if (T.Inside(ViewLine.P.toXYZF()))
                ListOfTriangles2.Add(T);
            }
            for (int i = 0; i < ListOfTriangles2.Count; i++)
            {
                if (ListOfTriangles2[i].Inside(ViewLine.P.toXYZF()))
                {
                    TriangleF F = ListOfTriangles2[i];
                    ListOfTriangles2.RemoveAt(i);
                    ListOfTriangles2.Insert(0, F);
                }
            }
            List <Line3D> Lines = Cross(ListOfTriangles1, ListOfTriangles2, ViewLine);
            xyz           P1    = new xyz(0, 0, 0);
            xyz           P2    = new xyz(0, 0, 0);

            if (Lines.Count < 2)
            {
                double           Lam = -1;
                double           Mue = -1;
                List <TriangleF> L1  = new List <TriangleF>();
                List <TriangleF> L2  = new List <TriangleF>();
                for (int i = 0; i < ListOfTriangles1.Count; i++)
                {
                    if (ListOfTriangles1[i].Inside(ViewLine.P.toXYZF()))
                    {
                        L1.Add(ListOfTriangles1[i]);
                    }
                }
                for (int i = 0; i < ListOfTriangles2.Count; i++)
                {
                    if (ListOfTriangles2[i].Inside(ViewLine.P.toXYZF()))
                    {
                        L2.Add(ListOfTriangles2[i]);
                    }
                }
                L1 = ListOfTriangles1;
                L2 = ListOfTriangles2;
                for (int i = 0; i < L1.Count; i++)
                {
                    for (int j = 0; j < L2.Count; j++)
                    {
                        if (TriangleF.Cross(L1[i], L2[j], out Lam, out Mue, out P1, out P2))
                        {
                            int _lam = (int)Lam;
                            switch (_lam)
                            {
                            case 0:
                                Lines.Add(new Line3D(L1[i].A.Toxyz(), L1[i].B.Toxyz()));
                                break;

                            case 1:
                                Lines.Add(new Line3D(L1[i].B.Toxyz(), L1[i].C.Toxyz()));
                                break;

                            case 2:
                                Lines.Add(new Line3D(L1[i].C.Toxyz(), L1[i].A.Toxyz()));
                                break;

                            default:
                                break;
                            }
                            int _mue = (int)Mue;
                            switch (_mue)
                            {
                            case 0:
                                Lines.Add(new Line3D(L2[j].A.Toxyz(), L2[j].B.Toxyz()));
                                break;

                            case 1:
                                Lines.Add(new Line3D(L2[j].B.Toxyz(), L2[j].C.Toxyz()));
                                break;

                            case 2:
                                Lines.Add(new Line3D(L2[j].C.Toxyz(), L2[j].A.Toxyz()));
                                break;

                            default:
                                break;
                            }
                        }
                        break;
                    }
                }
                //if (TriangleF.Cross(ListOfTriangles1[0], ListOfTriangles2[0], out Lam, out Mue, out P1, out P2))
                //{
                //    int _lam = (int)Lam;
                //    switch (_lam)
                //    {case  0: Lines.Add(new Line3D(ListOfTriangles1[0].A.Toxyz(),ListOfTriangles1[0].B.Toxyz()));
                //           break;
                //        case 1: Lines.Add(new Line3D(ListOfTriangles1[0].B.Toxyz(), ListOfTriangles1[0].C.Toxyz()));
                //            break;
                //        case 2: Lines.Add(new Line3D(ListOfTriangles1[0].C.Toxyz(), ListOfTriangles1[0].A.Toxyz()));
                //            break;
                //        default:
                //            break;
                //    }
                //    int _mue = (int)Mue;
                //    switch (_mue)
                //    {
                //        case 0:
                //            Lines.Add(new Line3D(ListOfTriangles2[0].A.Toxyz(), ListOfTriangles2[0].B.Toxyz()));
                //            break;
                //        case 1: Lines.Add(new Line3D(ListOfTriangles2[0].B.Toxyz(), ListOfTriangles2[0].C.Toxyz()));
                //            break;
                //        case 2: Lines.Add(new Line3D(ListOfTriangles2[0].C.Toxyz(), ListOfTriangles2[0].A.Toxyz()));
                //            break;
                //        default:
                //            break;
                //    }
                //}
            }

            double di  = 1e10;
            xyz    Pos = new xyz(0, 0, 0);
            int    Id  = -1;

            for (int i = 0; i < Lines.Count; i++)
            {
                LineType L   = new LineType(Lines[i].A, Lines[i].B - Lines[i].A);
                double   Lam = -1;

                double d       = ViewLine.Distance(L, SnapItem.Snapdist, false, false, out Lam);
                xyz    Nearest = L.Value(Lam);
                if ((Lam >= -0.00001) && (Lam <= 1.00001))
                {
                    if (d < di)
                    {
                        Pos = Nearest;
                        di  = d;
                        Id  = i;
                    }
                }
            }
            if ((di < 1e10) && (di <= SnapItem.Snapdist))
            {
                Plane1.Crossed = true;
                Plane1.Point   = Pos;
                Plane2.Crossed = true;
                Plane2.Point   = Pos;
                return(true);
            }

            xyzArray A = Plane1.getxyzArray();
            xyzArray B = Plane2.getxyzArray();

            if ((A != null) && (B != null))
            {
                return(IntersectLineWithLine(Plane1, Plane2, ViewLine));
            }



            return(false);
        }