We are still processing your video. It will be automatically posted when finished.

Eric O. answered 07/18/21
B.S. Mechanical Engineering with 5+ years MATLAB Tutoring Experience

Video Attached!
close all
clear all
clc
%Get User Input and Make curve
SplineCP = input('How many control points would you like to use: ');
x = [];
y = [];
SplineDisplay = input('would you like to display the points(Y,N): ','s');
for n = 1:SplineCP
Xprompt = horzcat('X', num2str(n), ': ');
x(end+1) = input(Xprompt);
Yprompt = horzcat('Y', num2str(n), ': ');
y(end+1) = input(Yprompt);
if SplineDisplay == 'Y'
close all
scatter(x,y);
end
end
qx = input('How many Query Points would you like to create: ');
xx = linspace(min(x), max(x), qx);
yy = spline(x,y,xx);
if SplineDisplay == 'Y'
close all
plot(x,y,'o',xx,yy)
end
AlignAxis = input('Which Axis do you want your vase along(X,Y,Z): ','s');
ExtrudeDist = input('How long would you like to extrude the top: ');
%Create 3D Geometry
[X,Y,Z] = cylinder(yy);
%Scale Z
Z = Z * max(x);
%Make Bottom
X = vertcat(0*X(1,:), X);
Y = vertcat(0*Y(1,:), Y);
Z = vertcat(0*Z(1,:), Z);
%Extrude Top
X = vertcat(X, X(end,:));
Y = vertcat(Y, Y(end,:));
Z = vertcat(Z, Z(end,:) + ExtrudeDist);
%Rotate Vase
Z2XTransform = [...
0,0,1;
0,1,0;
-1,0,0];
Z2YTransform = [...
1,0,0;
0,0,1;
0,-1,0];
%Z2ZTransform = [...
% 1,0,0;
% 0,1,0;
% 0,0,1];
RandRotMat = (2*rand(3))-1;
%RandRotMat = quat2rotm(randrot());
for n = 1:size(X,1)
for m = 1:size(X,2)
P = [...
X(n,m);
Y(n,m);
Z(n,m)];
if AlignAxis == 'X'
P = Z2XTransform*P;
elseif AlignAxis == 'Y'
P = Z2YTransform*P;
elseif AlignAxis == 'Z'
else
P = RandRotMat * P;
end
X(n,m) = P(1);
Y(n,m) = P(2);
Z(n,m) = P(3);
end
end
%Graphics
Ax1 = axes();
VaseSurface = surf(X,Y,Z);
VaseSurface.EdgeColor = 'none';
axis equal
axis vis3d
Ax1.Color = 'none';
Ax1.AmbientLightColor = '#4DBEEE';
%Texturing
TextureFN = input('What is the Texture File Name: ','s');
TilesX = input('Num X Tiles: ');
TilesY = input('Num Y Tiles: ');
if isempty(TextureFN)
load clown
TextureRaw = ind2rgb(X,map);
else
TextureRaw = imread(TextureFN);
end
TextureScaled = TextureRaw;
if TilesX > 1
for n = 2:TilesX
TextureScaled = horzcat(TextureScaled, TextureRaw);
end
end
TextureRaw = TextureScaled;
if TilesY > 1
for n = 2:TilesY
TextureScaled = vertcat(TextureScaled, TextureRaw);
end
end
VaseSurface.FaceColor = 'texturemap';
VaseSurface.CData = TextureRaw;
VaseSurface.CData = flipud(TextureScaled);