2

As far as I am aware there is no inbuilt polygon functionality for Python. I want to create a 3D map and figured that polygons would be the best way to go about it.

Not wanting to reinvent the wheel I did some googling and found that there's a lot of Python stuff out there, but I couldn't find what I wanted. Thus before I reinvent the wheel (or invent it a whole), does anybody know of a Polygon system for Python?

Note that it does need to be 3D (I found quite a few 2D ones). Note also that I am not interested in the displaying of them but in storing them and the datastructure within Python.

Thanks

4

3 回答 3

4

One of the most complete geography/mapping systems available for Python that I know about is GeoDjango. This works on top of the Django, an MVC framework. With it comes a large collection of polygon, line and distance calculation tools that can even take into account the curvature of the earth's surface if need be.

With that said, the quickest way I can think of to produce a 3D map is using a height map. Create a two dimensional list of tuples containing (x, y, z) coordinates. Each tuple represents an evenly spaced point on a grid, mapped out by the dimensions of the array. This creates a simple plane along the X and Z axes; the ground plane. The polygons that make up the plane are quads, a polygon with four sides.

Next, to produce the three dimensional height, simply give each point a Y value. This will create peaks and valleys in your ground plane.

How you render this will be up to you, and converting your grid of points into a polygon format that something like OpenGL can understand may take some work, but have a look at Visual Python, its the simplest 3D library I've seen for Python.

于 2009-01-11T01:37:41.763 回答
2

I think you mean Polyhedron, not Polygon .. and you might wanna look at vpython

于 2009-01-11T02:35:58.383 回答
0

CGAL is a C++ geometry library which, amongst other things, models Polyhedra (3D flat-surfaced shapes)

It has Python bindings available. The documentation for the Polygon3 class is here: http://cgal-python.gforge.inria.fr/Manual/CGAL.Polyhedron.html#Polyhedron_3

于 2011-02-08T20:24:09.830 回答