Triangle centroid
조회 수: 8 (최근 30일)
이전 댓글 표시
Hello, do you somebody know any simlpe method how to find the triangle centroid (or geometric barycenter) in 3D?
Thanks a lot,
Tom
댓글 수: 1
Zhenren Yang
2016년 5월 9일
이동: DGM
2025년 6월 30일
hi, have you get the code that can find the barycenter of 3d (stl,ply)?
채택된 답변
Jonathan Sullivan
2012년 3월 20일
Just average all the coordinates. For example, if you have a vector containing x coordinates and a vector containing y coordinates, you can find it in the following manner.
x = rand(3,1); % x-coordinate
y = rand(3,1); % y-coordinate
x_centroid = mean(x);
y_centroid = mean(y);
추가 답변 (1개)
DGM
2025년 6월 30일
편집: DGM
2025년 7월 16일
Another example for emphasis:
unzip stepholecube.stl.zip % for the forum
% so you have some triangles in 3D
T = stlread('stepholecube.stl');
[F V] = t2fv(T); % just for cleanliness
% then get the centroids. you're done
C = mean(permute(reshape(V(F,:),[size(F,1) 3 3]),[1 3 2]),3);
% not sure if that's right?
% well, the barycenter is at [1 1 1]/3 in barycentric coordinates, so ...
idx = (1:size(T,1)).';
Cref = barycentricToCartesian(T,idx,ones(numel(idx),3)/3);
immse(C,Cref) % they're the same.
Now, would this example have worked in 2012? The calculation of the centroid would work fine, though some of the other tools are anachronistic. That said, you don't actually need them to take the mean. If we were living in 2012, the same demo could still be written:
% so you have some triangles in 3D
[F V] = stlread('stepholecube.stl'); % FEX #22409 (NOT the same function!)
% then get the centroids. you're done
C = mean(permute(reshape(V(F,:),[size(F,1) 3 3]),[1 3 2]),3);
% not sure if that's right?
% well, the barycenter is at [1 1 1]/3 in barycentric coordinates, so ...
T = TriRep(F,V);
idx = (1:size(T,1)).';
Cref = baryToCart(T,idx,ones(numel(idx),3)/3);
mean((C(:) - Cref(:)).^2) % they're the same.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Polynomials에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!