コード例 #1
0
        bool PointOnSegment(Vertex A, Vertex B,
                            Vertex P,
                            float distanceEpsilon,
                            float parametricEpsilon,
                            out float pointSegmentDistance)
        {
            // Determines whether P lies within the segment A-B

            float segmentLength = Vertex.Distance(A, B);
            float tangentABdist = Vertex.Dot(Vertex.Normalize(B - A), Vertex.Normalize(P - A)) * (P - A).Length();
            float u             = tangentABdist / segmentLength;

            if (u < parametricEpsilon || u > 1.0 - parametricEpsilon)
            {
                pointSegmentDistance = float.MaxValue;
                return(false);
            }

            Vertex isect = A + (B - A) * u;
            float  dist  = (P - isect).Length();

            pointSegmentDistance = dist;

            if (dist > distanceEpsilon * segmentLength)
            {
                return(false);
            }
            return(true);
        }
コード例 #2
0
        float ClosestAngleOnTri(int vA, int vB, int vC)
        {
            int[] indices = new int[3];
            indices[0] = vA;
            indices[1] = vB;
            indices[2] = vC;

            double closestAngle = Math.PI;

            for (int i = 0; i < 3; i++)
            {
                Vertex nAB = Vertex.Normalize(vertices[indices[(i + 1) % 3]] - vertices[indices[i]]);
                Vertex nAC = Vertex.Normalize(vertices[indices[(i + 2) % 3]] - vertices[indices[i]]);
                float  dot = Vertex.Dot(nAB, nAC);
                Debug.Assert(dot >= -1.01f && dot <= 1.01f);
                double angle = Math.Acos(dot);
                if (angle < closestAngle)
                {
                    closestAngle = angle;
                }
            }
            return((float)closestAngle);
        }