An algorithm for intersection of arbitrary polygons in space

Source: Internet
Author: User

        public static string Mypf_function () {var lee = 0;            float D1 = 0, d2 = 0; var ret = "Multipatch does not intersect!!            ";            Space two multipatch p1[0] = new Polytopepoint (0, 0, 1);            P1[1] = new Polytopepoint (0, 0, 2);            P1[2] = new Polytopepoint (2, 2, 2);            P1[3] = new Polytopepoint (2, 2, 1);            P2[0] = new Polytopepoint (2, 1, 0);            P2[1] = new Polytopepoint (0, 1, 0);            P2[2] = new Polytopepoint (0, 1, 3);            P2[3] = new Polytopepoint (2, 1, 3); var x1 = p1[1]. X-p1[0].            X var y1 = p1[1]. Y-p1[0].            Y var z1 = p1[1]. Z-p1[0].            Z var x2 = p1[2]. X-p1[0].            X var y2 = p1[2]. Y-p1[0].            Y var z2 = p1[2]. Z-p1[0].                         Z var a1 = P2[1]. X-p2[0].            X var B1 = p2[1]. Y-p2[0].            Y var C1 = p2[1]. Z-p2[0].            Z var a2 = p2[2]. X-p2[0].             X var b2 = p2[2]. Y-p2[0].            Y var C2 = P2[2]. Z-p2[0].            Z            Two-way vector var n1 = new Polytopepoint (y1 * z2-z1 * y2, z1 * x2-x1 * z2, x1 * y2-y1 * x2);            var n2 = new Polytopepoint (B1 * c2-c1 * B2, C1 * A2-A1 * c2, A1 * B2-B1 * A2);            The signed distance of the first plane point to the second plane var a=new float[4]; for (var i = 0; i < 4; i++) {A[i] = n1. X * (P2[i]. X-p1[0]. X) + N1. Y * (P2[i]. Y-p1[0]. Y) + N1. Z * (P2[i]. Z-p1[0].            Z);            }//Disjoint condition if (a[0] * A[1] > 0 && a[0] * A[2] > 0 && a[0] * A[3] > 0)            {return ret; }//Coplanar if (Math.Abs (a[0]) < 0.00000000000001 && Math.Abs (a[1]) < 0.00000000000001 &amp                ;& Math.Abs (a[2]) < 0.00000000000001 && Math.Abs (a[3]) < 0.00000000000001) { ret = "Two Multipatch coplanar!"                ";            return ret;  }//First plane point to the first plane of the signed distance var B = new Float[4];          for (var i = 0; i < 4; i++) {b[i] = n2. X * (P1[i]. X-p2[0]. X) + n2. Y * (P1[i]. Y-p2[0]. Y) + n2. Z * (P1[i]. Z-p2[0].            Z);                    } for (var i = 0, i < 3; i++) {for (var j = 0; J < 3; J + +) {                        On the second plane of the clamping edge on the existence of conditions if (a[i] * a[i + 1] < 0) {                            The existence condition if (b[j] * b[j + 1] < 0) for the clamping edge on the first plane { var L = p1[j + 1]. X-P1[J].                            X var m = p1[j + 1]. Y-P1[J].                            Y var n = p1[j + 1]. Z-P1[J].                             Z var o = p2[i + 1]. X-p2[i].                            X var p = p2[i + 1]. Y-p2[i].                            Y var q = p2[i + 1]. Z-p2[i].                            Z          On one or two sides, take a clip edge to the vector NT vertical var nt=new polytopepoint (M*q-n*p,n*o-l*q,l*p-m*o);                  if (Lee = = 0) {d1 = nt. X* (P1[i]. X-P2[J]. X) + NT. y* (P1[i]. Y-P2[J]. Y) + NT. z* (P1[i]. Z-P2[J].                                Z);                            lee++; } else {d2 = NT. X * (P1[i]. X-P2[J]. X) + NT. Y * (P1[i]. Y-P2[J]. Y) + NT. Z * (P1[i]. Z-P2[J].                            Z); }//Polygon intersection condition if (D1 * D2 < 0 | |    (Math.Abs (D1) < 0.00000000000001 && Math.Abs (D2) < 0.00000000000001)) A slight flaw puts the condition wide enough to intersect the intersection of {ret = "two Multipatch" as long as the cable intersects the Multipatch!                                  ";                            return ret;            }}}}} ret = "Exception";        return ret; }

  

An algorithm for intersection of arbitrary polygons in space

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.