MATLAB Spherical Coordiantes
clc
clear
A = meshgrid(linspace(0, 2*pi, 51), linspace(0, 2*pi, 51));
X = cos(A);
Y = sin(A);
for i=-25:25
R(i+26) = 5*cos(asin(i/25));
end
for i=1:51
for j=1:51
X(j,i) = X(j,i) * R(j);
Y(j,i) = Y(j,i) * R(j);
end
end
Z = meshgrid(linspace(-5, 5, 51), linspace(-5, 5, 51))';
surf(X, Y, Z);
axis equal
axis([-5 5 -5 5 -10 10])
clear
A = meshgrid(linspace(0, 2*pi, 51), linspace(0, 2*pi, 51));
X = cos(A);
Y = sin(A);
for i=-25:25
R(i+26) = 5*cos(asin(i/25));
end
for i=1:51
for j=1:51
X(j,i) = X(j,i) * R(j);
Y(j,i) = Y(j,i) * R(j);
end
end
Z = meshgrid(linspace(-5, 5, 51), linspace(-5, 5, 51))';
surf(X, Y, Z);
axis equal
axis([-5 5 -5 5 -10 10])
Calculating Center of Gravity for Mushroom Shape
clc
clear
A = meshgrid(linspace(0, 2*pi, 51), linspace(0, 2*pi, 51));
X = cos(A);
Y = sin(A);
for i=-25:25
R(i+26) = 5*cos(asin(i/25));
end
for i=1:51
for j=1:25
X(j,i) = X(j,i) * R(j);
Y(j,i) = Y(j,i) * R(j);
end
end
Z = meshgrid(linspace(-5, 5, 51), linspace(-5, 5, 51))';
surf(X, Y, Z);
t1=size(X(:))
t2=size(Y(:))
t3=size(Z(:))
xc=sum(X(:))/t1(1)
yc=sum(Y(:))/t2(1)
zc=sum(Z(:))/t3(1)
axis equal
axis([-5 5 -5 5 -10 10])
clear
A = meshgrid(linspace(0, 2*pi, 51), linspace(0, 2*pi, 51));
X = cos(A);
Y = sin(A);
for i=-25:25
R(i+26) = 5*cos(asin(i/25));
end
for i=1:51
for j=1:25
X(j,i) = X(j,i) * R(j);
Y(j,i) = Y(j,i) * R(j);
end
end
Z = meshgrid(linspace(-5, 5, 51), linspace(-5, 5, 51))';
surf(X, Y, Z);
t1=size(X(:))
t2=size(Y(:))
t3=size(Z(:))
xc=sum(X(:))/t1(1)
yc=sum(Y(:))/t2(1)
zc=sum(Z(:))/t3(1)
axis equal
axis([-5 5 -5 5 -10 10])
MATLAB Rotation of Sphere
clc
clear
fi0=0;
fi1=360;
R=1;
R0=0;
R1=1;
M=30;
dfi=(fi1-fi0)/M;
dR=(R1-R0)/M;
fi=[fi0:dfi:fi1];
aa=pi/180;
theta0=0;
theta1=360;
dtheta=(theta1-theta0)/M;
theta=[theta0:dtheta:theta1];
t=0;
tt=-1;
for j=1:M/2+1
tt=tt+1;
t=tt;
for i=1:M+1
t=t+1;
b(t)=t;
x(i)=R*sin(aa*fi(i))*cos(aa*theta(j));
y(i)=R*sin(aa*fi(i))*sin(aa*theta(j));
z(i)=R*cos(aa*fi(i));
%pause
v(1:6,b(t))=[ x(i) y(i) z(i) fi(i) theta(j) b(t)];
end
plot3(x,y,z)
axis equal
grid on
hold on
end
t=0;
tt=-1;
for j=1:M/2+1
tt=tt+1;
t=tt;
for i=1:M+1
t=t+1;
bb(t)=t;
xx(i)=R*sin(aa*fi(j))*cos(aa*theta(i));
yy(i)=R*sin(aa*fi(j))*sin(aa*theta(i));
zz(i)=R*cos(aa*fi(j));
%pause
ang=45;
RR = rotx(ang);
vv = [xx(i);yy(i);zz(i)];
%pause
yyy = RR*vv;
vvv(1:6,bb(t))=[ yyy(1) yyy(2) yyy(3) fi(j) theta(i) bb(t)];
plot3(xx,yy,zz)
plot3(vvv(1,bb(t)),vvv(2,bb(t)),vvv(3,bb(t)),'r*')
axis equal
grid on
hold on
end
end
clear
fi0=0;
fi1=360;
R=1;
R0=0;
R1=1;
M=30;
dfi=(fi1-fi0)/M;
dR=(R1-R0)/M;
fi=[fi0:dfi:fi1];
aa=pi/180;
theta0=0;
theta1=360;
dtheta=(theta1-theta0)/M;
theta=[theta0:dtheta:theta1];
t=0;
tt=-1;
for j=1:M/2+1
tt=tt+1;
t=tt;
for i=1:M+1
t=t+1;
b(t)=t;
x(i)=R*sin(aa*fi(i))*cos(aa*theta(j));
y(i)=R*sin(aa*fi(i))*sin(aa*theta(j));
z(i)=R*cos(aa*fi(i));
%pause
v(1:6,b(t))=[ x(i) y(i) z(i) fi(i) theta(j) b(t)];
end
plot3(x,y,z)
axis equal
grid on
hold on
end
t=0;
tt=-1;
for j=1:M/2+1
tt=tt+1;
t=tt;
for i=1:M+1
t=t+1;
bb(t)=t;
xx(i)=R*sin(aa*fi(j))*cos(aa*theta(i));
yy(i)=R*sin(aa*fi(j))*sin(aa*theta(i));
zz(i)=R*cos(aa*fi(j));
%pause
ang=45;
RR = rotx(ang);
vv = [xx(i);yy(i);zz(i)];
%pause
yyy = RR*vv;
vvv(1:6,bb(t))=[ yyy(1) yyy(2) yyy(3) fi(j) theta(i) bb(t)];
plot3(xx,yy,zz)
plot3(vvv(1,bb(t)),vvv(2,bb(t)),vvv(3,bb(t)),'r*')
axis equal
grid on
hold on
end
end
Unless otherwise noted, all content on this site is @Copyright by Ahmed Al Makky 2012-2015 - http://cfd2012.com