开发者

Is there a standard 3d vector class in C++

开发者 https://www.devze.com 2023-02-27 02:01 出处:网络
In an existing project, I see a class Vector_3d, templated, with the usual operations for vectors (in the sense of algebra). After profiling, I noticed that a large amount of the time is spent in this

In an existing project, I see a class Vector_3d, templated, with the usual operations for vectors (in the sense of algebra). After profiling, I noticed that a large amount of the time is spent in this class.

I was wondering if there was a well-known implementation of such a basic concept as a 3d vector in C++. Indeed, it might be e开发者_如何转开发asier to use a good implementation of the vector instead of trying to optimize this one.

Edit: This is in a context of a geometrical representation of some objects. But it is independent from any visualization. I will see if there is a way of avoiding to call the various methods too often. And I will have a look at the proposed packages.


There is no much room for improvement in a 3d vector class (basically, dot / cross products are fairly easy, matrix multiplication as well). If so much time is spent in that class, maybe your code using it is flawed. Have you checked against

  • copy vs references
  • wrong association (like multiply matrix then all vectors by the resulting matrix, rather than all vectors by the chain of matrices)

I know that there is QVector3D in Qt, that might help you (by the way, they got Vector 2D and 4D as well for common 3D geometry operations)


Dave Eberly's http://www.geometrictools.com/ is a great resource for those types of classes.


I'm partial to Eigen. Plus it's header-only and has built-in vectorization support.


Boost::QVM could be also an option: http://boostorg.github.io/qvm/

0

精彩评论

暂无评论...
验证码 换一张
取 消