HiveBrain v1.2.0
Get Started
← Back to all entries
patterncppMinor

3D matrix rotation in homogeneous coordinate space

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
spacecoordinatehomogeneousrotationmatrix

Problem

Assuming that the framework is in place to handle the difference between row and column major matrices, I am curious to know if in a header based library such implementation is semantically and syntactically correct and or appealing. I am not using PIMPL here because it is strictly a header library.

```
template
matrix_4X4 rotate_by(const matrix_4X4 &m, const T &angle,
const vector_3d &v, angle_mode mode = radians)
{
T a = angle;
if (mode == degrees) {

Solution

You have a matrix class. Presumably, the class is part of a library that supports basic matrix operations such as multiplication and addition.

It's odd, therefore, that a rotate_by() function would implement matrix operations from scratch. What you want to express is \$\mathbf{b} = \mathrm{N}^T \mathbf{m}\$, and it should be written that way. All of the details of how to perform that multiplication, including the row-major vs. column-major layout, should be taken care of elsewhere.

The definitions of the elements of \$\mathrm{N}\$ look suspicious to me, as the units of the addends don't agree.

Context

StackExchange Code Review Q#62235, answer score: 2

Revisions (0)

No revisions yet.