أخر الاخبار

Exercises matlab program for drawing

 Exercises  matlab program for drawing


ex/1.

Clips the polygon showing in figure against each edge of the Clipping window (left, top, bottom and right) using Sutherland Algorithm. Suppose the polygon is [a, b, c, d, e, f, g, h,]. Then find the coordinates of the intersection points.



 sol//





 

 


ex/translate the same object seven units horizontally to right and four units vertically down.

sol//

close all

 clear all

 clc

 a=[15 10 1; 20 10 1; 20 20 1; 15 20 1; 15 10 1];

 plot(a(:,1),a(:,2)) 

hold on

 t=[1 0 0; 0 1 0; 7 -4 1];

 b= a*t;

 plot(b(:,1),b(:,2),'r') 

axis([5 30 0 30])

 grid on 


Example :- write a matlab program to maximizing an object A(2, 6), B(6,6), (6,9), and D(2,9), using scaling factor = 2.5 and the fixed point is A (2, 6).

sol//

obj=[2 6 1;6 6 1;6 9 1;2 9 1;2 6 1]; 

plot(obj(:,1),obj(:,2),'k')

 tra=[1 0 0;0 1 0;-2 -6 1];

 scale=[2.5 0 0;0 2.5 0;0 0 1]; 

trai=[1 0 0;0 1 0;2 6 1];

 obj1=obj*tra*scale*trai;

 hold on  

plot(obj1(:,1),obj1(:,2),'k'); 

axis([0 15 0 15])


Example // write a matlab program to maximizing the same object a(2,6) , b(6,6), c(6,9), d(2,9) using scaling factor = 2.5 and minimizing the same object using scaling factor = 0.4. Note the fixed point is(2,6).

sol//

obj=[2 6 1;6 6 1;6 9 1;2 9 1;2 6 1];

 plot(obj(:,1),obj(:,2),'b') 

tra=[1 0 0;0 1 0;-2 -6 1]; 

scale=[2.5 0 0;0 2.5 0;0 0 1]; 

trai=[1 0 0;0 1 0;2 6 1]; 

obj1=obj*tra*scale*trai; 

hold on

 plot(obj1(:,1),obj1(:,2),'k'); 

scale2=[0.4 0 0;0 0.4 0;0 0 1];

 obj2=obj*tra*scale2*trai; 

plot(obj2(:,1),obj2(:,2),'k'); 

axis([0 15 0 15]) 


Example // write a program to reflect the object about x = y.

sol//

x1=[0 10];

 y1=[0 10]; 

obj=[3 1 1;6 1 1;6 4 1;3 1 1]; 

ref=[0 1 0; 1 0 0; 0 0 1]; 

obj1=obj*ref; 

plot(obj(:,1),obj(:,2),'b');

 hold on 

plot(obj1(:,1),obj1(:,2),'r'); 

plot(x1,y1,'k'); 

grid on;

 axis([0 10 0 10]);


Example // write a matlab program to reflect the object (2,4), (4,6), (2,6) about the line (3,2) - (6,6).

sol//

obj=[2 4 1; 4 6 1; 2 6 1; 2 4 1]; 

tra=[1 0 0; 0 1 0; -3 -2 1]; 

rot=[cos(-26) sin(-26) 0;-sin(-26) cos(-26) 0;0 0 1]

 ref=[1 0 0; 0 -1 0; 0 0 1]

 roti=[cos(26) sin(26) 0;-sin(26) cos(26) 0;0 0 1]

 trai=[1 0 0; 0 1 0; 3 2 1]; 

obj1=obj*tra*rot*ref*roti*trai 

plot (obj(:,1),obj(:,2)) 

hold on

 plot ([3,6],[2,6]) 

plot (obj1(:,1),obj1(:,2)) 

axis([0 10 0 10]);

 grid on 

axis square;  



Example// write a matlab program to get the following figure. (Using transformation techniques) ( assume its 4 trangles)

sol//

obj=[13 13 1;17 13 1;15 15 1;13 13 1]; 

plot(obj(:,1),obj(:,2),'b')

 tra=[1 0 0;0 1 0;-4 0 1]; 

obj1=obj*tra ;

 hold on

 plot(obj1(:,1),obj1(:,2),'k'); 

tra=[1 0 0;0 1 0;-13 -13 1];

 rot=[cos(90) sin(90) 0;-sin(90) cos(90) 0;0 0 1];

 trai=[1 0 0;0 1 0; 13 13 1];

 obj2=obj1*tra*rot*trai 

plot(obj2(:,1),obj2(:,2),'k'); 

tra=[1 0 0;0 1 0;0 -4 1]; 

obj3=obj1*tra 

plot(obj3(:,1),obj3(:,2),'k');

 tra=[1 0 0;0 1 0;-13 -9 1]; 

rot=[cos(-135)sin(-135)0;-sin(-135) cos(-135) 0;0 0 1];

 trai=[1 0 0;0 1 0;13 9 1]; 

obj4=obj3*tra*rot*trai 

plot(obj4(:,1),obj4(:,2),'k'); 

 tra=[1 0 0;0 1 0;4 0 1]; 

obj5=obj*tra; 

plot(obj5(:,1),obj5(:,2),'k'); 

tra=[1 0 0;0 1 0;-17 -13 1]; 

rot=[cos(-90) sin(-90) 0;-sin(-90) cos(-90) 0;0 0 1];

 trai=[1 0 0;0 1 0;17 13 1]; obj6=obj5*tra*rot*trai; 

plot(obj6(:,1),obj6(:,2),'k')

 grid on; 

axis([0 20 0 20])



Example// write a matlab program to get the following figure. (Using transformation techniques)


 sol//

obj=[4 10 1; 5 10 1;5 9 1; 7 9 1;7 10 1;8 10 1;6 11 1;4 10 1]; 

plot(obj(:,1),obj(:,2),'k')

 tra=[1 0 0;0 1 0;-7 -9 1]

 rot=[cos(-45) sin(-45) 0;-sin(-45) cos(-45) 0;0 0 1] 

trai=[1 0 0;0 1 0;7 9 1] obj1=obj*tra*rot*trai 

hold on 

 plot(obj1(:,1),obj1(:,2),'k') 

tra=[1 0 0;0 1 0;2 -2.5 1] 

obj2=obj1*tra plot(obj2(:,1),obj2(:,2),'k')

 %%%%%%%%%%%%%%%%%%%%% 

tra=[1 0 0;0 1 0;-5 -9 1]

 rot=[cos(45) sin(45) 0;-sin(45) cos(45) 0;0 0 1] 

trai=[1 0 0;0 1 0;5 9 1] 

obj3=obj*tra*rot*trai 

 plot(obj3(:,1),obj3(:,2),'k') 

tra=[1 0 0;0 1 0;-2 -2.5 1] 

obj4=obj3*tra 

plot(obj4(:,1),obj4(:,2),'k') 

%%%%%%%%%%%%%%%%%%%%%%

 tra=[1 0 0 ;0 1 0;0 -6 1]; 

ref=[1 0 0;0 -1 0;0 0 1] 

 trai=[1 0 0 ;0 1 0;0 6 1];

 obj5=obj*tra*ref*trai 

plot(obj5(:,1),obj5(:,2),'k') 

%%%%%%%%%%%%%%%%%%%%%%%%% 

ref=[1 0 0;0 -1 0;0 0 1] 

obj6=obj2*tra*ref*trai 

plot(obj6(:,1),obj6(:,2),'k') 

%%%%%%%%%%%%%%%%%%%%%%%%%

 ref=[1 0 0;0 -1 0;0 0 1]

 obj7=obj4*tra*ref*trai 

plot(obj7(:,1),obj7(:,2),'k') 

grid on 

axis([0 12 0 12])

Example // write a matlab program to get the following figure using transformation

techniques. Assume the object coordinates are A(5,5), B(5,8), and C(7,5).

sol//

obj=[5 5 1;5 8 1;7 5 1;5 5 1];

plot(obj(:,1),obj(:,2),'k')

tra=[1 0 0;0 1 0;0.25 0.25 1];

obj2= obj*tra

hold on

plot(obj2(:,1),obj2(:,2),'k');

tra=[1 0 0;0 1 0;0.5 0.5 1];

obj3= obj*tra

plot(obj3(:,1),obj3(:,2),'k');

tra=[1 0 0;0 1 0;-5 0 1];

ref=[-1 0 0;0 1 0;0 0 1];

trai=[1 0 0;0 1 0;5 0 1];

obj1= obj*tra*ref*trai

plot(obj1(:,1),obj1(:,2),'k');

%%%%%%%%%%%%%%%%%%%%%%%%%

tra=[1 0 0;0 1 0;-0.25 0.25 1];

obj2= obj1*tra

plot(obj2(:,1),obj2(:,2),'k');

tra=[1 0 0;0 1 0;-0.5 0.5 1];

obj3= obj1*tra

(obj3(:,1),obj3(:,2),'k');

axis([0 10 0 10])

axis square

تعليقات



حجم الخط
+
16
-
تباعد السطور
+
2
-