I have point A and point B in a 3D world defined by X,Y,Z and I wish to rotate B around A using C defined by X,Y,Z (pitch, roll, yaw respectively). How do I do this please? I believe I may need to use a rotation matrix. I am attempting to do this in code so some pseudo code example would really help.
Rotate 3D Point Around Point
1.3k Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail AtThere are 3 best solutions below
On
That means that $B$ will remain on a sphere centered in $A$ and of radius $|AB|$. To individuate the position of $B'$ on the sphere you need only two angular parameters: delta latitude and delta longitude, because the rotation around the $AB$ axis won't move $B$. Can you take on from here ?
On
A rotation matrix ${\rm R}$ describes a rotation about the origin. If you want to rotate B around A then you do the following operation
$$ \vec{r}_C = \vec{r}_A + {\rm R}\; (\vec{r}_B-\vec{r}_A) $$
where you subtract the coordinates $\vec{r}_A$ of the pivot A from the coordinates of the target $\vec{r}_B$, do the rotation defined by the 3×3 rotation matrix ${\rm R}$, and then add the pivot coordinates again to get the resulting coordinates $\vec{r}_C$.
If you are asking how to construct the rotation matrix ${\rm R}$, then you have not provided any information in the question on the requirements, other than they might be given by roll/pitch/yaw Euler angles. There are other options, such as axis-angle, or a quaternion to store the rotation information. In the end, all of those need to allow you to construct the rotation matrix ${\rm R}$.
Euler angles - Rotation is defined by three rotations about three known orthogonal directions. There are many conventions here that depend on your coordinate system orientation and sequence of rotations. All of them involve the multiplication of three elementary rotation matrices in sequence.
An example would be the XYZ scheme $${\rm R} = {\rm R}_X(\alpha)\, {\rm R}_Y(\beta) \,{\rm R}_Z(\gamma) $$
Axis-angle - Here the rotation is given by an angle $\phi$ about a single arbitrary axis $\boldsymbol{\hat{u}}$. The rotation matrix is constructed using the Rodrigues formula.
$${\rm R} = I + \sin \phi [\boldsymbol{\hat{u}}\times] + (1-\cos \phi) [\boldsymbol{\hat{u}}\times] [\boldsymbol{\hat{u}}\times] $$
Quaternions - Also known as Euler parameters, this is a scheme where 4 numbers encode a positive angle $\phi$ and rotation axis $\boldsymbol{\hat{u}}$ in the following manner
$$ \pmatrix{a \\ b \\ c \\ d} = \pmatrix{ \cos \tfrac{\phi}{2} \\ \boldsymbol{\hat{u}}_x \sin \tfrac{\phi}{2} \\ \boldsymbol{\hat{u}}_y \sin \tfrac{\phi}{2} \\ \boldsymbol{\hat{u}}_z \sin \tfrac{\phi}{2} } $$
A rotation matrix is extracted from the four numbers with the following process
$${\rm R} = \frac{2}{m^2} \pmatrix{ \tfrac{m^2}{2} - c^2 -d^2 & b c - a d & a c + b d \\ a d + b c & \tfrac{m^2}{2} -b^2-d^2 & c d -a b \\ b d - a c & a b + c d & \tfrac{m^2}{2} - b^2-c^2 }$$
where $m^2 = a^2+b^2+c^2+d^2$.
Since I have not encountered any situation using codes, I am afraid I cannot give an example using code. you may want to look at Quaternions, which are $a+bi+cj+dk$ numbers while $a,b,c,d\in\mathbb{R}$. These numbers can help you both define an axis of rotation and angle of rotation. For me, they are the commonly used way of expressing rotations in code, as my friend in computer sciences often talks about this.
If you really want to look at the matrix form and some Java code, you can visit the site:https://sites.google.com/site/glennmurray/Home/rotation-matrices-and-formulas
Hope I helped. This is my first answer here and I hope I did not break any rules.