txt文件的排列方式如下:
// X Y Z Normal Normal Point_Number Polygon_Number Point_Order_in_Polygon
67985.9074793747 34638.0915607559 533.775655680476 -1 -1 1 1 1
67981.5437461855 34627.2539106468 533.764021321678 0 0 2 1 2
67997.7408091771 34620.3855689056 533.927503654968 0 0 3 1 3
67989.4413768826 34601.1464928668 533.901896342952 0 0 4 1 4
67973.1472424856 34608.5241453471 533.734791828197 0 0 5 1 5
67968.2664777245 34596.6747014774 533.721414813632 0 0 6 1 6
67994.8853704575 34584.8244917691 533.994873913293 0 0 7 1 7
68013.5423896126 34626.2315086909 534.059094507073 1 1 8 1 8
67986.0967153860 34638.0706547732 513.320220307159 -1 -1 9 2 1
68013.7316254312 34626.2106030220 513.603669292181 0 0 10 2 2
67995.0746065266 34584.8035856923 513.539435492419 0 0 11 2 3
67968.4557138123 34596.6537953690 513.265975376945 0 0 12 2 4
67973.3364783805 34608.5032395525 513.279362549935 0 0 13 2 5
67989.6306123557 34601.1255877651 513.446489413198 0 0 14 2 6
67997.9290884072 34620.2630805532 513.475272916085 0 0 15 2 7
67981.7329827733 34627.2330037206 513.308555473084 1 1 16 2 8
68013.7316254312 34626.2106030220 513.603669292181 -1 -1 17 3 1
67986.0967153860 34638.0706547732 513.320220307159 0 0 18 3 2
67985.9074793747 34638.0915607559 533.775655680476 0 0 19 3 3
68013.5423896126 34626.2315086909 534.059094507073 1 1 20 3 4
67995.0746065266 34584.8035856923 513.539435492419 -1 -1 21 4 1
68013.7316254312 34626.2106030220 513.603669292181 0 0 22 4 2
68013.5423896126 34626.2315086909 534.059094507073 0 0 23 4 3
67994.8853704575 34584.8244917691 533.994873913293 1 1 24 4 4
大约有700个多边形。并非所有多边形都具有相同的点数。 我在C ++中阅读这些多边形没有任何问题,但我不知道如何将它们可视化。
Matlab或Python中是否有可以绘制多个3D多边形的函数,还是必须使用像qgis或arcgis这样的gis软件?
答案 0 :(得分:0)
假设以下polygons.txt
:
10 10 25 1 1 1
10 20 2 2 1 2
20 20 3 3 1 3
10 10 1 4 1 4
10 10 10 5 2 1
20 20 10 6 2 2
30 50 40 7 2 3
尝试:
from pprint import pprint
import matplotlib.pyplot as plt
from collections import defaultdict
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
polygons = defaultdict(dict)
with open("polygons.txt") as f:
for row in f:
x, y, z, _, p, n = map(float, row.split())
polygons[p][n] = (x, y, z)
verts = [[p for n, p in sorted(poly.items())] for poly in polygons.values()]
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_xlim(0, 50)
ax.set_ylim(0, 50)
ax.set_zlim(0, 50)
pprint(verts)
ax.add_collection3d(Poly3DCollection(verts))
plt.show()
有关添加颜色和更多选项的信息,请参阅https://matplotlib.org/gallery/mplot3d/polys3d.html