コード例 #1
0
        public static bool IsOnSamePlane(GeoPointsArray3 points, ref GeoPlane plane)
        {
            if (points.Size() < 4)
            {
                return(true);
            }
            int     count = points.Size();
            int     i     = 2;
            Vector3 p     = points[0];

            for (; i < count; ++i)
            {
                p = points[i];
                if (!GeoLineUtils.IsPointInLine3(points[0], points[1], ref p))
                {
                    break;
                }
            }
            if (i == count)
            {
                return(true);
            }
            plane = GeoPlaneUtils.CreateFromTriangle(points[0], points[1], p);
            i     = 2;
            int c = 2;

            for (; i < count; ++i)
            {
                if (GeoPlaneUtils.IsPointOnPlane(plane.mNormal, plane.mD, points[i]))
                {
                    c++;
                }
            }
            return(c == count);
        }
コード例 #2
0
ファイル: GeoTriangleUtils.cs プロジェクト: ByteKay/Nullspace
        public static bool IsTriangleInsectSphere(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 center, float r, ref GeoInsectPointArrayInfo insect)
        {
            GeoPlane plane   = GeoPlaneUtils.CreateFromTriangle(p1, p2, p3);
            bool     isInsec = GeoPlaneUtils.IsPlaneInsectSphere(plane, center, r, ref insect);

            if (isInsec)
            {
                Vector3 c1  = insect.mHitGlobalPoint.mPointArray[0];
                float   rad = insect.mHitGlobalPoint.mPointArray[0][0];
                insect.Clear();
                return(IsTriangleInsectPlaneCircle2(p1, p2, p3, c1, rad, plane, ref insect));
            }
            return(false);
        }
コード例 #3
0
ファイル: GeoTriangleUtils.cs プロジェクト: ByteKay/Nullspace
        // 两三角面 共面的情况
        private static bool IsTriangleInsectTrianglePlane2(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, Vector3 p5, Vector3 p6, ref GeoInsectPointArrayInfo insect)
        {
            GeoPlane plane = GeoPlaneUtils.CreateFromTriangle(p1, p2, p3);
            Vector2  p11, p21, p31, p41, p51, p61;

            GeoPlaneUtils.PlaneTransformLocalTriangle(p1, p2, p3, plane, out p11, out p21, out p31);
            GeoPlaneUtils.PlaneTransformLocalTriangle(p4, p5, p6, plane, out p41, out p51, out p61);
            GeoInsectPointArrayInfo tmp = new GeoInsectPointArrayInfo();
            bool isInsect = IsTriangleInsectTriangle2(p11, p21, p31, p41, p51, p61, ref tmp);

            if (isInsect)
            {
                foreach (Vector3 v in tmp.mHitGlobalPoint.mPointArray)
                {
                    Vector3 vt = new Vector3(v.x, 0.0f, v.z);
                    vt = plane.TransformToGlobal(vt);
                    insect.mHitGlobalPoint.mPointArray.Add(vt);
                }
                insect.mIsIntersect = insect.mHitGlobalPoint.mPointArray.Count > 0;
            }
            return(insect.mIsIntersect);
        }