19
votes

i'm looking for a 3d math library in python or with python bindings.

it needs to handle rotation, translation, perspective projection, everything basically.

what im NOT looking for is a library aimed at drawing on the screen, googling for hours only led to 3d libraries bent on rendering something to the screen. i dont want any visualization whatsoever, all i need is to be able feed a library x,y,z coordinates and recieve the x,y screen coordinates.

i dont mind if its a visualization library, as long as it can be used without rendering anything to the screen.

is there anything like this for python?

Edit: please dont recommend scipy/numpy as they arent aimed at 3d math but at math in general, they look like great tools if i wanted to build the library myself, which i dont. thanks.

9
Can you clarify what you want? The transformations you are asking for can be done with matrix multiplications, which numpy is a natural fit for. Are you hoping to do 3d work without seeing any matrices at all? - John La Rooy
python has good support for working with strings, does that mean everyone should roll their own XML parsing library? numpy is good for general math, but i cant just feed it (x,y,z) coords and have it present the 2d (x,y) coords, can i , i'd habe to use numpy to roll my own 3d math engine? whats wrong with looking for a library to handle something as common as 3d geometry - spearfire

9 Answers

3
votes

Try gameobjects -- it's a math library that includes Python classes for matrices and vectors, along with methods for transformations. I think it will provide most (if not all) of what you need, plus it's pure Python so you can modify it if you need to.

5
votes

OpenCV - Python Interface can handle all the operations you've mentioned.

I hear SciPy's excellent for this as well, but I've only used OpenCV.

4
votes

transformations.py

A library for calculating 4x4 matrices for translating, rotating, reflecting, scaling, shearing, projecting, orthogonalizing, and superimposing arrays of 3D homogeneous coordinates as well as for converting between rotation matrices, Euler angles, and quaternions. Also includes an Arcball control object and functions to decompose transformation matrices.

Authors: Christoph Gohlke http://www.lfd.uci.edu/~gohlke/ Laboratory for Fluorescence Dynamics, University of California, Irvine

2
votes

python-math3d is another good 3D mathematic library which is object oriented https://github.com/mortlind/pymath3d

import math3d as m3d

v = m3d.Vector(1,2,3) # A vector object

o = m3d.Orientation.new_euler((1,0,0), "ZYX") # An Orientation object from one type of euler angles

t = m3d.Transform(o, v) # A Transform object created using the vector and orientation

t2 = m3d.Transform()# Another Transform object (Identity)

t2.orient.rotate_x(3) # rotate the transformation around x

res = t * t2 #Matrix multiplication

1
votes

What about PyGame? I never used it, but it may contain what you're looking for.

1
votes

I would suggest MayaVi. Please take a look at the given link. It does almost everything you mentioned.

1
votes

I'm working on one now. https://github.com/adamlwgriffiths/Pyrr

It uses numpy for speed. The aim is to provide a pure python 3D maths lib.

I'm avoiding external libs because I'm sick of having to follow complex software installs. Python should be easy.

0
votes

http://cgkit.sourceforge.net/doc/index.html

The implementation isn't always the best, but it includes quaternions as well as the standard matrix and vector types. I've used it for tools on a couple commercial game projects.