3D Rotation

46 sec read

Assume you have a vector (x,y,z) and you want to rotate it to, say x-axis, you can multiply the rotation matrix to the vector.

First, make the vector a column vector and append 1 to the end. It becomes a 4×1 matrix:

v =
x
y
z
1

Then, convert the vector from Cartesian to spherical coordinate:

[theta, phi, r] = cart2sph(x,y,z)

The meaning of theta, phi and r is illustrated by the following diagram:

Then based on theta and phi, do proper rotations. For example, to rotate the vector to x-axis, you might want to rotate the vector to XZ plane first (by rotate along Z axis with angle theta), and then to x-axis by rotate along Y axis with angle phi. You need to construct the rotation matrix (below) and multiply the matrix with the original vector. Note the order matters.

v_final = M2*M1*v

The following material is from http://www.siggraph.org/education/materials/HyperGraph/modeling/mod_tran/3drota.htm

Rotate along z-axis

         ( cos q  sin q  0  0)
         (-sin q  cos q  0  0)
         ( 0        0    1  0)
         ( 0        0    0  1)

Along x-axis

        (1    0      0    0)
        (0  cos q  sin q  0)
        (0 -sin q  cos q  0)
        (0    0     0     1)

Along y-axis

        (cos q  0  -sin q   0)
        (0      1    0      0)
        (sin q  0  cos q    0)
        (0      0    0     1)

Note:

To construct a unique rotation matrix, you will need 4 vectors (not on the same plane) in 3D.



写作助手,把中式英语变成专业英文


Want to receive new post notification? 有新文章通知我

采用基于频率簇(Cluster)的置换检验(Permutation)方法选取感兴趣频段

作者:北京师范大学 龙宇航,[email protected]代码来源(见本页底部):周思远 在使用wtc计算脑间神经同步后,我们需要在多个频率段、多个通道组合上对神经同步值进行统计检验,因
Xu Cui
1 min read

Calculate phase difference between two general signals (e.g. HbO…

In a recent fNIRS journal club (vedio recorded here), Dr. Tong talked about their work on the phase difference between oxy and deoxy Hb, and its relationship with participants’ age. This article is a demo of how to use Hilbert transform to calc
Xu Cui
1 min read

nirs2img, create an image file from NIRS data

Update 2021/2/27: If you find griddata3 not working, try to change griddata3 to griddata. I was asked where to get nirs2img script. Here it is. The download link is at the bottom of this article. nirs2img is to create an image file from the input dat
Xu Cui
51 sec read

Leave a Reply

Your email address will not be published. Required fields are marked *