Sign in to follow this  
soconne

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

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this