Some Vector Math

Hi all,

I have this scenario whereby I need to rotate two vectors in a specific direction.

If you were to imagine a line between those two vectors (they are vertices btw), I need that imaginary line to be at the same rotation as a random spatial.

Got any ideas on how to do this?

Thx a zillion, DP

You can rotate a vector by converting the rotation to a matrix and then multiplying the matrix with the vector.

I think I might have miscommunicated my question. What I have is two vertices next to each other along any plane. Then I have this Spatial that is moving. Like so:


|      |        <---- TriMesh with 4 vertices
|      |


Say the spatial turns, I need to modify the rotation of the vertices:


|      |        <---- TriMesh with 4 vertices
|      |
|      *
|     /
|   /
* /             /
            /                    <
the spatial that has rotated

I need to move certain vertices to correspond with the rotation of the spatial.



The two vertices you want to move are connected via an edge. Then v2 - v1 is a vector representing that edge. If you know the rotation of the spatial, you can rotate that line the same way. After rotating, add the resulting vector to v2 again to get your v1.

Am I missing something here?

right, ok:

you can rotate that line the same way

and how would I be able to do that?

Sorry, im not very good with vector/matrix math ://


  1. get the rotation of the spatial → Quaternion q = s.getWorldRotation();
  2. convert it to a rotation matrix → Matrix3f r = q.toRotationMatrix();
  3. multiply v1 & v2 by r → r.mult(v1,v1); r.mult(v2,v2);

    now, this assumes that the centre of your object (the TriMesh) is at (0,0,0) to give you the effect that you drew above.

Sorry, just had another look at your drawing and realised i had misread it.

according to your drawing you are:


v1    c     v2

wanting to rotate it about c, but then translate it so that v2 lines up with its original position and v1 is on the same y as it was. (so the line v1-v2 is longer after rotation!)

so basically you calculate c, subtract c from v1 & v2 (to translate them so c is at origin), then rotate them, then multiply them by the ratio of their former horizontal size over their new horizontal size, then translate them down by the difference in y of the old v1 and the new v1.

sound complicated enough? :)