Find Axis in Mesh

Help me please. I want to define the axis of the mesh. For example I have a cylinder (mesh) I click on the cylinder wall, and the program builds a straight line, the axis of the cylinder.

There is nothing automatic that will let you do that.
You can turn on the points of the mesh and extract the ones at the edges of the cylinder walls. Then select the points of one of the caps and run the Circle command with the Fitpoints option. That will create a best-fit circle around the end of the cylinder. Do the same at the other end (unless the cylinder is aligned with one of the world axes) and make a center axis through the centers of both circles.

If I understand correctly, the sequence is as follows:

But I would like to write a script for Rninoсeros. I saw in the third-party plug-ins, it’s possible.

Sorry, your method all happened. I want to automate this process or to write the script or make a plug-in in visual studio. You could do a clue. Help me please.

I’m changing the category to scripting and hope that one of the scripters can help you.

Using PCA you can do that, if you sample your curves/objects into points, then calculate covariance matrix the principal eigenvector is the axis (more or less, depends on the sampling). Something like:

points = sample_objects(object)
center = center_of_mass(points)
covmat = [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]

for point in points:
    x = center[0] - point[0]
    y = center[1] - point[1]
    z = center[2] - point[2]

    covmat[0][0] += x * x
    covmat[1][1] += y * y
    covmat[2][2] += z * z
    xy = x * y
    covmat[0][1] += xy
    covmat[1][0] += xy
    xz = x * z
    covmat[0][2] += xz
    covmat[2][0] += xz
    yz = y * z
    covmat[1][2] += yz
    covmat[2][1] += yz

principal_axis = eigenvector(covmat, 3)

you can use a simple power method to calculate the eigenvector for the matrix. Hope this helps!


Thank direction asked. I’ll do it. On the results I will tell later.