views:

474

answers:

3

Disclaimer: The context is a project I'm working on as part of my Master's degree. I guess it qualifies as homework.


Introduction

(feel free to skip to the bottom line)

Curved 3D surfaces are commonly displayed as a large set of very small triangles. Each triangle has the following properties:

  • 3 corners
  • uniform color

Such that when they're all displayed together, you get the illusion of a smooth surface. This is similar to the way pixels of a uniform color are used to get the illusion of a smooth image.

My project involves generating and displaying all the triangles that make up a given surfaces. Assuming that I have code that generates a set of triangles, how can I display them?

The code that generates the set of triangles is in Python. I'd prefer to use Python to display the triangles, but I'm not picky.


Bottom line

How can I display a triangle in 3D using Python, when the input is the coordinates of the 3 corners of the triangle.

+7  A: 

Well, that depends, very much, like which OS you are using, do you need to be portable, etc.

But a generic answer is probably to use something like OpenGL, which is a portable API, and has Python bindings. http://pyopengl.sourceforge.net/

On Windows you can use Direct3D, but that isn't particularily portable, and I wouldn't be surprised if there is something special for OS X too.

Lennart Regebro
yes use opengl and be happy, i will recommend using wxPython's wxGLCanavas, so you can have other UI elements easily.
Anurag Uniyal
If you choose OpenGL, you still have to decide on framework that would contain your OpenGL control. Some options are PyGame, SFML, wxPython, FxPy, Qt and pyglet.
Josip
A: 

EDIT: I misread your question. This is only for 2D:

You can use a wx.Canvas of wxpython or implement your application using pygame.

Ralph
you *can* use 2D pygame, however that would need you to calculate the 3d to 2d mapping yourself. Fortunately, pygame has also a 3D api.
nosklo
There's no wx.Canvas. There is wx.Panel, generally for 2D GDI drawing. There's also wx.glcanvas.GLCanvas for OpenGL.
FogleBird
+1  A: 

Here's an example integrating OpenGL with wxPython.

http://code.activestate.com/recipes/325392/

FogleBird