2019IMG-031 CG Assignment

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

CG LAB ASSIGNMENT-4

Kshitiz Dhooria
2019IMG-031
Assume:
A ≡ (2 , 1 , 1) B ≡ (4 , 1 , 1)
C ≡ (4 , 2 , 1) D ≡ (2 , 2 , 1) and P ≡ (2 , 0 , 1)

Solution-1

Code-
x=[2,4,4,2,2]
y=[1,1,2,2,1]
z=[1,1,1,1,1]
Xp=2
Yp=0
Zp=1
Sx=2
Sy=2
Sz=2
Xs=Sx*(x-Xp)+Xp
Ys=Sy*(y-Yp)+Yp
Zs=Sz*(z-Zp)+Zp
plot3(x,y,z)
hold on
plot3(Xs,Ys,Zs)
scatter3(Xp,Yp,Zp)
xlabel('x')
ylabel('y')
zlabel('z')
grid on
axis on
box off

OUTPUT:-

Final Points
A ≡ (2 , 2 , 1) B ≡ (4 , 2 , 1)
C ≡ (6 , 4 , 1) D ≡ (2 , 4 , 1)
Solution-2

Code-
x=[2,4,4,2,2]
y=[1,1,2,2,1]
z=[1,1,1,1,1]
function [m,n,p] = rotation(x1,y1,z1,x2,y2,z2,t,xi,yi,zi)
x=xi-x1
y=yi-y1
z=zi-z1
a=asin((y2-y1)/((x2-x1)^2+(y2-y1)^2+(z2-z1)^2)^(1/2))
x3=x
y3=y.*cosd(a)-z.*sind(a)
z3=y.*sind(a)+z.*cosd(a)
b=asin((x2-x1)/((x2-x1)^2+(y2-y1)^2+(z2-z1)^2)^(1/2))
x4=z3.*sind(b)+x3.*cosd(b)
y4=y3
z4=z3.*cosd(b)-x3.*sind(b)
x5=x4.*cosd(t)-y4.*sind(t)
y5=x4.*sind(t)+y4.*cosd(t)
z5=z4
x6=z5.*sind(-b)+x5.*cosd(-b)
y6=y5
z6=z5.*cosd(-b)-x5.*sind(-b)
x7=x6
y7=y6.*cosd(-a)-z.*sind(-a)
z7=y6.*sin(-a)+z.*cosd(-a)
m=x7+x1
n=y7+y1 p=z7+z1
endfunction
[m,n,p]=rotation(2,0,1,4,1,4,45,x,y,z)
plot3(x,y,z)
hold on
plot3(m,n,p)
plot3([2,4],[0,1],[1,4]) %plotting line of rotation xlabel('x')
ylabel('y')
zlabel('z')
grid on
axis on
box off

OUTPUT:-
Final Points

A ≡ (1.29 , 0.70 , 0.81) B ≡ (2.70 , 2.12 , 0.43)


C ≡ (2.00 , 2.82 , 0.24) D ≡ (0.58 , 1.41 , 0.62)

You might also like