在DXFReader中, 一般的多边形的面积计算绝对值
其中K表是顶点的数目,它们的坐标,用于在求和和,
所以用下面的代码就可以计算出一个封闭的多段线的区域:
01 | Dim Vertex As Object |
02 | Dim Entity As Object |
03 | Dim k As Long |
04 | Dim i As Long |
05 | Dim Area As Single |
06 |
07 | With DXFReader1 |
08 |
09 | For Each Entity In .Entities |
10 | If Entity.EntityType = "POLYLINE" Then |
11 |
12 | Area = 0 |
13 |
14 | For k = 1 To Entity.Vertexes.Count |
15 |
16 | If k = Entity.Vertexes.Count Then |
17 | i = 1 |
18 | Else |
19 | i = k + 1 |
20 | End If |
21 |
22 | Area = Area + _ |
23 | Entity.Vertexes(k).x0 * Entity.Vertexes(i).y0 - _ |
24 | Entity.Vertexes(i).x0 * Entity.Vertexes(k).y0 |
25 |
26 | Next k |
27 |
28 | Area = Abs(Area) / 2 |
29 |
30 | End If |
31 | Next Entity |
32 |
33 | End With |