0
$\begingroup$

I am trying to rotate a point in a 3D space in the 3 axis together around a specific origin point.

Unfortunately I can't use matrices in my application,All I can do is just the basic math operations (including the trigonometrical functions).

So Instead of the normal transformation matrix,I want a normal function that has 3 angles (x,y,z) and the original location of the vertex and the origin point location as inputs and return the new point location.

Is it possible to do that without using matrices?

$\endgroup$
  • $\begingroup$ Can't you just write out the matrices, apply them to an arbitrary vector $(x,y)^T$ and then use the resulting equation? $\endgroup$ – David Kleiman Jan 15 '16 at 19:38
  • $\begingroup$ I can do this,But I want to see if there was an existed function to do it,as I don't know how to implement the origin point portion on my matrix. $\endgroup$ – Omar Ahmad Jan 15 '16 at 19:42
  • $\begingroup$ Any specific reason why matrices are out? Are you programming in a language that does not have arrays? $\endgroup$ – Justpassingby Jan 15 '16 at 19:47
  • $\begingroup$ No,I am an artist,I work with node based system,call it a visual programming language,We can't do arrays there. $\endgroup$ – Omar Ahmad Jan 15 '16 at 19:49
  • 1
    $\begingroup$ To expand on my previous comment, it is possible to change the origin with matrices, in which case you can obtain a general formula by multiplying all the matrices out with a general vector. I have posted an answer that elaborates on this. $\endgroup$ – David Kleiman Jan 15 '16 at 20:06
2
$\begingroup$

The trick is to write out your matrices in homogeneous coordinates (with an extra column to allow for affine transformations i.e., translation matrices). Letting the point you want to rotate about equal $(a,b,c)$ gives:

$$ R_x(\theta) = \begin{bmatrix} 1 & 0 & 0 & 0\\ 0 & \cos\theta & -\sin\theta & 0 \\ 0 & \sin\theta & \cos\theta & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} $$

$$ R_y(\theta) = \begin{bmatrix} \cos\theta & 0 & \sin\theta & 0\\ 0 & 1 & 0 & 0 \\ -\sin\theta & 0 & \cos\theta & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} $$

$$ R_z(\theta) = \begin{bmatrix} \cos\theta & -\sin\theta & 0 & 0\\ \sin\theta & \cos\theta & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 0 & 0 & 1 \end{bmatrix} $$

$$ T_1(a,b,c) = \begin{bmatrix} 1 & 0 & 0 & -a\\ 0 & 1 & 0 & -b\\ 0 & 0 & 1 & -c\\ 0 & 0 & 0 & 1 \end{bmatrix} $$

$$ T_2(a,b,c) = \begin{bmatrix} 1 & 0 & 0 & a\\ 0 & 1 & 0 & b\\ 0 & 0 & 1 & c\\ 0 & 0 & 0 & 1 \end{bmatrix} $$

Now applying these matrices as follows to a general vector $v = (x,y,z,1)^T$ gives a general formula:

$$ T_2(a,b,c)R_z(\theta)R_y(\theta)R_x(\theta)T_1(a,b,c)v. $$

Afterwards, the fourth entry of the vector can be dropped. The logic behind this is that you first translate $(a,b,c)$ to be at the origin, then you rotate, then you translate $(a,b,c)$ to be back to where it was originally.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.