tags:

views:

733

answers:

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  A: 

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.

Soviut
This is both a good way of storing it and a system that'll work better for me
Teifion
+2  A: 

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

Scott Evernden