Maybe I'm just missing something in the docs, but it seem it's not possible with GLM to take the transpose of a vector. I also see no mat3x1 or mat1x3 types. Also glm::transpose doesn't work for vectors. Am I missing something or is this just a feature lacking in GLM?
2 Answers
GLM is based on GLSL, where there's simply no need to transpose a vector. If you do vector/matrix multiplication, it will multiply the vector in the way that works for the size of the matrix (unless it would have to change the order of the multiplication). So if you have a mat4
and do mat4*vec4
, your vec4
is considered a column vector. If you do vec4*mat4
, it is considered a row vector. If you do mat2x4*vec4
, you get an error, while vec4*mat2x4
works (as a row vector).
So in general, there's no reason to need to "transpose" a vector. The system simply does whatever works.

- 449,505
- 63
- 781
- 982
-
2What if you want to calculate something like v * transpose(v) where v is a vec4. What I want is a mat4 as a result. I.e. multiplying a 4x1 and a 1x4 to get a 4x4. I don't see how to do that in GLM. Maybe you can't? – Chuck Mar 21 '13 at 05:13
-
@Chuck: Well, that's probably because it's not a very useful operation. Besides, you can do the math for it yourself easily enough; it's just pairwise multiplying each element of the vector. – Nicol Bolas Mar 21 '13 at 05:15
-
1Of course I can do it myself. However, it is a very useful general purpose operation. For instance, it is a standard piece of things like the matrix formulation of the Rodrigues' rotation formula. It would be nice to have merely as syntactic sugar. Languages like APL, A+, k, Matlab, etc... provide this out of the box. – Chuck Mar 21 '13 at 05:59
-
7@Chuck: The operation you're talking about is the [Outer Product](http://en.wikipedia.org/wiki/Outer_product). Which both [GLSL](http://www.opengl.org/sdk/docs/manglsl/xhtml/outerProduct.xml) and [GLM](http://glm.g-truc.net/api-0.9.4/a00133.html#ga5d896e8651512fc098a677dbe403eeac) can do. – Nicol Bolas Mar 21 '13 at 07:00
As a reference for people looking for how to transpose a vector (primarily for calculating outer products - u vT) in GLSL/GLM; its:
glm::core::function::matrix::outerProduct(u, v)
Nicol's GLM link now 404s as their API links have changed format from:

- 17,259
- 7
- 59
- 81