-1
$\begingroup$

I have the following data returned from a least square fitting function:

Xc, x coordinate of the cylinder centre
Yc, y coordinate of the cylinder centre
alpha, rotation angle (radian) about the x-axis 
beta, rotation angle (radian) about the y-axis
r, radius of the cylinder

How can I now determine the cartesian equation of this cylinder?

Context: I am researching fatigue of welded joint. Therefore I am developing an algorithm which automates what is called the 'hot spot stress approach'. The script uses the output of a finite element model as input. My current algorithm works perfectly with welded plates but does not work for tubular joints. From the finite element model I extract a m x 4 matrix containing [x_co y_co z_co data] with m equal to the number of nodes on surface of the mesh. Thus I have point cloud. For tubular joints I know that this point cloud will fit to a cylinder. Thus my goal is to fit a cylindrical surface to this data. I can then use the equation of that cylinder to calculate the coordinates needed for the application of the hot spot stress approach.

Edit

Clarification: I have dataset containing points which forms a 3d point cloud. All these points come from the surface of a cylinder so I know that I can fit a cylinder to these points. What I basically need is the equation of the cylinder surface as I later need it for other calculations. Thus the equation should define an infinite cylinder surface which fits best to the dataset.

Edit2

Here is the (python) code I am using to fit the cylinder to my dataset. This code snippet was given in this thread but I honestly don't know how I can use this to get a cylinder equation. I would like to know if (and if so how) it is possible to determine the equation of the cylinder surface fitted to my data with the return values given back by this function.

import numpy as np
from scipy.optimize import leastsq


def cylinderFitting(xyz,p,th):

    """
    This is a fitting for a vertical cylinder fitting
    Reference:
    http://www.int-arch-photogramm-remote-sens-spatial-inf-sci.net/XXXIX-B5/169/2012/isprsarchives-XXXIX-B5-169-2012.pdf

    xyz is a matrix contain at least 5 rows, and each row stores x y z of a cylindrical surface
    p is initial values of the parameter;
    p[0] = Xc, x coordinate of the cylinder centre
    P[1] = Yc, y coordinate of the cylinder centre
    P[2] = alpha, rotation angle (radian) about the x-axis
    P[3] = beta, rotation angle (radian) about the y-axis
    P[4] = r, radius of the cylinder

    th, threshold for the convergence of the least squares

    """   
    x = xyz[:,0]
    y = xyz[:,1]
    z = xyz[:,2]

    fitfunc = lambda p, x, y, z: (- np.cos(p[3])*(p[0] - x) - z*np.cos(p[2])*np.sin(p[3]) - np.sin(p[2])*np.sin(p[3])*(p[1] - y))**2 + (z*np.sin(p[2]) - np.cos(p[2])*(p[1] - y))**2 #fit function
    errfunc = lambda p, x, y, z: fitfunc(p, x, y, z) - p[4]**2 #error function 

    est_p , success = leastsq(errfunc, p, args=(x, y, z), maxfev=1000)

    return est_p

if __name__=="__main__":

    np.set_printoptions(suppress=True)    
    xyz = np.loadtxt('cylinder11.xyz')
    #print xyz
    print "Initial Parameters: "
    p = np.array([-13.79,-8.45,0,0,0.3])
    print p
    print " "

    print "Performing Cylinder Fitting ... "
    est_p =  cylinderFitting(xyz,p,0.00001)
    print "Fitting Done!"
    print " "


    print "Estimated Parameters: "
    print est_p

Edit 3: $$ f_{v}(x_{ci},y_{ci},\alpha'_{i},\beta_{i},r_{i}) = \left[R_{2}(\beta_{i})R_{1}(\alpha'_{i})(x-x_{ci})\right]^2 +\left[R_2(\beta_i)R_1(\alpha'_i)(y-y_{ci})\right]^2 -r^2_i $$

Edit 4

$$ f_{v}(x_{ci},y_{ci},\alpha'_{i},\beta_{i},r_{i}) = X'^2 + Y'^2 -r_i^2 $$ with

$$ R_2(\beta_i) = \left[ \begin {array}{ccc} \cos \left( \beta_{i} \right) &0&\sin \left( \beta_{i} \right) \\ 0&1&0 \\ -\sin \left( \beta_{i} \right) &0&\cos \left( \beta_{i} \right) \end {array} \right] $$ $$ R_1(\alpha)=\left[ \begin {array}{ccc} 1&0&0\\0&\cos \left( \alpha_{i} \right) &-\sin \left( \alpha_{i} \right) \\0&\sin \left( \alpha_{i} \right) &\cos \left( \alpha_{i} \right) \end {array} \right] $$ this becomes: $$ \left[ \begin {array}{c} X'\\ Y'\\ Z'\end {array} \right] = \left[ \begin {array}{c} \cos \left( \beta_{i} \right) \left( x-x_{{\it ci}} \right) +\sin \left( \beta_{i} \right) \sin \left( \alpha_{i} \right) \left( y-y_{{\it ci}} \right) +\sin \left( \beta_{i} \right) \cos \left( \alpha_{i} \right) z\\ \cos \left( \alpha_{i} \right) \left( y-y_{{\it ci}} \right) -\sin \left( \alpha_{i} \right) z \\-\sin \left( \beta_{i} \right) \left( x-x_{{\it ci}} \right) +\cos \left( \beta_{i} \right) \sin \left( \alpha_{i} \right) \left( y-y_{{\it ci}} \right) +\cos \left( \beta_{i} \right) \cos \left( \alpha_{i} \right) z\end {array} \right] $$

$\endgroup$
  • $\begingroup$ Comments are not for extended discussion; this conversation has been moved to chat. $\endgroup$ – Aloizio Macedo May 12 at 21:02
0
$\begingroup$

The equation of a cylindre with a vertical axis is

$$(x'-x_c)^2+(y'-y_c)^2=r^2.$$

If you rotate it around some point $O$, with a rotation matrix $R$, the points are transformed by

$$P=R(P'-O)+O.$$ Conversely,

$$P'=R^T(P-O)+O$$ (as $R$ is an orthogonal matrix, $R^T=R^{-1}$).

Expanding these equation, you will obtain the affine expressions

$$x'=ax+by+cz+d,\\y'=ex+fy+gz+h$$ and finally the equation of the cylinder has the form $$(ax+by+cz+d')^2+(ex+fy+gz+h')=r^2.$$

There is no benefit in expanding this expression in terms of the angles, no simplification will occur.

$\endgroup$
  • $\begingroup$ Thank you for replying. The parameters I describe above are the fitting parameters that the python script returns. I want to convert the expression as described in the paper mentioned in the docstring of the python script (which uses the parameters described in my explanation) to the cartesian equation of the cylinder. I agree with what you are saying but I'm not sure how this is an answer to my original question. $\endgroup$ – KrisH May 11 at 22:13
  • $\begingroup$ @KrisH: this answer gives the implicit equation of a cylindre described by the parameters $x_c,y_c,r,\alpha,\beta$ (though I didn't explicit the rotation matrix). I even specified the rotation center, which was missing in the question. I am answering what you ask: "How can I now determine the cartesian equation of this cylinder?" You modified your question later. $\endgroup$ – Yves Daoust May 12 at 17:47
  • $\begingroup$ Alright sorry for my misunderstanding. And thank you for taking your time to answer. $\endgroup$ – KrisH May 12 at 20:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.