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

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

问题描述

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

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天全站免登陆