# Rotation

Rotations are Non Deformative Simple or Composite Transformations that any object can be subjected to. It refers to angular change in the position of coordinate points of an object, either because the object is rotated or the coordinate system is rotated. Rotation can happen either clockwise or counter/anti clockwise. Rotating an object/point clockwise is similar to rotating the coordinate system/equation of an object counter clockwise. Conversely, rotating an object/point counter clockwise is similar to rotating the coordinate system/equation of an object clockwise.

## Rotations in 2D

Rotations is 2D can either happen with respect to origin or with repect to any other point on the plane.

1. Rotation with respect to origin: This is a Simple Transformation. To understand this let's consider a point (x,y) at a distance d from the origin (0,0). The line joining this point and the origin makes an angle $$\theta$$ with the positive direction of x axis. Then the coordinates of the point can be given in terms of the distance d and the angle $$\theta$$ as:
$$x = d \cos(\theta)$$
$$y = d \sin(\theta)$$

Now if the point (x,y) is rotated counter clockwise by an angle $$A$$ then the new point (x',y') shall be given as:
$$x' = d \cos(\theta + A)$$
$$\Rightarrow x' = d \cos(\theta)\cos(A) - d \sin(\theta)\sin(A)$$
$$\Rightarrow x' = x \cos(A) - y \sin(A)$$

$$y' = d \sin(\theta + A)$$
$$\Rightarrow y' = d \sin(\theta)\cos(A) + d \cos(\theta)\sin(A)$$
$$\Rightarrow y' = y \cos(A) + x \sin(A)$$

Similarly, if the point (x,y) is rotated clockwise by an angle $$A$$ then the new point (x',y') shall be given as:
$$x' = d \cos(\theta - A)$$
$$\Rightarrow x' = d \cos(\theta)\cos(A) + d \sin(\theta)\sin(A)$$
$$\Rightarrow x' = x \cos(A) + y \sin(A)$$

$$y' = d \sin(\theta - A)$$
$$\Rightarrow y' = d \sin(\theta)\cos(A) - d \cos(\theta)\sin(A)$$
$$\Rightarrow y' = y \cos(A) - x \sin(A)$$

The following table summarises the formula for 2D Rotations with respect to origin:
 Rotation Type Equation Form Matrix Multiplication Form For counter clockwise rotation of a point/object (clockwise rotation of equation / coordinate system) $$x' = x \cos(A) - y \sin(A)$$ $$y' = y \cos(A) + x \sin(A)$$ $$\begin{bmatrix} cos(A) & -sin(A) \\ sin(A) & cos(A) \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} = \begin{bmatrix} x' \\ y' \end{bmatrix}\hspace{1cm} OR \hspace{1cm} \begin{bmatrix} x & y \end{bmatrix} \begin{bmatrix} cos(A) & sin(A) \\ -sin(A) & cos(A) \end{bmatrix} = \begin{bmatrix} x' & y' \end{bmatrix}$$ For clockwise rotation of a point/object (counter clockwise rotation of equation / coordinate system) $$x' = x \cos(A) + y \sin(A)$$ $$y' = y \cos(A) - x \sin(A)$$ $$\begin{bmatrix} cos(A) & sin(A) \\ -sin(A) & cos(A) \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} = \begin{bmatrix} x' \\ y' \end{bmatrix}\hspace{1cm} OR \hspace{1cm} \begin{bmatrix} x & y \end{bmatrix} \begin{bmatrix} cos(A) & -sin(A) \\ sin(A) & cos(A) \end{bmatrix} = \begin{bmatrix} x' & y' \end{bmatrix}$$ Note: The angle A given in above matrices and formulae (and in matrices and formulae in the rest of the document) must be greater than or equal to zero. If the angle is lesser than zero then all the matrices and formulae that do clockwise rotations will rotate counter clockwise and vice versa.
2. Rotation with respect to any other point on plane $$(t_x,t_y)$$: This is a Composite Transformation involving the multiple Simple Transformations applied in the following order:
1. Shift the origin to $$(t_x,t_y)$$
2. Apply the required rotation
3. Undo the shifting of origin, i.e. shift the origin back to $$(0,0)$$
For counter clockwise rotation of an object/point with respect to $$(t_x,t_y)$$ the transformation matrix can be obtained by following Matrix Multiplication:
 Matrix Type Matrix Post Multiplication $$\begin{bmatrix} 1 & 0 & t_x \\ 0 & 1 & t_y \\0 & 0 & 1 \end{bmatrix} \begin{bmatrix} cos(A) & -sin(A) & 0 \\sin(A) & cos(A) & 0 \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & -t_x \\ 0 & 1 & -t_y \\0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} = \begin{bmatrix} cos(A) & -sin(A) & t_x (1-cos(A)) + t_y sin(A) \\sin(A) & cos(A) & t_y (1-cos(A)) - t_x sin(A) \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}$$ Pre Multiplication $$\begin{bmatrix} x & y & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\-t_x & -t_y & 1 \end{bmatrix} \begin{bmatrix} cos(A) & sin(A) & 0 \\-sin(A) & cos(A) & 0 \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\t_x & t_y & 1 \end{bmatrix} = \begin{bmatrix} x & y & 1 \end{bmatrix} \begin{bmatrix} cos(A) & sin(A) & 0\\-sin(A) & cos(A) & 0 \\ t_x (1-cos(A)) + t_y sin(A) & t_y (1-cos(A)) - t_x sin(A) & 1 \end{bmatrix}$$ Equation $$x' = x \cos(A) - y \sin(A) + t_x (1-cos(A)) + t_y sin(A)$$ $$y' = y \cos(A) + x \sin(A)+ t_y (1-cos(A)) - t_x sin(A)$$

For clockwise rotation of an object/point with respect to $$(t_x,t_y)$$ the transformation matrix can be obtained by following Matrix Multiplication:
 Matrix Type Matrix Post Multiplication $$\begin{bmatrix} 1 & 0 & t_x \\ 0 & 1 & t_y \\0 & 0 & 1 \end{bmatrix} \begin{bmatrix} cos(A) & sin(A) & 0 \\-sin(A) & cos(A) & 0 \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & -t_x \\ 0 & 1 & -t_y \\0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} = \begin{bmatrix} cos(A) & sin(A) & t_x (1-cos(A)) - t_y sin(A) \\-sin(A) & cos(A) & t_y (1-cos(A)) + t_x sin(A) \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}$$ Pre Multiplication $$\begin{bmatrix} x & y & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\-t_x & -t_y & 1 \end{bmatrix} \begin{bmatrix} cos(A) & -sin(A) & 0 \\sin(A) & cos(A) & 0 \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\t_x & t_y & 1 \end{bmatrix} = \begin{bmatrix} x & y & 1 \end{bmatrix} \begin{bmatrix} cos(A) & -sin(A) & 0\\sin(A) & cos(A) & 0 \\ t_x (1-cos(A)) - t_y sin(A) & t_y (1-cos(A)) + t_x sin(A) & 1 \end{bmatrix}$$ Equation $$x' = x \cos(A) + y \sin(A) + t_x (1-cos(A)) - t_y sin(A)$$ $$y' = y \cos(A) - x \sin(A)+ t_y (1-cos(A)) + t_x sin(A)$$

## Rotations in 3D

Rotations is 3D can happen in the following manner:

1. Rotation with respect to origin (0,0,0) along a particular coordinate axis (x,y or z):
1. Rotation along x axis:
 Rotation Type Equation Form Matrix Form For counter clockwise rotation of a point (clockwise rotation of equation / x axis) $$x'=x$$ $$y' = y \cos(A) - z \sin(A)$$ $$z' = z \cos(A) + y \sin(A)$$ $$\begin{bmatrix} 1 & 0 & 0 \\ 0 & cos(A) & -sin(A) \\0 & sin(A) & cos(A) \end{bmatrix} \begin{bmatrix} x \\ y \\ z \end{bmatrix} = \begin{bmatrix} x' \\ y' \\ z' \end{bmatrix}\hspace{.5cm} OR \hspace{.5cm} \begin{bmatrix} x & y & z \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 \\ 0 & cos(A) & sin(A) \\0 & -sin(A) & cos(A) \end{bmatrix} = \begin{bmatrix} x' & y' & z' \end{bmatrix}$$ For clockwise rotation of a point (counter clockwise rotation of equation / x axis) $$x'=x$$ $$y' = y \cos(A) + z \sin(A)$$ $$z' = z \cos(A) - y \sin(A)$$ $$\begin{bmatrix} 1 & 0 & 0 \\ 0 & cos(A) & sin(A) \\0 & -sin(A) & cos(A) \end{bmatrix} \begin{bmatrix} x \\ y \\ z \end{bmatrix} = \begin{bmatrix} x' \\ y' \\ z' \end{bmatrix}\hspace{.5cm} OR \hspace{.5cm} \begin{bmatrix} x & y & z \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 \\ 0 & cos(A) & -sin(A) \\0 & sin(A) & cos(A) \end{bmatrix} = \begin{bmatrix} x' & y' & z' \end{bmatrix}$$
2. Rotation along y axis:
 Rotation Type Equation Form Matrix Form For counter clockwise rotation of a point (clockwise rotation of equation / y axis) $$x' = x \cos(A) + z \sin(A)$$ $$y'=y$$ $$z' = z \cos(A) - x \sin(A)$$ $$\begin{bmatrix}cos(A) & 0 & sin(A) \\0 & 1 & 0 \\ -sin(A) & 0 & cos(A) \end{bmatrix} \begin{bmatrix} x \\ y \\ z \end{bmatrix} = \begin{bmatrix} x' \\ y' \\ z' \end{bmatrix}\hspace{.5cm} OR \hspace{.5cm} \begin{bmatrix} x & y & z \end{bmatrix} \begin{bmatrix}cos(A) & 0 & -sin(A) \\0 & 1 & 0 \\ sin(A) & 0 & cos(A) \end{bmatrix} = \begin{bmatrix} x' & y' & z' \end{bmatrix}$$ For clockwise rotation of a point (counter clockwise rotation of equation / y axis) $$x' = x \cos(A) - z \sin(A)$$ $$y'=y$$ $$z' = z \cos(A) + x \sin(A)$$ $$\begin{bmatrix}cos(A) & 0 & -sin(A) \\0 & 1 & 0 \\ sin(A) & 0 & cos(A) \end{bmatrix} \begin{bmatrix} x \\ y \\ z \end{bmatrix} = \begin{bmatrix} x' \\ y' \\ z' \end{bmatrix}\hspace{.5cm} OR \hspace{.5cm} \begin{bmatrix} x & y & z \end{bmatrix} \begin{bmatrix}cos(A) & 0 & sin(A) \\0 & 1 & 0 \\ -sin(A) & 0 & cos(A) \end{bmatrix} = \begin{bmatrix} x' & y' & z' \end{bmatrix}$$ Please notice the difference from x axis & z axis rotations in Matrix Form
3. Rotation along z axis:
 Rotation Type Equation Form Matrix Form For counter clockwise rotation of a point (clockwise rotation of equation / z axis) $$x' = x \cos(A) - y \sin(A)$$ $$y' = y \cos(A) + x \sin(A)$$ $$z'=z$$ $$\begin{bmatrix} cos(A) & -sin(A) & 0 \\sin(A) & cos(A) & 0 \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \end{bmatrix} = \begin{bmatrix} x' \\ y' \\ z' \end{bmatrix}\hspace{.5cm} OR \hspace{.5cm} \begin{bmatrix} x & y & z \end{bmatrix} \begin{bmatrix} cos(A) & sin(A) & 0 \\-sin(A) & cos(A) & 0 \\ 0 & 0 & 1 \end{bmatrix} = \begin{bmatrix} x' & y' & z' \end{bmatrix}$$ For clockwise rotation of a point (counter clockwise rotation of equation / z axis) $$x' = x \cos(A) + y \sin(A)$$ $$y' = y \cos(A) - x \sin(A)$$ $$z'=z$$ $$\begin{bmatrix} cos(A) & sin(A) & 0 \\-sin(A) & cos(A) & 0 \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \end{bmatrix} = \begin{bmatrix} x' \\ y' \\ z' \end{bmatrix}\hspace{.5cm} OR \hspace{.5cm} \begin{bmatrix} x & y & z \end{bmatrix} \begin{bmatrix} cos(A) & -sin(A) & 0 \\sin(A) & cos(A) & 0 \\ 0 & 0 & 1 \end{bmatrix} = \begin{bmatrix} x' & y' & z' \end{bmatrix}$$ Please notice the similarity with 2D rotations
2. Rotation with respect to any arbitrary point $$(t_x,t_y,t_z)$$ along a particular coordinate axis (x,y or z): Just like 2D Rotation with respect to any arbitrary point, this is a Composite Transformation involving the multiple Simple Transformations applied in the following order:
1. Shift the origin to $$(t_x,t_y,t_z)$$
2. Apply the required rotation
3. Undo the shifting of origin, i.e. shift the origin back to $$(0,0,0)$$
For counter clockwise rotation along x axis of an object/point with respect to $$(t_x,t_y,t_z)$$ the transformation matrix can be obtained by following Matrix Multiplication:
 Matrix Type Matrix Post Multiplication $$\begin{bmatrix} 1 & 0 & 0 & t_x \\ 0 & 1 & 0 & t_y \\0 & 0 & 1 & t_z \\0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & cos(A) & -sin(A) & 0 \\0 & sin(A) & cos(A) & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & -t_x \\ 0 & 1 & 0 & -t_y \\ 0 & 0 & 1 & -t_z \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & cos(A) & -sin(A) & t_y (1-cos(A)) + t_z sin(A) \\0 & sin(A) & cos(A) & t_z (1-cos(A)) - t_y sin(A)\\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix}$$ Pre Multiplication $$\begin{bmatrix} x & y & z & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\0 & 0 & 1 & 0 \\ -t_x & -t_y & -t_z & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & cos(A) & sin(A) & 0 \\0 & -sin(A) & cos(A) & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\t_x & t_y & t_z & 1 \end{bmatrix} = \begin{bmatrix} x & y & z & 1 \end{bmatrix} \begin{bmatrix}1 & 0 & 0 & 0 \\0 & cos(A) & sin(A) & 0 \\0 & -sin(A) & cos(A) & 0 \\ 0 & t_y (1-cos(A)) + t_z sin(A) & t_z (1-cos(A)) - t_y sin(A) & 1 \end{bmatrix}$$ Equation $$x' = x$$ $$y' = y \cos(A) - z \sin(A) + t_y (1-cos(A)) + t_z sin(A)$$ $$z' = z \cos(A) + y \sin(A)+ t_z (1-cos(A)) - t_y sin(A)$$

For clockwise rotation along x axis of an object/point with respect to $$(t_x,t_y,t_z)$$ the the transformation matrix can be obtained by following Matrix Multiplication:
 Matrix Type Matrix Post Multiplication $$\begin{bmatrix} 1 & 0 & 0 & t_x \\ 0 & 1 & 0 & t_y \\0 & 0 & 1 & t_z \\0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & cos(A) & sin(A) & 0 \\0 & -sin(A) & cos(A) & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & -t_x \\ 0 & 1 & 0 & -t_y \\ 0 & 0 & 1 & -t_z \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & cos(A) & sin(A) & t_y (1-cos(A)) - t_z sin(A) \\0 & -sin(A) & cos(A) & t_z (1-cos(A)) + t_y sin(A)\\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix}$$ Pre Multiplication $$\begin{bmatrix} x & y & z & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\0 & 0 & 1 & 0 \\ -t_x & -t_y & -t_z & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & cos(A) & -sin(A) & 0 \\0 & sin(A) & cos(A) & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\t_x & t_y & t_z & 1 \end{bmatrix} = \begin{bmatrix} x & y & z & 1 \end{bmatrix} \begin{bmatrix}1 & 0 & 0 & 0 \\0 & cos(A) & -sin(A) & 0 \\0 & sin(A) & cos(A) & 0 \\ 0 & t_y (1-cos(A)) - t_z sin(A) & t_z (1-cos(A)) + t_y sin(A) & 1 \end{bmatrix}$$ Equation $$x' = x$$ $$y' = y \cos(A) + z \sin(A) + t_y (1-cos(A)) - t_z sin(A)$$ $$z' = z \cos(A) - y \sin(A)+ t_z (1-cos(A)) + t_y sin(A)$$

For counter clockwise rotation along y axis of an object/point with respect to $$(t_x,t_y,t_z)$$ the transformation matrix can be obtained by following Matrix Multiplication:
 Matrix Type Matrix Post Multiplication $$\begin{bmatrix} 1 & 0 & 0 & t_x \\ 0 & 1 & 0 & t_y \\0 & 0 & 1 & t_z \\0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix}cos(A) & 0 & sin(A) & 0 \\ 0 & 1 & 0 & 0 \\-sin(A) & 0 & cos(A) & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & -t_x \\ 0 & 1 & 0 & -t_y \\ 0 & 0 & 1 & -t_z \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} = \begin{bmatrix}cos(A) & 0 & sin(A) & t_x (1-cos(A)) - t_z sin(A) \\ 0 & 1 & 0 & 0 \\-sin(A) & 0 & cos(A) & t_z (1-cos(A)) + t_x sin(A)\\ 0 & 0 & 0 & 1\end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix}$$ Pre Multiplication $$\begin{bmatrix} x & y & z & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\0 & 0 & 1 & 0 \\ -t_x & -t_y & -t_z & 1 \end{bmatrix} \begin{bmatrix}cos(A) & 0 & -sin(A) & 0 \\ 0 & 1 & 0 & 0 \\sin(A) & 0 & cos(A) & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\t_x & t_y & t_z & 1 \end{bmatrix} = \begin{bmatrix} x & y & z & 1 \end{bmatrix} \begin{bmatrix}cos(A) & 0 & -sin(A) & 0 \\0 & 1 & 0 & 0\\sin(A) & 0 & cos(A) & 0 \\ t_x (1-cos(A)) - t_z sin(A) & 0 & t_z (1-cos(A)) + t_x sin(A) & 1 \end{bmatrix}$$ Equation $$x' = x \cos(A) + z \sin(A) + t_x (1-cos(A)) - t_z sin(A)$$ $$y'=y$$ $$z' = z \cos(A) - x \sin(A) + t_z (1-cos(A)) + t_x sin(A)$$

For clockwise rotation along y axis of an object/point with respect to $$(t_x,t_y,t_z)$$ the the transformation matrix can be obtained by following Matrix Multiplication:
 Matrix Type Matrix Post Multiplication $$\begin{bmatrix} 1 & 0 & 0 & t_x \\ 0 & 1 & 0 & t_y \\0 & 0 & 1 & t_z \\0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix}cos(A) & 0 & -sin(A) & 0 \\ 0 & 1 & 0 & 0 \\sin(A) & 0 & cos(A) & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & -t_x \\ 0 & 1 & 0 & -t_y \\ 0 & 0 & 1 & -t_z \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} = \begin{bmatrix}cos(A) & 0 & -sin(A) & t_x (1-cos(A)) + t_z sin(A) \\ 0 & 1 & 0 & 0 \\sin(A) & 0 & cos(A) & t_z (1-cos(A)) - t_x sin(A)\\ 0 & 0 & 0 & 1\end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix}$$ Pre Multiplication $$\begin{bmatrix} x & y & z & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\0 & 0 & 1 & 0 \\ -t_x & -t_y & -t_z & 1 \end{bmatrix} \begin{bmatrix}cos(A) & 0 & sin(A) & 0 \\ 0 & 1 & 0 & 0 \\-sin(A) & 0 & cos(A) & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\t_x & t_y & t_z & 1 \end{bmatrix} = \begin{bmatrix} x & y & z & 1 \end{bmatrix} \begin{bmatrix}cos(A) & 0 & sin(A) & 0 \\0 & 1 & 0 & 0\\-sin(A) & 0 & cos(A) & 0 \\ t_x (1-cos(A)) + t_z sin(A) & 0 & t_z (1-cos(A)) - t_x sin(A) & 1 \end{bmatrix}$$ Equation $$x' = x \cos(A) - z \sin(A) + t_x (1-cos(A)) + t_z sin(A)$$ $$y'=y$$ $$z' = z \cos(A) + x \sin(A) + t_z (1-cos(A)) - t_x sin(A)$$

For counter clockwise rotation along z axis of an object/point with respect to $$(t_x,t_y,t_z)$$ the transformation matrix can be obtained by following Matrix Multiplication:
 Matrix Type Matrix Post Multiplication $$\begin{bmatrix} 1 & 0 & 0 & t_x \\ 0 & 1 & 0 & t_y \\0 & 0 & 1 & t_z \\0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} cos(A) & -sin(A) & 0 & 0 \\sin(A) & cos(A) & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & -t_x \\ 0 & 1 & 0 & -t_y \\ 0 & 0 & 1 & -t_z \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} = \begin{bmatrix} cos(A) & -sin(A) & 0 & t_x (1-cos(A)) + t_y sin(A) \\sin(A) & cos(A) & 0 & t_y (1-cos(A)) - t_x sin(A)\\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix}$$ Pre Multiplication $$\begin{bmatrix} x & y & z & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0\\0 & 0 & 1 & 0 \\ -t_x & -t_y & -t_z & 1 \end{bmatrix} \begin{bmatrix} cos(A) & sin(A) & 0 & 0 \\-sin(A) & cos(A) & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\t_x & t_y & t_z & 1 \end{bmatrix} = \begin{bmatrix} x & y & z & 1 \end{bmatrix} \begin{bmatrix}cos(A) & sin(A) & 0 & 0 \\-sin(A) & cos(A) & 0 & 0 \\ 0 & 0 & 1 & 0 \\ t_x (1-cos(A)) + t_y sin(A) & t_y (1-cos(A)) - t_x sin(A) & 0 & 1 \end{bmatrix}$$ Equation $$x' = x \cos(A) - y \sin(A) + t_x (1-cos(A)) + t_y sin(A)$$ $$y' = y \cos(A) + x \sin(A)+ t_y (1-cos(A)) - t_x sin(A)$$ $$z' = z$$

For clockwise rotation along z axis of an object/point with respect to $$(t_x,t_y,t_z)$$ the the transformation matrix can be obtained by following Matrix Multiplication:
 Matrix Type Matrix Post Multiplication $$\begin{bmatrix} 1 & 0 & 0 & t_x \\ 0 & 1 & 0 & t_y \\0 & 0 & 1 & t_z \\0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} cos(A) & sin(A) & 0 & 0 \\-sin(A) & cos(A) & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & -t_x \\ 0 & 1 & 0 & -t_y \\ 0 & 0 & 1 & -t_z \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} = \begin{bmatrix} cos(A) & sin(A) & 0 & t_x (1-cos(A)) - t_y sin(A) \\-sin(A) & cos(A) & 0 & t_y (1-cos(A)) + t_x sin(A)\\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix}$$ Pre Multiplication $$\begin{bmatrix} x & y & z & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\0 & 0 & 1 & 0 \\ -t_x & -t_y & -t_z & 1 \end{bmatrix} \begin{bmatrix} cos(A) & -sin(A) & 0 & 0 \\sin(A) & cos(A) & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\t_x & t_y & t_z & 1 \end{bmatrix} = \begin{bmatrix} x & y & z & 1 \end{bmatrix} \begin{bmatrix}cos(A) & -sin(A) & 0 & 0 \\sin(A) & cos(A) & 0 & 0 \\ 0 & 0 & 1 & 0 \\ t_x (1-cos(A)) - t_y sin(A) & t_y (1-cos(A)) + t_x sin(A) & 0 & 1 \end{bmatrix}$$ Equation $$x' = x \cos(A) + y \sin(A) + t_x (1-cos(A)) - t_y sin(A)$$ $$y' = y \cos(A) - x \sin(A)+ t_y (1-cos(A)) + t_x sin(A)$$ $$z' = z$$
3. Rotation with respect to origin (0,0,0) along any arbitrary unit vector <X,Y,Z>: This is a Composite Transformation involving following five Simple Transformations in the following order.
1. Rotate along any of the coordinate axes so that the vector projects to one of the coordinate planes (xy, yz or zx)
2. Rotate along the coordinate axis on which the vector does not lie. For eg. if the vector lies on coordinate plane xy, then rotate along z axis so that the vector aligns with either x or y axis. Similarly if the vector lies on coordinate plane yz, then rotate along x axis so that the vector aligns with either y or z axis and if the vector lies on coordinate plane zx, then rotate along y axis so that the vector aligns with either z or x axis.
3. Apply the required rotation along the axis to which the vector has been aligned
4. Undo the rotation given in Step b by rotating in the opposite direction of Step b.
5. Undo the rotation given in Step a by rotating in the opposite direction of Step a.
Please note that depending on the coordinate axes to which one would like to align the vector, many configurations of matrices are possible for performing the rotations given in Step a and correspondingly in Step b. Hence the matrix used to perform Stem d is Transpose/Inverse of the matrix used in Step b. Also the matrix used to perform Stem e is Transpose/Inverse of the matrix used in Step a.
Irrespective of the rotation matrices chosen in Steps a and b and correspondingly in Steps d and e, the transformation matrix for rotating along any arbitrary unit vector <X,Y,Z> comes down to following:
 Rotation Type Transformation Matrix For counter clockwise rotation of a point (clockwise rotation of equation) $$\begin{bmatrix} tX^2 + c & tXY - sZ & tXZ + sY\\tXY + sZ & tY^2 + c & tYZ - sX\\tXZ - sY & tYZ + sX & tZ^2 + c\end{bmatrix} \begin{bmatrix} x \\ y \\ z \end{bmatrix} = \begin{bmatrix} x' \\ y' \\ z' \end{bmatrix}\hspace{.5cm} OR \hspace{.5cm} \begin{bmatrix} x & y & z \end{bmatrix} \begin{bmatrix} tX^2 + c & tXY + sZ & tXZ - sY\\tXY - sZ & tY^2 + c & tYZ + sX\\tXZ + sY & tYZ - sX & tZ^2 + c\end{bmatrix} = \begin{bmatrix} x' & y' & z' \end{bmatrix}$$ For clockwise rotation of a point (counter clockwise rotation of equation) $$\begin{bmatrix} tX^2 + c & tXY + sZ & tXZ - sY\\tXY - sZ & tY^2 + c & tYZ + sX\\tXZ + sY & tYZ - sX & tZ^2 + c\end{bmatrix}\begin{bmatrix} x \\ y \\ z \end{bmatrix} = \begin{bmatrix} x' \\ y' \\ z' \end{bmatrix}\hspace{.5cm} OR \hspace{.5cm} \begin{bmatrix} x & y & z \end{bmatrix} \begin{bmatrix} tX^2 + c & tXY - sZ & tXZ + sY\\tXY + sZ & tY^2 + c & tYZ - sX\\tXZ - sY & tYZ + sX & tZ^2 + c\end{bmatrix} = \begin{bmatrix} x' & y' & z' \end{bmatrix}$$ Where c = cos (A), s = sin (A), t = 1-cos (A), and is the unit vector representing the arbitary axis
4. Rotation with respect to any arbitrary point $$(t_x,t_y,t_z)$$ along any arbitrary unit vector <X,Y,Z>: This is a Composite Transformation involving following transformations in the following order.
1. Shift the origin to $$(t_x,t_y,t_z)$$
2. Apply the required rotation along vector <X,Y,Z>
3. Undo the shifting of origin, i.e. shift the origin back to $$(0,0,0)$$