[Closed] Fitting cylinder to vertex selection
Hey everyone!
I need to make script what fits cylinder to selected vertices and cylinder need to be fitted as optimal as possible. So it is not that easy than just scale cylinder over vertices :). Cylinder needs to be correctly rotated as well :(. There is my problem. How to calculate cylinder orientation and size than it fit perfectly as possible over selected vertices?
Here is little image to clear up. Dots are vertices and square is cylinder.
I think here’s the concept
find the two longest vectors in the dataset, these two vectors will form the plane of the length of the cylinder.
rotate the the points by the normal vector of the plane. Next find the longest distance of the projected plane to form the diameter.
I have to dive back to the maxscript manual to write this.
I might be wrong, but I think there is an infinite number of solutions to this problem. See the attached image.
- Martijn
A brute force method would be to find the outlying points, find the lines between each vertex pair (this will cause some redundant checks though :shrug:), go through all the remaining points and do a distance of point from line function and find the best length/radius ratio for your needs.