Sign in to follow this  

C++ - Python 3D Vectors

This topic is 4786 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this