|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2012-7-31 20:01:10
|
显示全部楼层
xivisi 发表于 2012-7-31 10:26 ![](static/image/common/back.gif)
楼主做什么? 感觉像什么运动的东西 计算误差
网上搜了一天,终于解决了,暂时也是拷贝的,自己没消化
像素法非常慢,现在这个办法很快,而且计算精确,跟CAD对比相差0.03%- CRgn intersectRgn;
- intersectRgn.CreateRectRgn(0,0,0,0);
- int nIntersect = intersectRgn.CombineRgn(&区域1, &区域2 ,RGN_AND);
- //计算相交部分的面积
- Region intersectRegion((HRGN)intersectRgn);
- Matrix matrix;
- Rect* rects = NULL;
- int count = 0;
-
- CClientDC dc(this);
- Graphics graphics(dc.GetSafeHdc());
- graphics.GetTransform(&matrix);
- count = intersectRegion.GetRegionScansCount(&matrix);
- rects = (Rect*)malloc(count*sizeof(Rect));
- intersectRegion.GetRegionScans(&matrix, rects, &count);
-
- double dbTotalArea=0;
- for(int j=0; j<count; ++j)
- dbTotalArea +=(rects[j].GetBottom()-rects[j].GetTop())* (rects[j].GetRight()-rects[j].GetLeft());
-
- free(rects);
- graphics.ReleaseHDC(dc.GetSafeHdc());
- //返回面积值
复制代码 |
|