1

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.

2 Answers 2

7

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.

Sign up to request clarification or add additional context in comments.

2 Comments

yes use opengl and be happy, i will recommend using wxPython's wxGLCanavas, so you can have other UI elements easily.
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.
0

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

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

2 Comments

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.
There's no wx.Canvas. There is wx.Panel, generally for 2D GDI drawing. There's also wx.glcanvas.GLCanvas for OpenGL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.