Coding/Math
[Math] 사선 공식
chobocho
2011. 9. 12. 00:51
임의의 점들을 이은 다각형의(볼록 다각형) 넓이를 구하는 공식인 사선공식 이다.
삼각형의 넓이를 구 할 때에도 헤론의 공식 보다 C로 구현하기가 간단하다.
삼각형의 넓이를 구 할 때에도 헤론의 공식 보다 C로 구현하기가 간단하다.
//
// Java 로 구현한 사선 공식
//
import java.lang.Math;
public double getArea(Point[] arrPoints) {
// Java 로 구현한 사선 공식
//
import java.lang.Math;
public double getArea(Point[] arrPoints) {
double area = 0.0;
Point tempPoint = new Point(arrPoints[0]);
for ( int i = 1; i < arrPoints.length; i++) {
area += tempPoint.x * arrPoints[i].y - tempPoint.y * arrPoints[i].x;
tempPoint = arrPoints[i];
}
area = Math.abs(area / 2.0);
return area;
}