Sign in to follow this  
Xetrov

C++ - Python 3D Vectors

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this