I have a 2D square ABCD in a 3D space, with side length 2s, that is represented by four vectors (one for each vertex) and a fifth vector v for the center point.The square lies standing upright on the plane z = -1 (xy plane).v  = < 0, 0, -1>OA = <-s, s, -1>OB = < s, s, -1>OC = <-s,-s, -1>OD = < s,-s, -1>Now, consider point P anywhere in the 3D space. I want to rotate the square around the origin, such that v aligns with OP. The result that I want is mainly the resulting rotated OA, OB, OC and OD vectors.Screenshot of scenario.The point P is arbitrary and can be any point in the 3D space. Any help is greatly appreciated!
Rotate 2D shape around origin in a 3D space
vector;3d
You should take a look at the Wikipedia page on rotation matrices, specifically the section on forming a rotation matrix from an axis and an angle. In your case, you have a vector $\vec{v}$ that you would like to align with another vector, $\vec{OP}$. The axis of rotation should be the unit vector $\hat{u}$ normal to these two vectors given by$$\vec{n}=\vec{v}\times\vec{OP},~~\hat{u}=\dfrac{\vec{n}}{||\vec{n}||}.$$The order of the cross product is important.The angle between the two vectors is given by$$\theta = \operatorname{acos}\left(\dfrac{\vec{v}\cdot\vec{OP}}{\left|\left|\vec{v}\right|\right|~\left|\left|\vec{OP}\right|\right|}\right)$$where $\theta\in[0,\pi)$.Once you have an angle and an axis of rotation you can form the rotation matrix $R$. This is given ason the Wikipedia page. To rotate your square (and any other vectors or points of interest) so that $\vec{v}$ is aligned with $\vec{OP}$ simply multiply all the coordinates $\vec{OA}$, $\vec{OB}$, $\vec{OC}$, and $\vec{OD}$ by the rotation matrix $R$. As mentioned in a comment, you could then also rotated the resulting points by any angle you wish about the axis $\vec{v}_{\text{new}}=\vec{OP}$ while still maintaining the same orientation for $\vec{v}_{\text{new}}$.I believe the only cases where this will fail are if $\vec{OP}=\pm\vec{v}$, in which case the cross product is zero. If $\vec{OP}=\vec{v}$ then there is nothing to do. If $\vec{OP}=-\vec{v}$ then $\theta = \pi$ you can choose $\vec{n} = (a,b,0)$ for any $a$ and $b$ you wish.