Circle fit in pointcloud, stl

17 views (last 30 days)
Patrick Brandt
Patrick Brandt on 28 Jun 2021
Answered: Matt J on 23 May 2024
Hi,
for a project I need to fit a circle in an pointcloud in a certain hight of a 3d stl-plot. I already get the circle of the whole thing but not in the height i need to know it (-263,6365).
stlData=stlread("24Lcav.stl");
X=stlData.Points;
x=X(:,1);
y=X(:,2);
z=X(:,3);
x=x(:); y=y(:);
a=[x y ones(size(x))]\[-(x.^2+y.^2)];
xc = -.5*a(1);
yc = -.5*a(2);
R = sqrt((a(1)^2+a(2)^2)/4-a(3))
When I set x=x(-263,6365) matlab sais it has to be positiv.
I hope you can help me.

Answers (2)

Pratyush
Pratyush on 23 May 2024
Hi Patrick,
To fit a circle to a subset of points from a 3D point cloud at a specific height (-263.6365) in MATLAB, follow these steps:
  • Load your 3D point cloud data from an STL file using `stlread`.
  • Extract the x, y, and z coordinates from the point cloud data.
  • Specify the desired height (z-coordinate) where you want to fit the circle. Set a tolerance level to account for the precision of your data and ensure you capture points around this height.
  • Use logical indexing to filter out points that fall within the specified height range, considering the tolerance. This creates a subset of points at the desired height.
  • Apply circle fitting to the filtered subset of points. This involves solving a linear system to find the circle's center (`xc`, `yc`) and radius (`R`) that best fits the points at the specified height.
  • The output will be the center coordinates and radius of the circle fitted to the points around the specified height.
This method involves filtering the 3D point cloud to focus on a horizontal slice at a certain height, then applying a circle fitting algorithm to the points within that slice. Adjust the tolerance as needed based on the precision and distribution of your data.

Matt J
Matt J on 23 May 2024
See the section "Fitting a 2D Shape to 3D Points" in the Examples tab of this FEX submission:

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!