Advertisement
Guest User

Zeotrope Generator

a guest
Aug 13th, 2023
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.09 KB | None | 0 0
  1. clear
  2. clc
  3. close all
  4.  
  5. importedBody = stlread("octodents.stl"); %cg should be at 0,0,0
  6.  
  7. global iterationNumber
  8. iterationNumber = 130;
  9. %steps = iterationNumber*2;
  10. angle = 0;
  11. xRotation = 0;
  12. yRotation = 0;
  13. zRotation = 0;
  14.  
  15.  
  16. for shapeDist = 1:iterationNumber
  17.  
  18.     radius = computeRadius(shapeDist);
  19.     z = computeZ(radius);
  20.     currentSize = computeSize(shapeDist);
  21.  
  22.     %position of centerpoint of shape
  23.     angle = angle + 137.5077640500378546463487;
  24.     pos(shapeDist,1) = cosd(angle)*radius;
  25.     pos(shapeDist,2) = sind(angle)*radius;
  26.     pos(shapeDist,3) = z;
  27.  
  28.     %points of the shape being imported
  29.     shapePos = importedBody.Points*currentSize*.8;
  30.     shapePos = rotz(shapePos,-angle); %rotate for position
  31.  
  32.     %rotate shape
  33.     xRotation = xRotation + 2; %2
  34.     yRotation = yRotation + 4.5; %5
  35.     zRotation = zRotation + 1.2; %1
  36.     shapePos = rotx(shapePos,xRotation);
  37.     shapePos = roty(shapePos,xRotation);
  38.     shapePos = rotz(shapePos,zRotation);
  39.  
  40.     %shift by center position
  41.     shapePos(:,1) = shapePos(:,1) + pos(shapeDist,1);
  42.     shapePos(:,2) = shapePos(:,2) + pos(shapeDist,2);
  43.     shapePos(:,3) = shapePos(:,3) + pos(shapeDist,3);
  44.    
  45.     tr = triangulation(importedBody.ConnectivityList,shapePos);
  46.     name = strcat('G:\My Drive\MATLAB\Bloom\Output\out',num2str(shapeDist),'.stl');
  47.     stlwrite(tr,name);
  48. end
  49.  
  50. scatter3(pos(:,1),pos(:,2),pos(:,3))
  51. axis equal
  52.  
  53.  
  54. function out = computeSize(iteration)
  55. global iterationNumber
  56.     out = .6*(1/iterationNumber)*iteration^1.4 + .8;
  57. end
  58.  
  59. function out = computeRadius(iteration)
  60. global iterationNumber
  61.     out = 6*(1/iterationNumber)*iteration;
  62.    
  63. end
  64.  
  65. function out = computeZ(radius)
  66.     out = -.5*(radius-2)^2 + 4;
  67. end
  68.  
  69. function out = rotx(input,angleX)
  70.     out = input*[1 0 0; 0 cosd(angleX) -sind(angleX) ; 0 sind(angleX) cosd(angleX)] ;
  71. end
  72.  
  73. function out = roty(input,angleY)
  74.     out = input*[cosd(angleY) 0 sind(angleY) ; 0 1 0 ; -sind(angleY) 0  cosd(angleY)] ;
  75. end
  76.  
  77. function out = rotz(input,angleZ)
  78.     out = input*[cosd(angleZ) -sind(angleZ) 0 ; sind(angleZ) cosd(angleZ) 0 ; 0 0 1] ;
  79. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement