是否有任何计算给定坐标的形状面积的算法? [英] Is there any algorithm for calculating area of a shape given co-ordinates that define the shape?

查看:135
本文介绍了是否有任何计算给定坐标的形状面积的算法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一些函数接收N个随机 2D 点。



是否有任何算法可以计算输入点定义的形状的面积?

解决方案

你想计算多边形的面积

a>?



(取自链接,转换为C#)

  class Point {double x,y; } 

double PolygonArea(Point [] polygon)
{
int i,j;
double area = 0;

for(i = 0; i j =(i + 1)%polygon.Length;

面积+ =多边形[i] .x *多边形[j] .y;
area - = polygon [i] .y * polygon [j] .x;
}

area / = 2;
return(area <0?-area:area);
}


So I have some function that receives N random 2D points.

Is there any algorithm to calculate area of the shape defined by the input points?

解决方案

You want to calculate the area of a polygon?

(Taken from link, converted to C#)

class Point { double x, y; } 

double PolygonArea(Point[] polygon)
{
   int i,j;
   double area = 0; 

   for (i=0; i < polygon.Length; i++) {
      j = (i + 1) % polygon.Length;

      area += polygon[i].x * polygon[j].y;
      area -= polygon[i].y * polygon[j].x;
   }

   area /= 2;
   return (area < 0 ? -area : area);
}

这篇关于是否有任何计算给定坐标的形状面积的算法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆