3D transform cylinder to make center line z axis I have an array of points that represent the surface of a cylinder, I was able to calculate the center line of this cylinder but it is translated and rotated away from origin. I want to transform this cylinder to make the center line become the Z axis, I remember it was done by multiplying with a transform matrix but I don't remember how.
here is an example of the cylinder, I have the center line 2 points (start and end), bottom point is supposed to become the new (0,0,0) origin, I added some numbers for simplification.

What I want:

any help is much appreciated
 A: With the rotation matrix
$$R=\left(
\begin{array}{ccc}
 \frac{1}{6} \left(\sqrt{3}+3\right) & \frac{1}{6} \left(\sqrt{3}-3\right) & -\frac{1}{\sqrt{3}} \\
 \frac{1}{6} \left(\sqrt{3}-3\right) & \frac{1}{6} \left(\sqrt{3}+3\right) & -\frac{1}{\sqrt{3}} \\
 \frac{1}{\sqrt{3}} & \frac{1}{\sqrt{3}} & \frac{1}{\sqrt{3}} \\
\end{array}
\right)$$
the points $(2,2,2)$ and $(3,3,3)$ become $\left(0,0,2 \sqrt{3}\right)$ and $\left(0,0,3 \sqrt{3}\right)$.
Thus, given a point $P=(x,y,z)$ the transformation
$$P'=RP+(0,0,-2\sqrt 3)$$
should do the job.

Edit
The rotation matrix for a generic vector $(d x,d y,d z)=(x_2-x_1,y_2-y_1,z_2-z1)$  is the following. To simplify the notation I substituted $d=\sqrt{dx^2+dy^2+dz^2}$
$$
R=\left(
\begin{array}{ccc}
 \frac{\frac{dx^2 dz}{d}+dy^2}{dx^2+dy^2} & \frac{dx dy \left(\frac{dz}{d}-1\right)}{dx^2+dy^2} & -\frac{dx}{d} \\
 \frac{dx dy \left(\frac{dz}{d}-1\right)}{dx^2+dy^2} & \frac{\frac{dy^2 dz}{d}+dx^2}{dx^2+dy^2} & -\frac{dy}{d} \\
 \frac{dx}{d} & \frac{dy}{d} & \frac{dz}{d} \\
\end{array}
\right)
$$
