C++ - Python 3D Vectors

Started by
0 comments, last by idadesub 19 years, 4 months ago
I have a nice C++ class for vector math functions which wraps a float[3] -- CVector, and the same thing with Quaternions etc... I'm using boost::python to expose my C++ classes/functions to python. Currently I have wrapped any functions taking or returning a CVector to take or return a boost tuple instead. However this is a somewhat dirty solution as I want to use vector math in python too. So the question is, which would be faster? : 1) Expose the C++ CVector class to python -- pro: easy. con: maybe not too efficient to have to convert all the time -- there might be a lot of vector math... 2) Create a python vector class and convert to that instead of tuples (as I currently am). pro: wont need to make repeated conversions back to C++ vectors. con: the conversion on passing/returning may take a bit longer, also python math functions probably add a little overhead on C++. After writing that out, I think #2 is probably better...
Advertisement
I'd also suggest looking into Numeric or Numarray's array class. It's got a well accelerated numerical arrays for doing vector math, plus it does have an api that simplifies reading an array into and out of python. Of course, I haven't really used numeric so I'm not really sure of the performance, but I've heard good things. With well designed use of its api, it can rival c code, b/c thats what it ultimately is.

This topic is closed to new replies.

Advertisement