1

the txt file is arranged like this:

// 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

There are about 700 polygons. Not all polygons have the same number of points. I didn't have any problems reading these polygons in C++, but i have no idea how to visualize them.

Is there any function in Matlab or Python which can draw multiple 3D polygons or do I have to use gis software like qgis or arcgis?

  • See this question for advice on drawing the polygons. Do you know how to read the data from the file easily? https://stackoverflow.com/questions/43971259/how-to-draw-polygons-with-python – Grant Williams Feb 13 '18 at 20:05
  • reading the data shouldn't be a problem, but the ImageDraw module can handle only 2d objects unfortunately. – Harry Manback Feb 13 '18 at 20:21
  • are you attempting to make a 3+ dimensional polygon? – Grant Williams Feb 13 '18 at 20:30
  • yes, if possible – Harry Manback Feb 13 '18 at 20:34
  • You could try this https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.ConvexHull.html – Grant Williams Feb 13 '18 at 20:50
  • 1
    The [`patch`](https://www.mathworks.com/help/matlab/ref/patch.html) and [`fill3`](https://www.mathworks.com/help/matlab/ref/fill3.html) functions would be what you need in MATLAB. You can see an example for square polygons in [this answer](https://stackoverflow.com/a/43949659/52738) (the first part generates the polygon data, the second part plots them with `patch`). – gnovice Feb 13 '18 at 21:19
  • You have added the `gis` tag. Are those polygons mathematical (visualize in a 3D graph) or geographical (visualize on a topographic map)? – Udi Feb 14 '18 at 12:59
  • they're geographical and represent parts of buildings – Harry Manback Feb 14 '18 at 22:40
  • Can you add to the question some example data? – Udi Feb 18 '18 at 09:01
  • I've added an excerpt of the txt file. The 'normal' values are irrelevant. – Harry Manback Feb 19 '18 at 14:52

1 Answers1

1

Assuming the following 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

Try:

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()

For adding colors and more options refer to https://matplotlib.org/gallery/mplot3d/polys3d.html

Udi
  • 29,222
  • 9
  • 96
  • 129