Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear
- clc
- close all
- importedBody = stlread("octodents.stl"); %cg should be at 0,0,0
- global iterationNumber
- iterationNumber = 130;
- %steps = iterationNumber*2;
- angle = 0;
- xRotation = 0;
- yRotation = 0;
- zRotation = 0;
- for shapeDist = 1:iterationNumber
- radius = computeRadius(shapeDist);
- z = computeZ(radius);
- currentSize = computeSize(shapeDist);
- %position of centerpoint of shape
- angle = angle + 137.5077640500378546463487;
- pos(shapeDist,1) = cosd(angle)*radius;
- pos(shapeDist,2) = sind(angle)*radius;
- pos(shapeDist,3) = z;
- %points of the shape being imported
- shapePos = importedBody.Points*currentSize*.8;
- shapePos = rotz(shapePos,-angle); %rotate for position
- %rotate shape
- xRotation = xRotation + 2; %2
- yRotation = yRotation + 4.5; %5
- zRotation = zRotation + 1.2; %1
- shapePos = rotx(shapePos,xRotation);
- shapePos = roty(shapePos,xRotation);
- shapePos = rotz(shapePos,zRotation);
- %shift by center position
- shapePos(:,1) = shapePos(:,1) + pos(shapeDist,1);
- shapePos(:,2) = shapePos(:,2) + pos(shapeDist,2);
- shapePos(:,3) = shapePos(:,3) + pos(shapeDist,3);
- tr = triangulation(importedBody.ConnectivityList,shapePos);
- name = strcat('G:\My Drive\MATLAB\Bloom\Output\out',num2str(shapeDist),'.stl');
- stlwrite(tr,name);
- end
- scatter3(pos(:,1),pos(:,2),pos(:,3))
- axis equal
- function out = computeSize(iteration)
- global iterationNumber
- out = .6*(1/iterationNumber)*iteration^1.4 + .8;
- end
- function out = computeRadius(iteration)
- global iterationNumber
- out = 6*(1/iterationNumber)*iteration;
- end
- function out = computeZ(radius)
- out = -.5*(radius-2)^2 + 4;
- end
- function out = rotx(input,angleX)
- out = input*[1 0 0; 0 cosd(angleX) -sind(angleX) ; 0 sind(angleX) cosd(angleX)] ;
- end
- function out = roty(input,angleY)
- out = input*[cosd(angleY) 0 sind(angleY) ; 0 1 0 ; -sind(angleY) 0 cosd(angleY)] ;
- end
- function out = rotz(input,angleZ)
- out = input*[cosd(angleZ) -sind(angleZ) 0 ; sind(angleZ) cosd(angleZ) 0 ; 0 0 1] ;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement