첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

■ Point 클래스를 사용해 다각형 내부 위치 여부를 구하는 방법을 보여준다.

 

▶ Point 클래스 : 다각형 내부 위치 여부 구하기 예제 (C#)

Point[] polygonPointArray = new Point[]
{
    new Point(100, 100),
    new Point(150, 130),
    new Point(120, 170),
    new Point(90 , 150),
    new Point(100, 100)
};

Point point = new Point(100, 150);

bool result = IsPointInPolygon(polygonPointArray, point);

 

▶ Point 클래스 : 다각형 내부 위치 여부 구하기 (C#)

using System.Drawing.Drawing2D;

#region 다각형 내부 위치 여부 구하기 - IsPointInPolygon(polygonPointArray, point)

/// <summary>
/// 다각형 내부 위치 여부 구하기
/// </summary>
/// <param name="polygonPointList">다각형 포인트 배열</param>
/// <param name="point">포인트</param>
/// <returns>다각형 내부 위치 여부</returns>
public bool IsPointInPolygon(Point[] polygonPointArray, Point point)
{
    GraphicsPath path = new GraphicsPath();

    path.AddPolygon(polygonPointArray);

    Region region = new Region(path);

    return region.IsVisible(point);
}

#endregion

※ System.Drawing.Common 누겟 패키지를 설치한다.

728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요