Advertisement
Guest User

Julia Vase Generator

a guest
Sep 18th, 2020
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 3.55 KB | None | 0 0
  1. %Filip Jander  8/24/2019
  2. %Exports stl from parametric equation, use a program called Meshmixer to
  3. %clean up the stl file for 3d printing. Recommended functions in meshmixer:
  4. %Reduce, Erase and Fill, Smooth and Make Solid
  5.  
  6. clear
  7. clc
  8. pointDensity = 100;
  9. outputArray = zeros(pointDensity);
  10. iterations = 100;
  11.  
  12. maxT = 200;
  13. threeDoutput = NaN(pointDensity^2*maxT,3);
  14. % (t/maxT) + sin((t/maxT)*2*pi)/10)
  15. for t = 0:maxT
  16.     clearvars -except pointDensity iterations maxT threeDoutput t
  17.     juliaPoint = 0.32*(sin((t/maxT)*2*pi)) + .3*(cos((t/maxT)*2*pi)-1)*1i;
  18.     juliaPointPlot(t+1) = juliaPoint;
  19.     for m = 1:pointDensity
  20.         for n = 1:pointDensity
  21.             k = 0;
  22.             x = m/((pointDensity-1)/4)-2-4/pointDensity;
  23.             y = n/((pointDensity-1)/4)-2-4/pointDensity;
  24.             point =  x + y*1i;
  25.             zn = point;
  26.            
  27.             while k < iterations
  28.                 if sqrt(real(zn)^2+ imag(zn)^2) > 2
  29.                     k = iterations + 1;
  30.                 else
  31.                     k = k + 1;
  32.                     zn = zn^2 + juliaPoint;
  33.                 end
  34.             end
  35.             if k == iterations + 1
  36.                 outputArray(m,n) = 1;
  37.             end
  38.         end
  39.     end
  40.     clear plotArray count
  41.     count = 1;
  42.     for n = 1:size(outputArray,1)
  43.         for m = 1:size(outputArray,2)
  44.             if outputArray(n,m) == 0
  45.                 %if t ~= 1 && t ~= maxT
  46.                    
  47.                 if 1==1
  48.                     if outputArray(n+1,m) == 1 || outputArray(n-1,m) == 1 || outputArray(n,m+1) == 1 || outputArray(n,m-1) == 1
  49.                         plotArray(count,1) = m;
  50.                         plotArray(count,2) = n;
  51.                         count = count + 1;
  52.                     end
  53.                 else
  54.                     plotArray(count,1) = m;
  55.                     plotArray(count,2) = n;
  56.                     count = count + 1;
  57.                 end
  58.             end
  59.         end
  60.     end
  61.     scatter(plotArray(:,1),plotArray(:,2),10,"filled")
  62.     axis equal
  63.     pause(0.005)
  64.    
  65.     threeDoutput((t+1)*pointDensity^2:(t+1)*pointDensity^2-1+size(plotArray,1),1:2) = plotArray;
  66.     threeDoutput((t+1)*pointDensity^2:(t+1)*pointDensity^2-1+size(plotArray,1),end) = (t+1);
  67. end
  68.  
  69. count = 0;
  70. for n = 1:size(threeDoutput)
  71.     if ~isnan(threeDoutput(n,1))
  72.         count = count + 1;
  73.     end
  74. end
  75. threeDoutput2 = zeros(count,3);
  76. count = 1;
  77. for n = 1:size(threeDoutput)
  78.     if ~isnan(threeDoutput(n,1))
  79.         threeDoutput2(count,:) = threeDoutput(n,:);
  80.         count = count +1;
  81.     end
  82. end
  83.  
  84. threeDoutput2(:,3) = threeDoutput2(:,3)/2.5;
  85. plot(juliaPointPlot);
  86. scatter3(threeDoutput2(:,1),threeDoutput2(:,2),threeDoutput2(:,3),1,"filled")
  87. axis equal
  88. %
  89. % out = [threeDoutput2(:,1),threeDoutput2(:,2),threeDoutput2(:,3)];
  90. % save xyzfile.xyz out -ascii
  91.  
  92. % k = boundary(threeDoutput2,.8);
  93. % hold on
  94. % trisurf(k,threeDoutput2(:,1),threeDoutput2(:,2),threeDoutput2(:,3),'Facecolor','red','FaceAlpha',0.1)
  95. % axis equal
  96.  
  97. % xSize = max(threeDoutput2(:,1))+1;
  98. % ySize = max(threeDoutput2(:,2))+1;
  99. % zSize = max(threeDoutput2(:,3))+1;
  100. % threeDoutputLogical = false(xSize,ySize,zSize);
  101. % for n = 1:size(threeDoutput2,1)
  102. %     threeDoutputLogical(round(threeDoutput2(n,1))+1,round(threeDoutput2(n,2))+1,round(threeDoutput2(n,3))+1) = 1;
  103. %     %round(threeDoutput2(n+1,1)),round(threeDoutput2(n+1,2)),round(threeDoutput2(n+1,3))
  104. % end
  105. % fv = isosurface(~threeDoutputLogical, 0.5); % Make patch w. faces "out"
  106. % nfv = reducepatch(fv,.25);
  107. % stlwrite('test5.stl',nfv) % Save to binary .stl
  108.  
  109.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement