Ejemplo n.º 1
0
        public static List <TriangleIntersection3d> CalcIntersection(List <List <xyz> > loops1, List <List <xyz> > loops2)
        {
            List <xyz> main1 = loops1[0];
            List <xyz> main2 = loops2[0];

            if (!MightIntersect_BB(main1, main2))
            {
                return(null);
            }

            List <Triangle3d> tris1 = new List <Triangle3d>();
            List <Triangle3d> tris2 = new List <Triangle3d>();

            tri.Triangulate3d_WithHoles(tris1, loops1);
            tri.Triangulate3d_WithHoles(tris2, loops2);

            List <TriangleIntersection3d> result = new List <TriangleIntersection3d>();

            foreach (Triangle3d t1 in tris1)
            {
                foreach (Triangle3d t2 in tris2)
                {
                    TriangleIntersection3d ti = CalcTriangleIntersection3d(t1, t2);
                    if (ti.Count > 0)
                    {
                        result.Add(ti);
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        public static TriangleIntersection3d CalcTriangleIntersection3d(Triangle3d t1, Triangle3d t2)
        {
            if (ut.AllVerticesPlanar(t1, t2))
            {
                TriangleIntersection3d ti = new TriangleIntersection3d();

                xyz n = t1.n;
                xyz i = t1.iv;
                xyz j = t1.jv;

                xy a1 = ut.ConvertPointTo2d(t1.a, t1.a, i, j);
                xy b1 = ut.ConvertPointTo2d(t1.b, t1.a, i, j);
                xy c1 = ut.ConvertPointTo2d(t1.c, t1.a, i, j);

                xy a2 = ut.ConvertPointTo2d(t2.a, t1.a, i, j);
                xy b2 = ut.ConvertPointTo2d(t2.b, t1.a, i, j);
                xy c2 = ut.ConvertPointTo2d(t2.c, t1.a, i, j);

                TriangleIntersection2d ti2d = TriangleIntersection2d.CalcTriangleIntersection2d(a1, b1, c1, a2, b2, c2);
                if (ti2d.Count > 0)
                {
                    foreach (xy p in ti2d)
                    {
                        xyz q = ut.Convert2dPointTo3d(p, t1.a, i, j);
                        ti.Add(q);
                    }
                }

                return(ti);
            }
            else
            {
                return(CalcTriangleIntersection3d_NotCoplanar(t1, t2));
            }
        }
Ejemplo n.º 3
0
        public static TriangleIntersection3d CalcTriangleIntersection3d_NotCoplanar(Triangle3d t1, Triangle3d t2)
        {
            int sign_t2_a = t1.GetSide(t2.a);
            int sign_t2_b = t1.GetSide(t2.b);
            int sign_t2_c = t1.GetSide(t2.c);

            int sign_t1_a = t2.GetSide(t1.a);
            int sign_t1_b = t2.GetSide(t1.b);
            int sign_t1_c = t2.GetSide(t1.c);

            TriangleIntersection3d ti = new TriangleIntersection3d();

            if (!((sign_t2_a == sign_t2_b) && (sign_t2_b == sign_t2_c)))
            {
                xyz pt1;
                xyz pt2;
                if ((sign_t2_a != sign_t2_b) && TriangleLineSegmentIntersect3d(t1, t2.a, t2.b, out pt1, out pt2, sign_t2_a, sign_t2_b))
                {
                    ti.Add(pt1);
                    ti.Add(pt2);
                }
                if ((sign_t2_b != sign_t2_c) && TriangleLineSegmentIntersect3d(t1, t2.b, t2.c, out pt1, out pt2, sign_t2_b, sign_t2_c))
                {
                    ti.Add(pt1);
                    ti.Add(pt2);
                }
                if ((sign_t2_c != sign_t2_a) && TriangleLineSegmentIntersect3d(t1, t2.c, t2.a, out pt1, out pt2, sign_t2_c, sign_t2_a))
                {
                    ti.Add(pt1);
                    ti.Add(pt2);
                }
                if ((sign_t1_a != sign_t1_b) && TriangleLineSegmentIntersect3d(t2, t1.a, t1.b, out pt1, out pt2, sign_t1_a, sign_t1_b))
                {
                    ti.Add(pt1);
                    ti.Add(pt2);
                }
                if ((sign_t1_b != sign_t1_c) && TriangleLineSegmentIntersect3d(t2, t1.b, t1.c, out pt1, out pt2, sign_t1_b, sign_t1_c))
                {
                    ti.Add(pt1);
                    ti.Add(pt2);
                }
                if ((sign_t1_c != sign_t1_a) && TriangleLineSegmentIntersect3d(t2, t1.c, t1.a, out pt1, out pt2, sign_t1_c, sign_t1_a))
                {
                    ti.Add(pt1);
                    ti.Add(pt2);
                }
            }
            return(ti);
        }
Ejemplo n.º 4
0
        public static List <TriangleIntersection3d> CalcIntersection_NotCoplanar(List <Triangle3d> tris1, List <List <xyz> > loops2)
        {
            List <Triangle3d> tris2 = new List <Triangle3d>();

            tri.Triangulate3d_WithHoles(tris2, loops2);

            List <TriangleIntersection3d> result = new List <TriangleIntersection3d>();

            foreach (Triangle3d t1 in tris1)
            {
                foreach (Triangle3d t2 in tris2)
                {
                    TriangleIntersection3d ti = CalcTriangleIntersection3d_NotCoplanar(t1, t2);
                    if (ti.Count > 0)
                    {
                        result.Add(ti);
                    }
                }
            }

            return(result);
        }