You are on page 1of 8

% --- Executes on button press in btnRefleksi.

function btnRefleksi_Callback(hObject, eventdata, handles)


% hObject handle to btnRefleksi (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% REFLEKSI
b=10;
set(handles.txtx1,'Visible','on');
set(handles.txty1,'Visible','on');
set(handles.txtHasilRefleksi,'Visible','on');
indeks2=get(handles.popupmenu2,'Value');
switch indeks2
case 2
% REFLEKSI thd TITIK (0,0)
indeks1=get(handles.popupmenu1,'Value');
switch indeks1
case 2
% REFLEKSI thd titik (0,0) --> untuk TITIK
xA=str2double(get(handles.ExA, 'String'));
yA=str2double(get(handles.EyA, 'String'));
T=[-1 0; 0 -1]; X=[xA; yA];
X1=T*X;txA= X1(1);tyA= X1(2);
%txA= -xA; tyA= -yA;

minx=min([xA txA]);
miny=min([yA tyA]);
maxx=max([xA txA]);
maxy=max([yA tyA]);

% Menyesuaikan sumbu-x
if minx>-b && maxx<b
minxx=-b; maxxx=b;
else
if maxx>=b
maxxx=maxx+2;
z=maxx+2-2*b;
z=min([z minx]);
if z <= 0
minxx=z-2;
else
minxx=-1;
end;
else
if minx<=-b
minxx=minx-2;
z=minx-2+2*b;
z=max([z maxx]);
if z >=0
maxxx=z+2;
else
maxxx=1;
end;
end;
end;
end;
% Menyesuaikan sumbu-y
if miny>-b && maxy<b
minyy=-b; maxyy=b;
else
if maxy>=b
maxyy=maxy+2;
z=maxy+2-2*b;
z=min([z miny]);
if z <= 0
minyy=z-2;
else
minyy=-1;
end;
else
if miny<=-b
minyy=miny-2;
z=miny-2+2*b;
z=max([z maxy]);
if z >=0
maxyy=z+2;
else
maxyy=1;
end;
end;
end;
end;

xx=minxx:0.1:maxxx; xy=0.*xx; %xx dan xy untuk sumbu


x
yy=minyy:0.1:maxyy; yx=0.*yy; %yx dan yy untuk sumbu
y

%Membuat Garis (xA,yA), (txA,tyA) dan cek grs


vertikal/horisontal
if xA==txA % jika garisnya vertikal
tyg1=min([yA tyA]):0.1:max([yA tyA]);
n=length(tyg1);
txg1=ones(1,n);
txg1=txg1*xA;
else
if yA==tyA % jika garisnya horisontal
txg1=min([xA txA]):0.1:max([xA txA]);
n=length(txg1);
tyg1=ones(1,n);
tyg1=tyg1*yA;
else
if xA<txA
txg1=xA:0.1:txA;
else
txg1=txA:0.1:xA;
end;
tyg1=yA+(tyA-yA)*(txg1-xA)/(txA-xA);
end;
end;

set(handles.ExA1,'Visible','on');
set(handles.EyA1,'Visible','on');
set(handles.ExA1, 'String', num2str(txA));
set(handles.EyA1, 'String', num2str(tyA));

plot(xA,yA,'r*',txA,tyA,'b*',xx,xy,'k',
yx,yy,'k',txg1,tyg1,'g-.',0,0,'ro');
axis([minxx maxxx minyy maxyy]);grid;%range gambar
%Memberi text titik nol
a1=abs(maxxx-minxx)/200;b1=abs(maxyy-minyy)/50;
text(a1,-b1,'0');
xA=xA+a1;yA=yA-b1;xA1=txA+a1;yA1=tyA-b1;
text(xA,yA,'A');text(xA1,yA1,'A1');
xP=a1;yP=b1;text(xP,yP,'P');

case 3
% REFLEKSI thd titik (0,0) --> untuk GARIS
xA=str2double(get(handles.ExA, 'String'));
yA=str2double(get(handles.EyA, 'String'));
xB=str2double(get(handles.ExB, 'String'));
yB=str2double(get(handles.EyB, 'String'));

T=[-1 0; 0 -1]; XA=[xA; yA];XB=[xB; yB];


XA1=T*XA;txA= XA1(1);tyA= XA1(2);
XB1=T*XB;txB= XB1(1);tyB= XB1(2);

%txA= -xA; tyA= -yA;


%txB= -xB; tyB= -yB;

minx=min([xA xB txA txB]);


maxx=max([xA xB txA txB]);
miny=min([yA yB tyA tyB]);
maxy=max([yA yB tyA tyB]);

% Menyesuaikan sumbu-x
if minx>-b && maxx<b
minxx=-b; maxxx=b;
else
if maxx>=b
maxxx=maxx+2;
z=maxx+2-2*b;
z=min([z minx]);
if z <= 0
minxx=z-2;
else
minxx=-1;
end;
else
if minx<=-b
minxx=minx-2;
z=minx-2+2*b;
z=max([z maxx]);
if z >=0
maxxx=z+2;
else
maxxx=1;
end;
end;
end;
end;

% Menyesuaikan sumbu-y
if miny>-b && maxy<b
minyy=-b; maxyy=b;
else
if maxy>=b
maxyy=maxy+2;
z=maxy+2-2*b;
z=min([z miny]);
if z <= 0
minyy=z-2;
else
minyy=-1;
end;
else
if miny<=-b
minyy=miny-2;
z=miny-2+2*b;
z=max([z maxy]);
if z >=0
maxyy=z+2;
else
maxyy=1;
end;
end;
end;
end;
xx=minxx:0.1:maxxx; xy=0.*xx; %xx dan xy untuk sumbu
x
yy=minyy:0.1:maxyy; yx=0.*yy; %yx dan yy untuk sumbu
y

%Membuat Garis (xA,yA), (txA,tyA) dan cek grs


vertikal/horisontal
if xA==txA % jika garisnya vertikal
tyg1=min([yA tyA]):0.1:max([yA tyA]);
n=length(tyg1);
txg1=ones(1,n);
txg1=txg1*xA;
else
if yA==tyA % jika garisnya horisontal
txg1=min([xA txA]):0.1:max([xA txA]);
n=length(txg1);
tyg1=ones(1,n);
tyg1=tyg1*yA;
else
if xA<txA
txg1=xA:0.1:txA;
else
txg1=txA:0.1:xA;
end;
tyg1=yA+(tyA-yA)*(txg1-xA)/(txA-xA);
end;
end;

%Membuat Garis (xB,yB), (txB,tyB) dan cek grs


vertikal/horisontal
if xB==txB % jika garisnya vertikal
tyg2=min([yB tyB]):0.1:max([yB tyB]);
n=length(tyg2);
txg2=ones(1,n);
txg2=txg2*xB;
else
if yB==tyB % jika garisnya horisontal
txg2=min([xA txA]):0.1:max([xA txA]);
n=length(txg2);
tyg2=ones(1,n);
tyg2=tyg2*yB;
else
if xB<txB
txg2=xB:0.1:txB;
else
txg2=txB:0.1:xB;
end;
tyg2=yB+(tyB-yB)*(txg2-xB)/(txB-xB);
end;
end;

%Membuat Garis (xA,yA), (xB,yB) dan cek grs


vertikal/horisontal
if xA==xB % jika garisnya vertikal
yg12=min([yA yB]):0.1:max([yA yB]);
n=length(yg12);
xg12=ones(1,n);
xg12=xg12*xA;
else
if yA==yB % jika garisnya horisontal
xg12=min([xA xB]):0.1:max([xA xB]);
n=length(xg12);
yg12=ones(1,n);
yg12=yg12*yA;
else
if xA<xB
xg12=xA:0.1:xB;
else
xg12=xB:0.1:xA;
end;
yg12=yA+(yB-yA)*(xg12-xA)/(xB-xA);
end;
end;

%Membuat Garis (txA,tyA), (txB,tyB) dan cek grs


vertikal/horisontal
if txA==txB % jika garisnya vertikal
tyg12=min([tyA tyB]):0.1:max([tyA tyB]);
n=length(tyg12);
txg12=ones(1,n);
txg12=txg12*txA;
else
if tyA==tyB % jika garisnya horisontal
txg12=min([txA txB]):0.1:max([txA txB]);
n=length(txg12);
tyg12=ones(1,n);
tyg12=tyg12*tyA;
else
if txA<txB
txg12=txA:0.1:txB;
else
txg12=txB:0.1:txA;
end;
tyg12=tyA+(tyB-tyA)*(txg12-txA)/(txB-txA);
end;
end;

set(handles.ExA1,'Visible','on');
set(handles.EyA1,'Visible','on');
set(handles.ExA1, 'String', num2str(txA));
set(handles.EyA1, 'String', num2str(tyA));
set(handles.ExB1,'Visible','on');
set(handles.EyB1,'Visible','on');
set(handles.ExB1, 'String', num2str(txB));
set(handles.EyB1, 'String', num2str(tyB));

plot(xA,yA,'r*',xB,yB,'r*',txA,tyA,'b*',txB,tyB,'b*',xx,xy,'k',
yx,yy,'k',xg12,yg12,'b',txg1,tyg1,'g-.',txg2,tyg2,'g-
.',txg12,tyg12,'r',0,0,'ro' );
axis([minxx maxxx minyy maxyy]);grid;%range gambar
%Memberi text titik nol
a1=abs(maxxx-minxx)/200;b1=abs(maxyy-minyy)/50;
text(a1,-b1,'0');
xA=xA+a1;yA=yA-b1;xA1=txA+a1;yA1=tyA-b1;
xB=xB+a1;yB=yB-b1;xB1=txB+a1;yB1=tyB-b1;
text(xA,yA,'A');text(xA1,yA1,'A1');
text(xB,yB,'B');text(xB1,yB1,'B1');
xP=a1;yP=b1;text(xP,yP,'P');

case 4
% REFLEKSI thd titik (0,0) --> untuk SEGITIGA
xA=str2double(get(handles.ExA, 'String'));
yA=str2double(get(handles.EyA, 'String'));
xB=str2double(get(handles.ExB, 'String'));
yB=str2double(get(handles.EyB, 'String'));
xC=str2double(get(handles.ExC, 'String'));
yC=str2double(get(handles.EyC, 'String'));
% dst

case 5
% REFLEKSI thd titik (0,0) --> untuk SEGIEMPAT
xA=str2double(get(handles.ExA, 'String'));
yA=str2double(get(handles.EyA, 'String'));
xB=str2double(get(handles.ExB, 'String'));
yB=str2double(get(handles.EyB, 'String'));
xC=str2double(get(handles.ExC, 'String'));
yC=str2double(get(handles.EyC, 'String'));
xD=str2double(get(handles.ExD, 'String'));
yD=str2double(get(handles.EyD, 'String'));
%dst
end;
case 3
% REFLEKSI thd TITIK P(a,b)
indeks1=get(handles.popupmenu1,'Value');
switch indeks1
case 2

case 3

case 4

case 5

end;
case 4
% REFLEKSI thd sumbu-x
indeks1=get(handles.popupmenu1,'Value');
switch indeks1
case 2

case 3

case 4

case 5

end;
case 5
% REFLEKSI thd sumbu-x
indeks1=get(handles.popupmenu1,'Value');
switch indeks1
case 2

case 3

case 4

case 5

end;
case 6
% REFLEKSI thd sumbu-x
indeks1=get(handles.popupmenu1,'Value');
switch indeks1
case 2

case 3

case 4
case 5

end;
case 7

case 8

case 9

case 10

case 11

end;

You might also like