# Multiplying (transforming) a Vector by a Matrix - in 3 or more steps...

• Hi gang,

So... back in the good-ole days (at least R14 and earlier), it was quite common in my code to have something like...

``````m_xfPoints[ndx] = m_pPoints[ndx] * mxForm;    // transform point by current matrix
``````

In other words, within a loop (increasing the value of 'ndx'), you could transform all points/vertices by some matrix - with a single line of code.

The (R20, but maybe back as far as R15?) API no longer seems to have a built-in "multiply a vector by a matrix" operator, so you end up with more lines of code, to achieve the same thing...

``````Vector xfPt = m_pPoints[ndx];             // get a copy of the point...
xfPt *= mxForm;                           // use the '*=' operator to modify it...
m_xfPoints[ndx] = xfPt;                   // ...finally, assign it to the transformed array
``````

...note that I had to use a new Vector to store a temporary copy of the original (so I wouldn't modify the original with the '*=' operator).

Of course I could have done it with one less line of code...

``````m_xfPoints[ndx] = m_pPoints[ndx];          // get original point value...
m_xfPoints[ndx] *= mxForm;                 // use the '*=' operator to modify it.
``````

..but the above is just the most simplistic example... I have other cases where more math is done on the same (single) line of code to the point (scaling, other matrices or vectors involved, etc.), so I more often than not have to add more, separate operations.

So... am I missing something? I'm sure there was some rationale for removing some operators (you can no longer multiply 2 Vectors either... have to use Dot(), can no longer use '%' - must use Cross(), etc.), but/so I'm just wondering what that is.

Thanks,

Keith

• Hello,

actually, you can still multiply in one line. You just have to multiply a matrix with a vector:

``````maxon::Vector points[count];
maxon::Matrix matrices[count];

// fill arrays ...

for (maxon::Int i = 0; i < count; ++i)
{
points[i] = matrices[i] * points[i];
}
``````

You find information on how to use matrices in these manuals:

best wishes,
Sebastian

• "actually, you can still multiply in one line. You just have to multiply a matrix with a vector:..."

D'oh! I'm surprised that I didn't try that - tho it doesn't seem as intuitive ("vector = some other vector, being modified by some operations" vs. "vector = a matrix, imposing/operating on some vector", etc.)... do you know why the Vector lost so many direct operators (* other Vector (Dot()), * Matrix, % other Vector (Cross()) - there may be others)?

Apparently, you can still '!v' to normalize it (yay), even tho there's a v.Normalize() call... and I can understand why the "Identity Matrix" operator might have changed from '!' to '~'... some of the other changes just seem a bit arbitrary.

I've already made all the changes at this point, but thanks for the tip/reply - I'll keep that in mind for future reference.

Cheers.