How to get rid off additional triangles on cut sphere with delaunayTriangulation.

3 views (last 30 days)
Hi,
I have problem with triangulation. I make cut sphere and triangulation for collision check, but i have problem with additional triangles made on "back" of flat surface. It's important for me to get rid of it because I am trying to simulate mirror (including concave mirror) and it's a major obstacle for me.
function obj = ConvexMirror(x, y, z, r, angle, n)
...
% some irrelevant code
...
[obj.x, obj.y, obj.z] = sphere(n);
obj.x = obj.x(ceil(2/3 * n):end,:); % here is cutting sphere
obj.y = obj.y(ceil(2/3 * n):end,:);
obj.z = obj.z(ceil(2/3 * n):end,:);
obj.r = r;
obj.s = surf(r.*obj.x + x,r.*obj.y + y,r.*obj.z + z, ...
'FaceColor', [0.5 0.5 0.5]);
obj = obj.triangulate();
end
function obj = triangulate(obj)
DT = delaunayTriangulation(obj.s.XData(:), ...
obj.s.YData(:), ...
obj.s.ZData(:));
[obj.faces, obj.vertices] = freeBoundary(DT); % i guess here are made additional triangles
obj.tris = trisurf(obj.faces, ...
obj.vertices(:,1), ...
obj.vertices(:,2), ...
obj.vertices(:,3), ...
'FaceAlpha', 1);
obj.vert1 = obj.vertices(obj.faces(:,1),:);
obj.vert2 = obj.vertices(obj.faces(:,2),:);
obj.vert3 = obj.vertices(obj.faces(:,3),:);
faceCenter = (obj.vert1+obj.vert2+obj.vert3)/3;
faceNormal = cross(obj.vert2-obj.vert1, ...
obj.vert3-obj.vert1,2);
obj.q = quiver3(faceCenter(:,1), ...
faceCenter(:,2), ...
faceCenter(:,3),...
faceNormal(:,1), ...
faceNormal(:,2), ...
faceNormal(:,3), 10, ...
'Visible', 'off');
...
% some irrevelant code
...
end
I've tried to delete first/last 19 faces, but it's not it.
Thanks for help!

Accepted Answer

Mateusz Szmyd
Mateusz Szmyd on 22 Jan 2022
Instead of using delaunay easier is to:
[x,y,z] = sphere;
s = surf(x,y,z);
patch(surf2patch(s,'triangles'))

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!