Ejemplo n.º 1
0
    private float PointToSegmentClosestPoint(geoPoint P, geoPoint V0, ref geoPoint V1, ref geoPoint projection)
    {
        // Input:  P  = a 3D point
        //         PL = a  plane with point V0 and normal n
        // Output: ClosestPt = base point on segment of perpendicular from P
        //         Return: the minimum distance from P to the segment

        float length = 0;
        float t      = 0;

        length = (V1.subtract(V0)).DotProduct(V1.subtract(V0));
        if (length == 0)
        {
            projection = V1;
        }
        else
        {
            t          = Math.Max(0, Math.Min(1, (P.subtract(V0)).DotProduct(V1.subtract(V0)) / length));
            projection = V0.Addition((V1.subtract(V0)).Multiply(t));
        }

        return(projection.distance(ref P));
    }
Ejemplo n.º 2
0
    private float PintToPlaneClosestPoint(geoPoint Q, geoPoint V0, ref geoPoint V1, geoPoint V2, ref geoPoint projection)
    {
        // Input:  P  = a 3D point
        //         PL = a  plane with point V0 and normal n
        // Output: ClosestPt = base point on PL of perpendicular from P

        float    sb = 0;
        float    sn = 0;
        float    sd = 0;
        geoPoint a  = null;
        geoPoint b  = null;
        geoPoint n  = null;

        a = V0.subtract(V1);
        b = V0.subtract(V2);
        n = a.CrossProduct(b);

        sn         = -n.DotProduct(Q.subtract(V0));
        sd         = n.DotProduct(n);
        sb         = sn / sd;
        projection = Q.Addition(n.Multiply(sb));
        return(projection.distance(ref Q));
    }