我的问题是测量路径的表面积。 我生成一个随机的路径,并绘制在画布上。触摸此closen道路上,我想这个绘制路径的面积大小。
我怎样才能得到这条道路的实际面积大小?
该pathes(形状)看起来像这样的位置: 链接到图片
My problem is to measure the surface area of a path. I generate a random Path and draw it on a canvas. After touching on this closen path, i want to get the area size of this drawn path.
How can i get the real area size of this path?
The pathes (shapes) looks like this here: link to the image
我找到了解决办法。我生成路径的区域,并使用RegionIterator使区域内Rects。与此Rects我可以计算路径的整个区域。
I found a solution. I generate a Region from the path and use a RegionIterator to get Rects inside the Region. With this Rects i can calculate the whole area of the path.
private void calculateArea(Region region) {
RegionIterator regionIterator = new RegionIterator(region);
int size = 0; // amount of Rects
float area = 0; // units of area
Rect tmpRect= new Rect();
while (regionIterator.next(tmpRect)) {
size++;
area += tmpRect.width() * tmpRect.height();
}
log.d("Rect amount=" + size);
log.d("Area Size / units of area=" + area);
}
上一篇:如何设置一个ListView成一个appwidget?如何设置、ListView、appwidget
下一篇:为什么MonkeyRunner.waitForConnection()错误"亚洲开发银行ADB拒绝端口转发命令:无法绑定套接字"亚洲、绑定、端口、开发银行