Create a g-torus

Viewed 66

I'm looking for an easy, elegant way to create a triangle mesh of a torus with an arbitrary number of holes. Here are some examples.


First, the AI had a problem with the question title, then a human decided "Closed. This question needs to be more focused."

Anyway, here is one direction:

% sphere
%fun = @(x, y, z) x.^2 + y.^2 + z.^2 - 1;

% 3-torus
% http://metamathological.blogspot.com/2013/01/today-i-learned-how-to-plot-doughnut.html
fun = @(x, y, z) (x.^2 + (y - 2).^2 - 1) .* ((x - sqrt(3)).^2 + (y + 1).^2 - 1) .* ((x + sqrt(3)).^2 + (y + 1).^2 - 1) - 0.0015*(x.^2 + y.^2 + 7*z.^2).^5;

% 4-torus
%fun = @(x, y, z) ((x - 2).^2 + (y - 2).^2 - 1) .* ((x - 2).^2 + (y + 2).^2 - 1) .* ((x + 2).^2 + (y - 2).^2 - 1) .* ((x + 2).^2 + (y + 2).^2 - 1) - 0.02*(x.^2 + y.^2 + 7*z.^2).^5;

res = 0.1;
r = 8;
x = -r:res:r;
y = -r:res:r;
z = -r:res:r;
[X, Y, Z] = meshgrid(x, y, z);
V = fun(X,Y,Z); % volumetric function (e.g. distance function)
I = isosurface(x ,y , z, V, 0); % extract level set as a mesh

p = patch(I);
isonormals(X, Y, Z, V, p);
p.FaceColor = 'red';
p.EdgeColor = 'none';
daspect([1 1 1])
view(3); 
axis tight;
camlight;
lighting gouraud;
0 Answers
Related