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 easier 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.
A 3D vector is a line segment in three-dimensional space running from point A (tail) to point B (head). Each vector has a magnitude (or length) and direction.
Vectors are a modern programming concept, which, unfortunately, aren't built into the standard C library. Vectors are same as dynamic arrays with the ability to resize itself automatically when an element is inserted or deleted, with their storage being handled automatically by the container.
A vector type represents a vector of as many of the specified C data type as will fit in a 128-bit register. Hence, the vector signed int is a 128-bit operand containing four 32-bit signed ints . The vector unsigned short is a 128-bit operand containing eight unsigned values.
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
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With