# How to apply a position, scale and quaternion to a vertex ??

This topic is 4628 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have a position, scale and quaternion. How do I apply this transformation to a single vertex? For instance: float pos[3]; float scale[3]; float quaternion[4]; I've tried searching the forums but everyone only talks about appyling a quaternion, not the position and scale as well. Arent' they needed too?

##### Share on other sites
Do you already have a 4x4 matrix class with matrix and vector multiplication implemented? Or do you need a 'from scratch' solution?

##### Share on other sites
Yes, I already have matrix transformations implemented. But I would like to know how to transform vectors by quaternions from scratch, or is it easier to transform them to matrices?

##### Share on other sites
Quote:
 Yes, I already have matrix transformations implemented. But I would like to know how to transform vectors by quaternions from scratch, or is it easier to transform them to matrices?
You can do it from scratch, but for multiple transformations the matrix form is probably more convenient and efficient.

Here's the from-scratch solution. This assumes standard quaternion multiplication order (you'll have to switch things around if you're using 'reverse' order).

The transformations you mention are usually performed in the order scale->rotate->translate. To scale the vector, simply multiply each component by the corresponding scale factor.

The next step is to rotate the vector by the quaternion. The equation for this is v' = q*quat(v)*conj(q). conj() returns the conjugate of a quaternion (all components but w negated), and quat() returns a quaternion with the same xyz components as the input vector and a w of 0 (typically). v' is also a quaternion; its xyz components are the rotated vector. Finally, translation is a simple vector addition.

For the matrix form, you would construct matrices S, R and T that represent the scaling, rotation, and translation, respectively. S and T are straightfoward; for R you need a quat-to-matrix function (if you get one from a reference, make sure the conventions match). The matrices are then multiplied together as T*R*S (column vectors) or S*R*T (row vectors). You can also exploit the many trivial operations in the matrix mults to create the final matrix more efficiently.

##### Share on other sites
Awsome, thanks alot.

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 14
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631435
• Total Posts
3000056
×