728x90
반응형
728x170
▶ 다각형 면적 구하기 예제
using System.Collections.Generic;
List<DoublePoint> sourceList = new List<DoublePoint>();
sourceList.Add(new DoublePoint(50 , 50 ));
sourceList.Add(new DoublePoint(250, 50 ));
sourceList.Add(new DoublePoint(150, 250));
sourceList.Add(new DoublePoint(50 , 150));
sourceList.Add(new DoublePoint(50 , 50 ));
double polygonArea = GetPolygonArea(sourceList);
728x90
▶ 다각형 면적 구하기
using System.Collections.Generic;
#region 다각형 면적 구하기 - GetPolygonArea(sourceList)
/// <summary>
/// 다각형 면적 구하기
/// </summary>
/// <param name="sourceList">소스 리스트</param>
/// <returns>다각형 면적</returns>
public double GetPolygonArea(List<DoublePoint> sourceList)
{
double polygonArea = 0d;
int firstIndex;
int secondIndex;
int sourceCount = sourceList.Count;
DoublePoint firstPoint;
DoublePoint secondPoint;
double factor = 0d;
for(firstIndex = 0; firstIndex < sourceCount; firstIndex++)
{
secondIndex = (firstIndex + 1) % sourceCount;
firstPoint = sourceList[firstIndex ];
secondPoint = sourceList[secondIndex];
factor = ((firstPoint.X * secondPoint.Y) - (secondPoint.X * firstPoint.Y));
polygonArea += factor;
}
polygonArea /= 2d;
return polygonArea;
}
#endregion
/// <summary>
/// 실수 포인트
/// </summary>
public class DoublePoint
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Property
////////////////////////////////////////////////////////////////////////////////////////// Public
#region X - X
/// <summary>
/// X
/// </summary>
public double X { get; set; }
#endregion
#region Y - Y
/// <summary>
/// Y
/// </summary>
public double Y { get; set; }
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Property
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - DoublePoint(x, y)
/// <summary>
/// 생성자
/// </summary>
/// <param name="x">X</param>
/// <param name="y">Y</param>
public DoublePoint(double x, double y)
{
X = x;
Y = y;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 문자열 구하기 - ToString()
/// <summary>
/// 문자열 구하기
/// </summary>
/// <returns>문자열</returns>
public override string ToString()
{
return string.Format("X={0},Y={1}", X, Y);
}
#endregion
}
728x90
반응형
그리드형(광고전용)
'C# > Common' 카테고리의 다른 글
[C#/COMMON] Dns 클래스 : GetHostAddresses 정적 메소드를 사용해 실행 호스트 IP 주소 여부 구하기 (0) | 2017.06.14 |
---|---|
[C#/COMMON] 윈도우즈 7 데스크톱과 탐색기 갱신하기 (0) | 2017.06.14 |
[C#/COMMON] TimeSpan 구조체 : 포맷 문자열을 사용해 문자열 구하기 (0) | 2017.06.13 |
[C#/COMMON] DOS 명령어 실행하기 (0) | 2017.06.12 |
[C#/COMMON] 다각형 무게 중심 구하기 (0) | 2017.06.11 |
[C#/COMMON] 파비콘 다운로드 하기 (0) | 2017.06.10 |
[C#/COMMON] 엣지 브라우저 버전 구하기 (0) | 2017.06.10 |
[C#/COMMON] 운영 체제 버전 구하기 (0) | 2017.06.10 |
[C#/COMMON] ZipArchive 클래스 : ZIP 파일 생성하기/추출하기 (0) | 2017.06.10 |
[C#/COMMON] 디렉토리 삭제하기 (0) | 2017.06.10 |
댓글을 달아 주세요