MATLAB Box Translation
clc
clear
A(1:3,1)= [0 0 1];
A(1:3,2)= [0 1 1];
A(1:3,3)= [1 0 1];
A(1:3,4)= [1 1 1];
for i=1:4;
x(i)=A(1,i);
y(i)=A(2,i);
end
X_translation=2;
Y_translation=2;
a=X_translation;
b=Y_translation;
T=[1 0 a; 0 1 b; 0 0 1];
for i=1:4;
AA(1:3,i)=T*A(1:3,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('Translation of a Box')
xlabel('x')
ylabel('y')
clear
A(1:3,1)= [0 0 1];
A(1:3,2)= [0 1 1];
A(1:3,3)= [1 0 1];
A(1:3,4)= [1 1 1];
for i=1:4;
x(i)=A(1,i);
y(i)=A(2,i);
end
X_translation=2;
Y_translation=2;
a=X_translation;
b=Y_translation;
T=[1 0 a; 0 1 b; 0 0 1];
for i=1:4;
AA(1:3,i)=T*A(1:3,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('Translation of a Box')
xlabel('x')
ylabel('y')
Transition of a 3D Surface
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)
X_translation=15;
Y_translation=15;
Z_translation=15;
a=X_translation;
b=Y_translation;
c=Z_translation;
T=[1 0 0 a; 0 1 0 b; 0 0 1 c; 0 0 0 1 ];
for i=1:q;
AA(1:4,i)=T*vector(1:4,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)
X_translation=15;
Y_translation=15;
Z_translation=15;
a=X_translation;
b=Y_translation;
c=Z_translation;
T=[1 0 0 a; 0 1 0 b; 0 0 1 c; 0 0 0 1 ];
for i=1:q;
AA(1:4,i)=T*vector(1:4,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')
Recommended website link for the studied case: http://en.wikipedia.org/wiki/Translation_%28geometry%29
Unless otherwise noted, all content on this site is @Copyright by Ahmed Al Makky 2012-2013 - http://cfd2012.com