첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.

[C#/WPF] 거리 구하기

C#/WPF 2013. 12. 28. 21:58
728x90
반응형
728x170

■ 피타고라스 법칙을 사용해 두 Point 객체 사이의 거리를 계산하는 방법을 보여준다.

 

▶ 예제 코드 (C#)

using System;
using System.Windows;

#region 거리 구하기 - GetDistance(startPoint, endPoint)

/// <summary>
/// 거리 계산하기
/// </summary>
/// <param name="startPoint">시작 위치</param>
/// <param name="endPoint">종료 위치</param>
/// <returns>거리</returns>
public double GetDistance(Point startPoint, Point endPoint)
{
    double deltaX = startPoint.X - endPoint.X;
    double deltaY = startPoint.Y - endPoint.Y;

    return Math.Sqrt((Math.Pow(Math.Abs(deltaX), 2) + Math.Pow(Math.Abs(deltaY), 2)));
}

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

댓글을 달아 주세요