What is parametric equation of a cylinder with an arbitrary norm in Cartesian system?

209 Views Asked by At

I just need to intersect a plane and a cylinder for an industry application and latter we would fit the intersection curve on to some sample data we have and that supposed to provide us with some model parameter which is of interest to us.

I just have a hard time figuring out parametric equation of a cylinder with radius r around an arbitrary normal vector $\overrightarrow{N}(a,b,c)$.

So, I tried different methods but none worked; then I decided to start with a cylinder with $Z(0,0,1)$ as normal vector.

$$ C_z : \,\,\, \begin{array}{|l} x=r\, \cos\!\left(q\right)\\ y = r\, \sin\!\left(q\right)\\ z=s \end{array} $$

Then rotated the Z axis as norm to the arbitrary norm using Matlab symbolic expressions.

To get the axis of rotation in 3D, I obtained the cross-product of the Z-norm and the arbitrary norm N(a,b,c) which led to:

$$(0,0,1) \times (a,b,c) = (-b,a,0)$$ Which looks a bit weird because it doesn't have z element???!!!

rotation axis: $$ \overrightarrow{Rot_{axis}} : [\begin{matrix} u_x = -b / sqrt(a^2+b^2) \\ u_y = a / sqrt(a^2+b^2); \\ u_z = 0 / sqrt(a^2+b^2); \end{matrix} ] $$

And, for rotation angle I used the inner/dot product of the two normal vectors: $$ cos(\theta) = {c \over \sqrt{a^2 + b^2 + c^2}} \\ \theta = {Atan{\sqrt{1-cos(\theta)^2} \over cos(\theta)}} $$

Given the axis and the angle of rotation, I used the below rotation matrix as discussed in the wiki page:

$$ {\displaystyle R={\begin{bmatrix}\cos \theta +u_{x}^{2}\left(1-\cos \theta \right)&u_{x}u_{y}\left(1-\cos \theta \right)-u_{z}\sin \theta &u_{x}u_{z}\left(1-\cos \theta \right)+u_{y}\sin \theta \\ u_{y}u_{x}\left(1-\cos \theta \right)+u_{z}\sin \theta &\cos \theta +u_{y}^{2}\left(1-\cos \theta \right)&u_{y}u_{z}\left(1-\cos \theta \right)-u_{x}\sin \theta \\u_{z}u_{x}\left(1-\cos \theta \right)-u_{y}\sin \theta &u_{z}u_{y}\left(1-\cos \theta \right)+u_{x}\sin \theta &\cos \theta +u_{z}^{2}\left(1-\cos \theta \right)\end{bmatrix}}.} $$

Then I plotted the rotated cylinders and they look fine to me.

Green is the Z-norm cylinder and red is (1,1,1)-norm cylinder.

The I used simplify symbolic function to get the parametric equation but it looks ugly to me:

$$ C_N: \,\,\, \begin{array}{|l} x=\frac{a^2\, c\, r\, \cos\!\left(q\right) + a\, s\, \sqrt{\frac{a^2 + b^2}{a^2 + b^2 + c^2}}\, \sqrt{a^2 + b^2}\, \sqrt{a^2 + b^2 + c^2} + a\, b\, c\, r\, \sin\!\left(q\right) + b^2\, c\, r\, \cos\!\left(q\right)\, \sqrt{\frac{a^2 + b^2 + c^2}{c^2}} - a\, b\, c\, r\, \sin\!\left(q\right)\, \sqrt{\frac{a^2 + b^2 + c^2}{c^2}}}{c\, \sqrt{\frac{a^2 + b^2 + c^2}{c^2}}\, \left(a^2 + b^2\right)}\\ y = \frac{b^2\, c\, r\, \sin\!\left(q\right) + b\, s\, \sqrt{\frac{a^2 + b^2}{a^2 + b^2 + c^2}}\, \sqrt{a^2 + b^2}\, \sqrt{a^2 + b^2 + c^2} + a\, b\, c\, r\, \cos\!\left(q\right) + a^2\, c\, r\, \sin\!\left(q\right)\, \sqrt{\frac{a^2 + b^2 + c^2}{c^2}} - a\, b\, c\, r\, \cos\!\left(q\right)\, \sqrt{\frac{a^2 + b^2 + c^2}{c^2}}}{c\, \sqrt{\frac{a^2 + b^2 + c^2}{c^2}}\, \left(a^2 + b^2\right)}\\ z = -\frac{a\, r\, \cos\!\left(q\right)\, \sqrt{\frac{a^2 + b^2}{a^2 + b^2 + c^2}}\, \sqrt{a^2 + b^2 + c^2} - c\, s\, \sqrt{a^2 + b^2} + b\, r\, \sin\!\left(q\right)\, \sqrt{\frac{a^2 + b^2}{a^2 + b^2 + c^2}}\, \sqrt{a^2 + b^2 + c^2}}{c\, \sqrt{\frac{a^2 + b^2 + c^2}{c^2}}\, \sqrt{a^2 + b^2}} \end{array} $$

So I have two question:

  1. Am I doing it right?
  2. Is there a better way to achieve this?

Below is the Matlab code I used for all the above:

close all;
grid on;
hold on;
xlabel x;
ylabel y;
zlabel z;

syms r q s a b c ;

Cz = [r*cos(q); r*sin(q); s];

% rotation axis
u_x = -b / sqrt(a^2+b^2);
u_y = a / sqrt(a^2+b^2);
u_z = 0 / sqrt(a^2+b^2);

% rotation angle
th = c / sqrt(a^2 + b^2 + c^2);
th = atan(sqrt(1-th^2)/th);

R = [cos(th) + u_x^2*(1-cos(th)),       u_x*u_y*(1-cos(th)) - u_z*sin(th), u_x*u_z*(1-cos(th)) + u_y*sin(th); ...
     u_y*u_x*(1-cos(th)) + u_z*sin(th), cos(th) + u_y^2*(1-cos(th)),       u_y*u_z*(1-cos(th)) - u_x*sin(th); ...
     u_z*u_x*(1-cos(th)) - u_y*sin(th), u_z*u_y*(1-cos(th))+u_x*sin(th),   cos(th) + u_z^2*(1-cos(th)) ...
     ];

Cu = R*Cz;
Cu = simplify(Cu)

Cu_v = subs(Cu, r, 5);
Cu_v = subs(Cu_v, q, -pi:pi/10:pi);
Cu_v = subs(Cu_v, s, -10:10);

Cu_v = subs(Cu_v, a, 1);
Cu_v = subs(Cu_v, b, 1);
Cu_v = subs(Cu_v, c, 1);

plot3(Cu_v(1,:), Cu_v(2,:), Cu_v(3,:), '.', 'color', 'red');


Cz_v = subs(Cz, r, 5);
Cz_v = subs(Cz_v, q, -pi:pi/10:pi);
Cz_v = subs(Cz_v, s, -10:10);
plot3(Cz_v(1,:), Cz_v(2,:), Cz_v(3,:), '.', 'color', 'green');
1

There are 1 best solutions below

0
On

P_eq_la:

\begin{array}{c} r\, \left(\frac{1}{\sqrt{1 - \frac{\left(\frac{c^2}{a^2 + b^2 + c^2} - 1\right)\, \left(a^2 + b^2 + c^2\right)}{c^2}}} - \frac{b^2\, \left(\frac{1}{\sqrt{1 - \frac{\left(\frac{c^2}{a^2 + b^2 + c^2} - 1\right)\, \left(a^2 + b^2 + c^2\right)}{c^2}}} - 1\right)}{a^2 + b^2}\right) + \frac{a\, b\, s\, \left(\frac{1}{\sqrt{1 - \frac{\left(\frac{c^2}{a^2 + b^2 + c^2} - 1\right)\, \left(a^2 + b^2 + c^2\right)}{c^2}}} - 1\right)}{a^2 + b^2}\\ s\, \left(\frac{1}{\sqrt{1 - \frac{\left(\frac{c^2}{a^2 + b^2 + c^2} - 1\right)\, \left(a^2 + b^2 + c^2\right)}{c^2}}} - \frac{a^2\, \left(\frac{1}{\sqrt{1 - \frac{\left(\frac{c^2}{a^2 + b^2 + c^2} - 1\right)\, \left(a^2 + b^2 + c^2\right)}{c^2}}} - 1\right)}{a^2 + b^2}\right) + \frac{a\, b\, r\, \left(\frac{1}{\sqrt{1 - \frac{\left(\frac{c^2}{a^2 + b^2 + c^2} - 1\right)\, \left(a^2 + b^2 + c^2\right)}{c^2}}} - 1\right)}{a^2 + b^2}\\ - \frac{a\, r\, \sqrt{1 - \frac{c^2}{a^2 + b^2 + c^2}}\, \sqrt{a^2 + b^2 + c^2}}{c\, \sqrt{1 - \frac{\left(\frac{c^2}{a^2 + b^2 + c^2} - 1\right)\, \left(a^2 + b^2 + c^2\right)}{c^2}}\, \sqrt{a^2 + b^2}} - \frac{b\, s\, \sqrt{1 - \frac{c^2}{a^2 + b^2 + c^2}}\, \sqrt{a^2 + b^2 + c^2}}{c\, \sqrt{1 - \frac{\left(\frac{c^2}{a^2 + b^2 + c^2} - 1\right)\, \left(a^2 + b^2 + c^2\right)}{c^2}}\, \sqrt{a^2 + b^2}} \end{array}

Cy_eq_la:

\begin{array}{c} \frac{a^2\, c\, r\, \cos\!\left(q\right) + a\, s\, \sqrt{\frac{a^2 + b^2}{a^2 + b^2 + c^2}}\, \sqrt{a^2 + b^2}\, \sqrt{a^2 + b^2 + c^2} + a\, b\, c\, r\, \sin\!\left(q\right) + b^2\, c\, r\, \cos\!\left(q\right)\, \sqrt{\frac{a^2 + b^2 + c^2}{c^2}} - a\, b\, c\, r\, \sin\!\left(q\right)\, \sqrt{\frac{a^2 + b^2 + c^2}{c^2}}}{c\, \sqrt{\frac{a^2 + b^2 + c^2}{c^2}}\, \left(a^2 + b^2\right)}\\ \frac{b^2\, c\, r\, \sin\!\left(q\right) + b\, s\, \sqrt{\frac{a^2 + b^2}{a^2 + b^2 + c^2}}\, \sqrt{a^2 + b^2}\, \sqrt{a^2 + b^2 + c^2} + a\, b\, c\, r\, \cos\!\left(q\right) + a^2\, c\, r\, \sin\!\left(q\right)\, \sqrt{\frac{a^2 + b^2 + c^2}{c^2}} - a\, b\, c\, r\, \cos\!\left(q\right)\, \sqrt{\frac{a^2 + b^2 + c^2}{c^2}}}{c\, \sqrt{\frac{a^2 + b^2 + c^2}{c^2}}\, \left(a^2 + b^2\right)}\\ -\frac{a\, r\, \cos\!\left(q\right)\, \sqrt{\frac{a^2 + b^2}{a^2 + b^2 + c^2}}\, \sqrt{a^2 + b^2 + c^2} - c\, s\, \sqrt{a^2 + b^2} + b\, r\, \sin\!\left(q\right)\, \sqrt{\frac{a^2 + b^2}{a^2 + b^2 + c^2}}\, \sqrt{a^2 + b^2 + c^2}}{c\, \sqrt{\frac{a^2 + b^2 + c^2}{c^2}}\, \sqrt{a^2 + b^2}} \end{array}

PCy_eq_la:

\begin{array}{c} r\, \left(\frac{1}{\sqrt{1 - \frac{\left(\frac{c^2}{a^2 + b^2 + c^2} - 1\right)\, \left(a^2 + b^2 + c^2\right)}{c^2}}} - \frac{b^2\, \left(\frac{1}{\sqrt{1 - \frac{\left(\frac{c^2}{a^2 + b^2 + c^2} - 1\right)\, \left(a^2 + b^2 + c^2\right)}{c^2}}} - 1\right)}{a^2 + b^2}\right) + \frac{a\, b\, s\, \left(\frac{1}{\sqrt{1 - \frac{\left(\frac{c^2}{a^2 + b^2 + c^2} - 1\right)\, \left(a^2 + b^2 + c^2\right)}{c^2}}} - 1\right)}{a^2 + b^2} = \frac{a^2\, c\, r\, \cos\!\left(q\right) + a\, s\, \sqrt{\frac{a^2 + b^2}{a^2 + b^2 + c^2}}\, \sqrt{a^2 + b^2}\, \sqrt{a^2 + b^2 + c^2} + a\, b\, c\, r\, \sin\!\left(q\right) + b^2\, c\, r\, \cos\!\left(q\right)\, \sqrt{\frac{a^2 + b^2 + c^2}{c^2}} - a\, b\, c\, r\, \sin\!\left(q\right)\, \sqrt{\frac{a^2 + b^2 + c^2}{c^2}}}{c\, \sqrt{\frac{a^2 + b^2 + c^2}{c^2}}\, \left(a^2 + b^2\right)}\\ s\, \left(\frac{1}{\sqrt{1 - \frac{\left(\frac{c^2}{a^2 + b^2 + c^2} - 1\right)\, \left(a^2 + b^2 + c^2\right)}{c^2}}} - \frac{a^2\, \left(\frac{1}{\sqrt{1 - \frac{\left(\frac{c^2}{a^2 + b^2 + c^2} - 1\right)\, \left(a^2 + b^2 + c^2\right)}{c^2}}} - 1\right)}{a^2 + b^2}\right) + \frac{a\, b\, r\, \left(\frac{1}{\sqrt{1 - \frac{\left(\frac{c^2}{a^2 + b^2 + c^2} - 1\right)\, \left(a^2 + b^2 + c^2\right)}{c^2}}} - 1\right)}{a^2 + b^2} = \frac{b^2\, c\, r\, \sin\!\left(q\right) + b\, s\, \sqrt{\frac{a^2 + b^2}{a^2 + b^2 + c^2}}\, \sqrt{a^2 + b^2}\, \sqrt{a^2 + b^2 + c^2} + a\, b\, c\, r\, \cos\!\left(q\right) + a^2\, c\, r\, \sin\!\left(q\right)\, \sqrt{\frac{a^2 + b^2 + c^2}{c^2}} - a\, b\, c\, r\, \cos\!\left(q\right)\, \sqrt{\frac{a^2 + b^2 + c^2}{c^2}}}{c\, \sqrt{\frac{a^2 + b^2 + c^2}{c^2}}\, \left(a^2 + b^2\right)}\\ - \frac{a\, r\, \sqrt{1 - \frac{c^2}{a^2 + b^2 + c^2}}\, \sqrt{a^2 + b^2 + c^2}}{c\, \sqrt{1 - \frac{\left(\frac{c^2}{a^2 + b^2 + c^2} - 1\right)\, \left(a^2 + b^2 + c^2\right)}{c^2}}\, \sqrt{a^2 + b^2}} - \frac{b\, s\, \sqrt{1 - \frac{c^2}{a^2 + b^2 + c^2}}\, \sqrt{a^2 + b^2 + c^2}}{c\, \sqrt{1 - \frac{\left(\frac{c^2}{a^2 + b^2 + c^2} - 1\right)\, \left(a^2 + b^2 + c^2\right)}{c^2}}\, \sqrt{a^2 + b^2}} = -\frac{a\, r\, \cos\!\left(q\right)\, \sqrt{\frac{a^2 + b^2}{a^2 + b^2 + c^2}}\, \sqrt{a^2 + b^2 + c^2} - c\, s\, \sqrt{a^2 + b^2} + b\, r\, \sin\!\left(q\right)\, \sqrt{\frac{a^2 + b^2}{a^2 + b^2 + c^2}}\, \sqrt{a^2 + b^2 + c^2}}{c\, \sqrt{\frac{a^2 + b^2 + c^2}{c^2}}\, \sqrt{a^2 + b^2}} \end{array}