如何计算有机形状的面积? [英] How to calculate area of an organic shape?

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

问题描述

我想知道可以计算出有机形状的面积.我试图计算的形状看起来像这样:

I want to know its possible to calculate the area of an organic shape. The shape im trying to calculate looks something like this:

想象一下它是由 CGPoints

为此有特殊功能吗?我在想CoreImage或Quartz或opengl.

Is there a special function for this? Im thinking maybe CoreImage or Quartz or maybe opengl.

推荐答案

如果边界路径仅由直线段组成并且不相交本身,那么您可以使用以下公式来计算封闭区域的面积(来自 https://en.wikipedia.org/wiki/Polygon#Area_and_centroid ):

If the boundary path consists only of straight line segments and does not intersect itself then you can use the following formula to compute the area of the enclosed region (from https://en.wikipedia.org/wiki/Polygon#Area_and_centroid):

CGPoint points[N]; 

CGFloat area = 0;
for (int i = 0; i < N; i++) {
    area += (points[i].x * points[(i+1) % N].y - points[(i+1) % N].x * points[i].y)/2.0;
}

其中 points [0],...,points [N-1] 是线段的逆时针起点.

where points[0], ... , points[N-1] are the starting points of the line segments in counter-clockwise order.

对于更复杂的路径段(例如贝塞尔曲线),您可以细分每个段分成可以由线段近似的小部分.

For more complicate path segments such as Bézier curves, you can subdivide each segment into small parts that can be approximated by line segments.

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

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