다각형 피처가 떨어지는 선의 측면을 결정하는 방법은 무엇입니까? 소포 데이터

소포 데이터 교차 선 데이터가 있습니다. 소포 데이터에는 선과 교차하지 않는 소포가 있습니다. 교차하지 않는 소포가 선의 오른쪽 또는 왼쪽에 있는지 어떻게 프로그래밍 방식으로 알아낼 수 있습니까? 감사.



답변

IHitTest 인터페이스를 사용하십시오 . 쿼리 포인트는 다각형 중심이되고 입력 지오메트리는 선이됩니다. 출력 중 하나는 부울 (bRightSide)이되어 현재 줄의 어느 쪽을 알려줍니다.


답변

이를 위해 내적을 사용할 수 있습니다

/// <summary>
/// Used to indicate the orientation of an object in space
/// with respect to another object
/// </summary>
public enum OrientationType
{
    Left,
    Right,
    Coincident,
    Unknown
}


/// <summary>
    /// Determines if a point is oriented left, right or coincident with
    /// a directed line.
    /// Line direction is determined by its From and To points.
    /// </summary>
    /// <param name="p">The point to test.</param>
    /// <param name="segment">The line dividing the space</param>
    /// <returns>An OrientationType indicating the orientation.</returns>
    public static OrientationType GetPointOrientation(IPoint p, ISegment segment)
    {

        OrientationType result = OrientationType.Unknown;

        double Ax = segment.FromPoint.X;
        double Ay = segment.FromPoint.Y;
        double Bx = segment.ToPoint.X;
        double By = segment.ToPoint.Y;
        double Px = p.X;
        double Py = p.Y;

        double nDotV = ((Ay - By) * (Px - Ax)) + ((Bx - Ax) * (Py - Ay));

        if (nDotV < 0)
        {
            result = OrientationType.Right;//opposite direction to normal vector
        }
        else if (nDotV > 0)
        {
            result = OrientationType.Left;
        }
        else if (nDotV == 0)
        {
            result = OrientationType.Coincident;
        }

        return result;
    }

답변

원하는 결과를 얻는 알고리즘 :

  1. 초점을 맞추십시오
  2. 선 지오메트리의 오른쪽 (또는 왼쪽)에 버퍼 (0.0000005)를 추가하십시오.
  3. 버퍼 지오메트리가 폴리곤 지오메트리의 ‘내부’인지 또는 폴리곤 지오메트리의 ‘오버랩’인지 확인하십시오.