Skip to content

Instantly share code, notes, and snippets.

@OrganicIrradiation
Created March 23, 2015 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OrganicIrradiation/f8bde9e0520d35defbc4 to your computer and use it in GitHub Desktop.
Save OrganicIrradiation/f8bde9e0520d35defbc4 to your computer and use it in GitHub Desktop.
3D “Potato” Generation using Sinusoidal Pertubations
nRecurse = 0;
FV = sphere_tri('ico',nRecurse,[],0);
lighting phong;
shading interp;
figure;
patch('vertices', FV.vertices,'faces', FV.faces, 'facecolor', [0.5 0.5 0.5], 'edgecolor', [.2 .2 .2]);
axis square;
axis off;
camlight infinite;
camproj('orthographic');
figure;
amplitude = 0.15;
for angle = 0:pi/4:3/4*pi
for frequency = 1:3:10
newShape = FV;
% Rotate around x-axis
a=cos(angle) * frequency;
b=sin(angle) * frequency;
newShape.vertices(:,1) = newShape.vertices(:,1) + sin(a*newShape.vertices(:,2) + b*newShape.vertices(:,3)) * amplitude;
subplot(4,4,(angle+pi/4)/(pi/4)+((frequency+2)-3)/3*4)
lighting phong;
shading interp;
patch('vertices', newShape.vertices, 'faces', newShape.faces, 'facecolor', [0.5 0.5 0.5], 'edgealpha', 0);
axis equal;
axis off;
camlight infinite;
camproj('orthographic');
end
end
figure;
amplitude = 0.15;
for angle = 0:pi/4:3/4*pi
for frequency = 1:3:10
newShape = FV;
% Rotate around x-axis
a=cos(angle) * frequency;
b=sin(angle) * frequency;
newShape.vertices(:,2) = newShape.vertices(:,2) + sin(a*newShape.vertices(:,1) + b*newShape.vertices(:,3)) * amplitude;
subplot(4,4,(angle+pi/4)/(pi/4)+((frequency+2)-3)/3*4)
lighting phong;
shading interp;
patch('vertices', newShape.vertices, 'faces', newShape.faces, 'facecolor', [0.5 0.5 0.5], 'edgealpha', 0);
axis equal;
axis off;
camlight infinite;
camproj('orthographic');
end
end
figure;
amplitude = 0.15;
for angle = 0:pi/4:3/4*pi
for frequency = 1:3:10
newShape = FV;
% Rotate around x-axis
a=cos(angle) * frequency;
b=sin(angle) * frequency;
newShape.vertices(:,3) = newShape.vertices(:,3) + sin(a*newShape.vertices(:,1) + b*newShape.vertices(:,2)) * amplitude;
subplot(4,4,(angle+pi/4)/(pi/4)+((frequency+2)-3)/3*4)
lighting phong;
shading interp;
patch('vertices',newShape.vertices,'faces',newShape.faces,...
'facecolor',[0.5 0.5 0.5],'edgealpha',0);
axis equal;
axis off;
camlight infinite;
camproj('orthographic');
end
end
% X-axis:
newShape.vertices(:,1) = newShape.vertices(:,1) + sin(a*newShape.vertices(:,2) + b*newShape.vertices(:,3)) * amplitude;
% Y-axis:
newShape.vertices(:,2) = newShape.vertices(:,2) + sin(a*newShape.vertices(:,1) + b*newShape.vertices(:,3)) * amplitude;
% Z-axis:
newShape.vertices(:,3) = newShape.vertices(:,3) + sin(a*newShape.vertices(:,1) + b*newShape.vertices(:,2)) * amplitude;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment