Rotation of a Box
clc
clear
A(1:2,1)= [0 0];
A(1:2,2)= [0 1];
A(1:2,3)= [1 0];
A(1:2,4)= [1 1];
Angle=40;
for i=1:4;
x(i)=A(1,i);
y(i)=A(2,i);
end
theta=Angle*(pi/180)
T=[cos(theta) -sin(theta); sin(theta) cos(theta)];
for i=1:4;
AA(1:2,i)=T*A(1:2,i);
xx(i)=AA(1,i);
yy(i)=AA(2,i);
end
v1=[x(1) x(2)];
v2=[y(1) y(2)];
v3=[x(2) x(4)];
v4=[y(2) y(4)];
v5=[x(3) x(4)];
v6=[y(3) y(4)];
v7=[x(1) x(3)];
v8=[y(1) y(3)];
f1=line(v1,v2);
f2=line(v3,v4);
f3=line(v5,v6);
f4=line(v7,v8);
hold on
plot(x,y,'r*')
vv1=[xx(1) xx(2)];
vv2=[yy(1) yy(2)];
vv3=[xx(2) xx(4)];
vv4=[yy(2) yy(4)];
vv5=[xx(3) xx(4)];
vv6=[yy(3) yy(4)];
vv7=[xx(1) xx(3)];
vv8=[yy(1) yy(3)];
ff1=line(vv1,vv2);
ff2=line(vv3,vv4);
ff3=line(vv5,vv6);
ff4=line(vv7,vv8);
plot(xx,yy,'r*')
grid on
axis equal
title('Rotation of a Box')
xlabel('x')
ylabel('y')
clear
A(1:2,1)= [0 0];
A(1:2,2)= [0 1];
A(1:2,3)= [1 0];
A(1:2,4)= [1 1];
Angle=40;
for i=1:4;
x(i)=A(1,i);
y(i)=A(2,i);
end
theta=Angle*(pi/180)
T=[cos(theta) -sin(theta); sin(theta) cos(theta)];
for i=1:4;
AA(1:2,i)=T*A(1:2,i);
xx(i)=AA(1,i);
yy(i)=AA(2,i);
end
v1=[x(1) x(2)];
v2=[y(1) y(2)];
v3=[x(2) x(4)];
v4=[y(2) y(4)];
v5=[x(3) x(4)];
v6=[y(3) y(4)];
v7=[x(1) x(3)];
v8=[y(1) y(3)];
f1=line(v1,v2);
f2=line(v3,v4);
f3=line(v5,v6);
f4=line(v7,v8);
hold on
plot(x,y,'r*')
vv1=[xx(1) xx(2)];
vv2=[yy(1) yy(2)];
vv3=[xx(2) xx(4)];
vv4=[yy(2) yy(4)];
vv5=[xx(3) xx(4)];
vv6=[yy(3) yy(4)];
vv7=[xx(1) xx(3)];
vv8=[yy(1) yy(3)];
ff1=line(vv1,vv2);
ff2=line(vv3,vv4);
ff3=line(vv5,vv6);
ff4=line(vv7,vv8);
plot(xx,yy,'r*')
grid on
axis equal
title('Rotation of a Box')
xlabel('x')
ylabel('y')
Rotation of a Triangle
clc
clear
A(1:2,1)= [1 1];
A(1:2,2)= [2 5];
A(1:2,3)= [3 1];
Angle=120;
for i=1:3;
x(i)=A(1,i);
y(i)=A(2,i);
end
theta=Angle*(pi/180);
T=[cos(theta) -sin(theta); sin(theta) cos(theta)];
for i=1:3;
AA(1:2,i)=T*A(1:2,i);
xx(i)=AA(1,i);
yy(i)=AA(2,i);
end
v1=[x(1) x(2)];
v2=[y(1) y(2)];
v3=[x(2) x(3)];
v4=[y(2) y(3)];
v7=[x(1) x(3)];
v8=[y(1) y(3)];
f1=line(v1,v2);
f2=line(v3,v4);
f4=line(v7,v8);
hold on
plot(x,y,'r*')
vv1=[xx(1) xx(2)];
vv2=[yy(1) yy(2)];
vv3=[xx(2) xx(3)];
vv4=[yy(2) yy(3)];
vv7=[xx(1) xx(3)];
vv8=[yy(1) yy(3)];
ff1=line(vv1,vv2);
ff2=line(vv3,vv4);
ff4=line(vv7,vv8);
plot(xx,yy,'r*')
grid on
axis equal
title('Rotation of a Triangle')
xlabel('x')
ylabel('y')
clear
A(1:2,1)= [1 1];
A(1:2,2)= [2 5];
A(1:2,3)= [3 1];
Angle=120;
for i=1:3;
x(i)=A(1,i);
y(i)=A(2,i);
end
theta=Angle*(pi/180);
T=[cos(theta) -sin(theta); sin(theta) cos(theta)];
for i=1:3;
AA(1:2,i)=T*A(1:2,i);
xx(i)=AA(1,i);
yy(i)=AA(2,i);
end
v1=[x(1) x(2)];
v2=[y(1) y(2)];
v3=[x(2) x(3)];
v4=[y(2) y(3)];
v7=[x(1) x(3)];
v8=[y(1) y(3)];
f1=line(v1,v2);
f2=line(v3,v4);
f4=line(v7,v8);
hold on
plot(x,y,'r*')
vv1=[xx(1) xx(2)];
vv2=[yy(1) yy(2)];
vv3=[xx(2) xx(3)];
vv4=[yy(2) yy(3)];
vv7=[xx(1) xx(3)];
vv8=[yy(1) yy(3)];
ff1=line(vv1,vv2);
ff2=line(vv3,vv4);
ff4=line(vv7,vv8);
plot(xx,yy,'r*')
grid on
axis equal
title('Rotation of a Triangle')
xlabel('x')
ylabel('y')
Rotation of a Line
clc
clear
A(1:2,1)= [-1 4];
A(1:2,2)= [3 1];
Angle=120;
for i=1:2;
x(i)=A(1,i);
y(i)=A(2,i);
end
theta=Angle*(pi/180);
T=[cos(theta) -sin(theta); sin(theta) cos(theta)];
for i=1:2;
AA(1:2,i)=T*A(1:2,i);
xx(i)=AA(1,i);
yy(i)=AA(2,i);
end
v1=[x(1) x(2)];
v2=[y(1) y(2)];
f1=line(v1,v2);
hold on
plot(x,y,'r*')
vv1=[xx(1) xx(2)];
vv2=[yy(1) yy(2)];
ff1=line(vv1,vv2);
plot(xx,yy,'r*')
grid on
axis equal
title('Rotation of a Line')
xlabel('x')
ylabel('y')
clear
A(1:2,1)= [-1 4];
A(1:2,2)= [3 1];
Angle=120;
for i=1:2;
x(i)=A(1,i);
y(i)=A(2,i);
end
theta=Angle*(pi/180);
T=[cos(theta) -sin(theta); sin(theta) cos(theta)];
for i=1:2;
AA(1:2,i)=T*A(1:2,i);
xx(i)=AA(1,i);
yy(i)=AA(2,i);
end
v1=[x(1) x(2)];
v2=[y(1) y(2)];
f1=line(v1,v2);
hold on
plot(x,y,'r*')
vv1=[xx(1) xx(2)];
vv2=[yy(1) yy(2)];
ff1=line(vv1,vv2);
plot(xx,yy,'r*')
grid on
axis equal
title('Rotation of a Line')
xlabel('x')
ylabel('y')
Rotation of a Surface Around the x Axis
clc
clear
M=20;
x0=-3;
xx=3;
dx=(xx-x0)/M;
y0=-3;
yy=3;
dy=(yy-y0)/M;
q=0;
for i=1:M;
for j=1:M;
for k=1:1;
q=q+1;
X(i,j,k)=i*dx+x0;
Y(i,j,k)=j*dy+y0;
Z(i,j,k)=X(i,j,k)^2-Y(i,j,k)^2;
vector(1:5,q)= [X(i,j,k) Y(i,j,k) Z(i,j,k) 1 q];
end
end
end
surf(X,Y,Z)
Angle=60;
theta=Angle*(pi/180);
T=[1 0 0 ; 0 cos(theta) -sin(theta) ; 0 sin(theta) cos(theta)];
for i=1:q;
AA(1:3,i)=T*vector(1:3,i);
end
q=0;
for i=1:M;
for j=1:M;
for k=1:1;
q=q+1;
XX(i,j,k)=AA(1,q);
YY(i,j,k)=AA(2,q);
ZZ(i,j,k)=AA(3,q);
end
end
end
hold on
surf(XX,YY,ZZ)
axis equal
xlabel('x axis')
ylabel('y axis')
zlabel('z axis')
clear
M=20;
x0=-3;
xx=3;
dx=(xx-x0)/M;
y0=-3;
yy=3;
dy=(yy-y0)/M;
q=0;
for i=1:M;
for j=1:M;
for k=1:1;
q=q+1;
X(i,j,k)=i*dx+x0;
Y(i,j,k)=j*dy+y0;
Z(i,j,k)=X(i,j,k)^2-Y(i,j,k)^2;
vector(1:5,q)= [X(i,j,k) Y(i,j,k) Z(i,j,k) 1 q];
end
end
end
surf(X,Y,Z)
Angle=60;
theta=Angle*(pi/180);
T=[1 0 0 ; 0 cos(theta) -sin(theta) ; 0 sin(theta) cos(theta)];
for i=1:q;
AA(1:3,i)=T*vector(1:3,i);
end
q=0;
for i=1:M;
for j=1:M;
for k=1:1;
q=q+1;
XX(i,j,k)=AA(1,q);
YY(i,j,k)=AA(2,q);
ZZ(i,j,k)=AA(3,q);
end
end
end
hold on
surf(XX,YY,ZZ)
axis equal
xlabel('x axis')
ylabel('y axis')
zlabel('z axis')
Unless otherwise noted, all content on this site is @Copyright by Ahmed Al Makky 2012-2013 - http://cfd2012.com