Anda di halaman 1dari 39

ase 10

% REFLEKSI thd y = ax + b
indeks1=get(handles.popupmenu1,'Value');
switch indeks1
case 2
% REFLEKSI thd y = ax + b --> untuk TITIK
xA=str2double(get(handles.ExA, 'String'));
yA=str2double(get(handles.EyA, 'String'));
xpA= (aa*(yA-bb)+xA)/(aa^2+1);
ypA=(yA*aa^2+xA*aa+bb)/(aa^2+1);
txA= 2*xpA-xA; tyA=2*ypA-yA ;
sk=atan(kx);
T=[cos(2*sk) sin(2*sk); sin(2*sk) -cos(2*sk)]; X=[xA;
yA]; K=[0; kb];
X1=T*(X-K)+K;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;

xsmbr=-1000:0.1:1000;
ky=kx*xsmbr+kb;

set(handles.tx1,'Visible','on');
set(handles.ty1,'Visible','on');
set(handles.thasil,'Visible','on');
set(handles.ta1,'Visible','on');
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-.',xsmbr,ky,'b-.');
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');
text(1,1,'y = ax + b');

case 3
% REFLEKSI thd y=ax+b --> untuk GARIS
kx=str2double(get(handles.eagaris,'String'));
kb=str2double(get(handles.ebgaris,'String'));
xA=str2double(get(handles.ExA,'String'));
yA=str2double(get(handles.EyA,'String'));
xB=str2double(get(handles.ExB,'String'));
yB=str2double(get(handles.EyB,'String'));

sk=atan(kx);
T=[cos(2*sk) sin(2*sk); sin(2*sk) -cos(2*sk)];
XA=[xA; yA]; XB=[xB; yB]; K=[0; kb];
XA1=T*(XA-K)+K;txA= XA1(1);tyA= XA1(2);
XB1=T*(XB-K)+K;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([xB txB]):0.1:max([xB txB]);
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;

xsmbr=-1000:0.1:1000;
ky=kx*xsmbr+kb;

set(handles.tx1,'Visible','on');
set(handles.ty1,'Visible','on');
set(handles.thasil,'Visible','on');
set(handles.ta1,'Visible','on');
set(handles.tb1,'Visible','on');
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',xsmbr,ky,'b-.');
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');
text(1,1,'y= ax + b');

case 4
% REFLEKSI thd y=ax+b --> untuk SEGITIGA
kx=str2double(get(handles.eagaris,'String'));
kb=str2double(get(handles.ebgaris,'String'));
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'));
sk=atan(kx);
T=[cos(2*sk) sin(2*sk); sin(2*sk) -cos(2*sk)];
XA=[xA; yA]; XB=[xB; yB]; XC=[xC; yC]; K=[0; kb];
XA1=T*(XA-K)+K;txA= XA1(1);tyA= XA1(2);
XB1=T*(XB-K)+K;txB= XB1(1);tyB= XB1(2);
XC1=T*(XC-K)+K;txC= XC1(1);tyC= XC1(2);

%txA= -xA; tyA= -yA;


%txB= -xB; tyB= -yB;
%txC= -xC; tyC= -yC;

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


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

% 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 (xC,yC), (txC,tyC) dan cek grs vertikal/horisontal


if xC==txC % jika garisnya vertikal
tyg3=min([yC tyC]):0.1:max([yC tyC]);
n=length(tyg2);
txg3=ones(1,n);
txg3=txg3*xC;
else
if yC==tyC % jika garisnya horisontal
txg3=min([xA txA]):0.1:max([xA txA]);
n=length(txg3);
tyg3=ones(1,n);
tyg3=tyg3*yC;
else
if xC<txC
txg3=xC:0.1:txC;
else
txg3=txC:0.1:xC;
end;
tyg3=yC+(tyC-yC)*(txg3-xC)/(txC-xC);
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;

%Membuat Garis (xB,yB), (xC,yC) dan cek grs vertikal/horisontal


if xB==xC % jika garisnya vertikal
yg23=min([yB yC]):0.1:max([yB yC]);
n=length(yg23);
xg23=ones(1,n);
xg23=xg23*xB;
else
if yB==yC % jika garisnya horisontal
xg23=min([xB xC]):0.1:max([xB xC]);
n=length(xg23);
yg23=ones(1,n);
yg23=yg23*yB;
else
if xB<xC
xg23=xB:0.1:xC;
else
xg23=xC:0.1:xB;
end;
yg23=yB+(yC-yB)*(xg23-xB)/(xC-xB);
end;
end;

%Membuat Garis (txB,tyB), (txC,tyC) dan cek grs vertikal/horisontal


if txB==txC % jika garisnya vertikal
tyg23=min([tyB tyC]):0.1:max([tyB tyC]);
n=length(tyg23);
txg23=ones(1,n);
txg23=txg23*txB;
else
if tyB==tyC % jika garisnya horisontal
txg23=min([txB txC]):0.1:max([txB txC]);
n=length(txg23);
tyg23=ones(1,n);
tyg23=tyg23*tyB;
else
if txB<txC
txg23=txB:0.1:txC;
else
txg23=txC:0.1:txB;
end;
tyg23=tyB+(tyC-tyB)*(txg23-txB)/(txC-txB);
end;
end;

%Membuat Garis (xC,yC), (xA,yA) dan cek grs vertikal/horisontal


if xC==xA % jika garisnya vertikal
yg31=min([yC yA]):0.1:max([yC yA]);
n=length(yg31);
xg31=ones(1,n);
xg31=xg31*xC;
else
if yC==yA % jika garisnya horisontal
xg31=min([xC xA]):0.1:max([xC xA]);
n=length(xg31);
yg31=ones(1,n);
yg31=yg31*yC;
else
if xC<xA
xg31=xC:0.1:xA;
else
xg31=xA:0.1:xC;
end;
yg31=yC+(yA-yC)*(xg31-xC)/(xA-xC);
end;
end;

%Membuat Garis (txC,tyC), (txA,tyA) dan cek grs vertikal/horisontal


if txC==txA % jika garisnya vertikal
tyg31=min([tyC tyA]):0.1:max([tyC tyA]);
n=length(tyg31);
txg31=ones(1,n);
txg31=txg31*txC;
else
if tyC==tyA % jika garisnya horisontal
txg31=min([txC txA]):0.1:max([txC txA]);
n=length(txg31);
tyg31=ones(1,n);
tyg31=tyg31*tyC;
else
if txC<txA
txg31=txC:0.1:txA;
else
txg31=txA:0.1:txC;
end;
tyg31=tyC+(tyA-tyC)*(txg31-txC)/(txA-txC);
end;
end;

xsmbr=-1000:0.1:1000;
ky=kx*xsmbr+kb;

set(handles.tx1,'Visible','on');
set(handles.ty1,'Visible','on');
set(handles.thasil,'Visible','on');
set(handles.ta1,'Visible','on');
set(handles.tb1,'Visible','on');
set(handles.tc1,'Visible','on');
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));
set(handles.exc1,'Visible','on');
set(handles.eyc1,'Visible','on');
set(handles.exc1, 'String', num2str(txC));
set(handles.eyc1, 'String', num2str(tyC));

plot(xA,yA,'r*',xB,yB,'r*',xC,yC,'r*',txA,tyA,'b*',txB,tyB,'b*',txC,tyC,'b*',
xx,xy,'k', yx,yy,'k',xg12,yg12,'b',xg23,yg23,'b',xg31,yg31,'b',txg1,tyg1,'g-
.',txg2,tyg2,'g-.',txg3,tyg3,'g-
.',txg12,tyg12,'r',txg23,tyg23,'r',txg31,tyg31,'r',xsmbr,ky,'b-.');
axis([minxx maxxx minyy maxyy]);grid;%range gambar
%Memberi text titik y=ax+b
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;
xC=xC+a1;yC=yC-b1;xC1=txC+a1;yC1=tyC-b1;
text(xA,yA,'A');text(xA1,yA1,'A1');
text(xB,yB,'B');text(xB1,yB1,'B1');
text(xC,yC,'C');text(xC1,yC1,'C1');
text(1,1,'y= ax + b');
case 5
% REFLEKSI thd y = ax+b --> untuk SEGIEMPAT
kx=str2double(get(handles.eagaris,'String'));
kb=str2double(get(handles.ebgaris,'String'));
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'));

sk=atan(kx);
T=[cos(2*sk) sin(2*sk); sin(2*sk) -cos(2*sk)];
XA=[xA; yA]; XB=[xB; yB]; XC=[xC; yC]; XD=[xD; yD]; K=[0; kb];
XA1=T*(XA-K)+K;txA= XA1(1);tyA= XA1(2);
XB1=T*(XB-K)+K;txB= XB1(1);tyB= XB1(2);
XC1=T*(XC-K)+K;txC= XC1(1);tyC= XC1(2);
XD1=T*(XD-K)+K;txD= XD1(1);tyD= XD1(2);

%txA= -xA; tyA= -yA;


%txB= -xB; tyB= -yB;
%txC= -xC; tyC= -yC;
%txD= -xD; tyD= -yD;
minx=min([xA xB xC xD txA txB txC txD]);
maxx=max([xA xB xC xD txA txB txC txD]);
miny=min([yA yB yC yD tyA tyB tyC tyD]);
maxy=max([yA yB yC yD tyA tyB tyC tyD]);

% 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([xB txB]):0.1:max([xB txB]);
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 (xC,yC), (txC,tyC) dan cek grs vertikal/horisontal


if xC==txC % jika garisnya vertikal
tyg3=min([yC tyC]):0.1:max([yC tyC]);
n=length(tyg3);
txg3=ones(1,n);
txg3=txg3*xC;
else
if yC==tyC % jika garisnya horisontal
txg3=min([xC txC]):0.1:max([xC txC]);
n=length(txg3);
tyg3=ones(1,n);
tyg3=tyg3*yC;
else
if xC<txC
txg3=xC:0.1:txC;
else
txg3=txC:0.1:xC;
end;
tyg3=yC+(tyC-yC)*(txg3-xC)/(txC-xC);
end;
end;

%Membuat Garis (xD,yD), (txD,tyD) dan cek grs vertikal/horisontal


if xD==txD % jika garisnya vertikal
tyg4=min([yD tyD]):0.1:max([yD tyD]);
n=length(tyg4);
txg4=ones(1,n);
txg4=txg4*xD;
else
if yD==tyD % jika garisnya horisontal
txg4=min([xD txD]):0.1:max([xD txD]);
n=length(txg4);
tyg4=ones(1,n);
tyg4=tyg4*yD;
else
if xD<txD
txg4=xD:0.1:txD;
else
txg4=txD:0.1:xD;
end;
tyg4=yD+(tyD-yD)*(txg4-xD)/(txD-xD);
end;
end;

%Garis Hasil Refleksi


%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 vertkal
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;

%Membuat Garis (xB,yB), (xC,yC) dan cek grs vertikal/horisontal


if xB==xC % jika garisnya vertikal
yg23=min([yB yC]):0.1:max([yB yC]);
n=length(yg23);
xg23=ones(1,n);
xg23=xg23*xB;
else
if yB==yC % jika garisnya horisontal
xg23=min([xB xC]):0.1:max([xB xC]);
n=length(xg23);
yg23=ones(1,n);
yg23=yg23*yB;
else
if xB<xC
xg23=xB:0.1:xC;
else
xg23=xC:0.1:xB;
end;
yg23=yB+(yC-yB)*(xg23-xB)/(xC-xB);
end;
end;

%Membuat Garis (txB,tyB), (txC,tyC) dan cek grs vertikal/horisontal


if txB==txC % jika garisnya vertikal
tyg23=min([tyB tyC]):0.1:max([tyB tyC]);
n=length(tyg23);
txg23=ones(1,n);
txg23=txg23*txB;
else
if tyB==tyC % jika garisnya horisontal
txg23=min([txB txC]):0.1:max([txB txC]);
n=length(txg23);
tyg23=ones(1,n);
tyg23=tyg23*tyB;
else
if txB<txC
txg23=txB:0.1:txC;
else
txg23=txC:0.1:txB;
end;
tyg23=tyB+(tyC-tyB)*(txg23-txB)/(txC-txB);
end;
end;

%Membuat Garis (xC,yC), (xD,yD) dan cek grs vertikal/horisontal


if xC==xD % jika garisnya vertikal
yg34=min([yC yD]):0.1:max([yC yD]);
n=length(yg34);
xg34=ones(1,n);
xg34=xg34*xC;
else
if yC==yD % jika garisnya horisontal
xg34=min([xC xD]):0.1:max([xC xD]);
n=length(xg34);
yg34=ones(1,n);
yg34=yg34*yC;
else
if xC<xD
xg34=xC:0.1:xD;
else
xg34=xD:0.1:xC;
end;
yg34=yC+(yD-yC)*(xg34-xC)/(xD-xC);
end;
end;

%Membuat Garis (txC,tyC), (txD,tyD) dan cek grs vertikal/horisontal


if txC==txD % jika garisnya vertkal
tyg34=min([tyC tyD]):0.1:max([tyC tyD]);
n=length(tyg34);
txg34=ones(1,n);
txg34=txg34*txC;
else
if tyC==tyD % jika garisnya horisontal
txg34=min([txC txD]):0.1:max([txC txD]);
n=length(txg34);
tyg34=ones(1,n);
tyg34=tyg34*tyC;
else
if txC<txD
txg34=txC:0.1:txD;
else
txg34=txD:0.1:txC;
end;
tyg34=tyC+(tyD-tyC)*(txg34-txC)/(txD-txC);
end;
end;

%Membuat Garis (xD,yD), (xA,yA) dan cek grs vertikal/horisontal


if xD==xA % jika garisnya vertikal
yg41=min([yD yA]):0.1:max([yD yA]);
n=length(yg41);
xg41=ones(1,n);
xg41=xg41*xD;
else
if yD==yA % jika garisnya horisontal
xg34=min([xD xA]):0.1:max([xD xA]);
n=length(xg34);
yg34=ones(1,n);
yg34=yg34*yD;
else
if xD<xA
xg41=xD:0.1:xA;
else
xg41=xA:0.1:xD;
end;
yg41=yD+(yA-yD)*(xg41-xD)/(xA-xD);
end;
end;

%Membuat Garis (txD,tyD), (txA,tyA) dan cek grs vertikal/horisontal


if txD==txA % jika garisnya vertkal
tyg41=min([tyD tyA]):0.1:max([tyD tyA]);
n=length(tyg41);
txg41=ones(1,n);
txg41=txg41*txD;
else
if tyD==tyA % jika garisnya horisontal
txg41=min([txD txA]):0.1:max([txD txA]);
n=length(txg41);
tyg41=ones(1,n);
tyg41=tyg41*tyD;
else
if txD<txA
txg41=txD:0.1:txA;
else
txg41=txA:0.1:txD;
end;
tyg41=tyD+(tyA-tyD)*(txg41-txD)/(txA-txD);
end;
end;

xsmbr=-1000:0.1:1000;
ky=kx*xsmbr+kb;

set(handles.tx1,'Visible','on');
set(handles.ty1,'Visible','on');
set(handles.thasil,'Visible','on');
set(handles.ta1,'Visible','on');
set(handles.tb1,'Visible','on');
set(handles.tc1,'Visible','on');
set(handles.td1,'Visible','on');
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));
set(handles.exc1,'Visible','on');
set(handles.eyc1,'Visible','on');
set(handles.exc1, 'String', num2str(txC));
set(handles.eyc1, 'String', num2str(tyC));
set(handles.exd1,'Visible','on');
set(handles.eyd1,'Visible','on');
set(handles.exd1, 'String', num2str(txD));
set(handles.eyd1, 'String', num2str(tyD));

plot(xA,yA,'r*',xB,yB,'r*',xC,yC,'r*',xD,yD,'r*',txA,tyA,'b*',txB,tyB,'b*',tx
C,tyC,'b*',txD,tyD,'b*',xx,xy,'k',
yx,yy,'k',xg12,yg12,'b',xg23,yg23,'b',xg34,yg34,'b',xg41,yg41,'b',txg1,tyg1,'
g-.',txg2,tyg2,'g-.',txg3,tyg3,'g-.',txg4,tyg4,'g-
.',txg12,tyg12,'r',txg23,tyg23,'r',txg34,tyg34,'r',txg41,tyg41,'r',xsmbr,ky,'
b-.');
axis([minxx maxxx minyy maxyy]);grid;%range gambar
%Memberi text garis ax+b
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;
xC=xC+a1;yC=yC-b1;xC1=txC+a1;yC1=tyC-b1;
xD=xD+a1;yD=yD-b1;xD1=txD+a1;yD1=tyD-b1;
text(xA,yA,'A');text(xA1,yA1,'A1');
text(xB,yB,'B');text(xB1,yB1,'B1');
text(xC,yC,'C');text(xC1,yC1,'C1');
text(xD,yD,'D');text(xD1,yD1,'D1');
text(1,1,'y= ax + b');
end;

case 11
% REFLEKSI thd P(a,b) dan Q(c,d)
indeks1=get(handles.popupmenu1,'Value');
switch indeks1
case 2
% REFLEKSI thd y = ax + b --> untuk TITIK
Pa=str2double(get(handles.epa1,'String'));
Pb=str2double(get(handles.epb1,'String'));
Qc=str2double(get(handles.epa2,'String'));
Qd=str2double(get(handles.epb2,'String'));
xA=str2double(get(handles.ExA,'String'));
yA=str2double(get(handles.EyA,'String'));
%cek garis vertikal/lainnya
if Pa==Qc %jika garisnya vertikal
yPQ=-1000:0.1:1000;
n=length(yPQ);
xPQ=ones(1,n);
xPQ=xPQ*Pa;

T=[-1 0; 0 1]; X=[xA; yA]; K=[2*Pa; 0];


X1=K+T*X; txA=X1(1);tyA=X1(2);
else%untuk lainnya
xPQ=-1000:0.1:1000;
yPQ=Qd+(Pb-Qd)*(xPQ-Qc)/(Pa-Qc);

kxPQ=(Pb-Qd)/(Pa-Qc);
kyPQ=(-(Pb-Qd)*Qc/(Pa-Qc))+Qd;
sk=atan(kxPQ);
T=[cos(2*sk) sin(2*sk); sin(2*sk) -cos(2*sk)];
X=[xA; yA]; K=[0; kyPQ];
X1=T*(X-K)+K; txA=X1(1); tyA=X1(2);
end;
%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.tx1,'Visible','on');
set(handles.ty1,'Visible','on');
set(handles.thasil,'Visible','on');
set(handles.ta1,'Visible','on');
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-.',xPQ,yPQ,'b-.');
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');
text(1,1,'P(a,b), Q(c,d)');

case 3
% REFLEKSI thd P(a,b) dan Q(c,d) --> untuk GARIS
Pa=str2double(get(handles.epa1,'String'));
Pb=str2double(get(handles.epb1,'String'));
Qc=str2double(get(handles.epa2,'String'));
Qd=str2double(get(handles.epb2,'String'));
xA=str2double(get(handles.ExA,'String'));
yA=str2double(get(handles.EyA,'String'));
xB=str2double(get(handles.ExB,'String'));
yB=str2double(get(handles.EyB,'String'));

%cek garis vertikal/lainnya


if Pa==Qc %jika garisnya vertikal
yPQ=-1000:0.1:1000;
n=length(yPQ);
xPQ=ones(1,n);
xPQ=xPQ*Pa;

T=[-1 0; 0 1]; XA=[xA; yA]; XB=[xB; yB]; K=[2*Pa;


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

else%untuk lainnya
xPQ=-1000:0.1:1000;
yPQ=Qd+(Pb-Qd)*(xPQ-Qc)/(Pa-Qc);

kxPQ=(Pb-Qd)/(Pa-Qc);
kyPQ=(-(Pb-Qd)*Qc/(Pa-Qc))+Qd;
sk=atan(kxPQ);
T=[cos(2*sk) sin(2*sk); sin(2*sk) -cos(2*sk)];
XA=[xA; yA]; XB=[xB;yB]; K=[0; kyPQ];
XA1=T*(XA-K)+K;txA=XA1(1);tyA=XA1(2);
XB1=T*(XB-K)+K;txB=XB1(1);tyB=XB1(2);
end;
%txA=-xA; tyA=-yA;
%tyB=-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([xB txB]):0.1:max([xB txB]);
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.tx1,'Visible','on');
set(handles.ty1,'Visible','on');
set(handles.thasil,'Visible','on');
set(handles.ta1,'Visible','on');
set(handles.tb1,'Visible','on');
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',xPQ,yPQ,'b-.');
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');
text(1,1,'P(a,b), Q(c,d)');

case 4
% REFLEKSI thd y=ax+b --> untuk SEGITIGA
Pa=str2double(get(handles.epa1,'String'));
Pb=str2double(get(handles.epb1,'String'));
Qc=str2double(get(handles.epa2,'String'));
Qd=str2double(get(handles.epb2,'String'));
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'))

%cek garis vertikal/lainnya


if Pa==Qc %jika garisnya vertikal
yPQ=-1000:0.1:1000;
n=length(yPQ);
xPQ=ones(1,n);
xPQ=xPQ*Pa;

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


yB];XC=[xC;yC]; K=[2*Pa; 0];
XA1=K+T*XA; txA=XA1(1);tyA=XA1(2);
XB1=K+T*XB; txB=XB1(1); tyB=XB1(2);
XC1=K+T*XC; txC=XC1(1); tyC=XC1(2);

else%untuk lainnya
xPQ=-1000:0.1:1000;
yPQ=Qd+(Pb-Qd)*(xPQ-Qc)/(Pa-Qc);

kxPQ=(Pb-Qd)/(Pa-Qc);
kyPQ=(-(Pb-Qd)*Qc/(Pa-Qc))+Qd;
sk=atan(kxPQ);
T=[cos(2*sk) sin(2*sk); sin(2*sk) -cos(2*sk)];
XA=[xA; yA]; XB=[xB;yB];XC=[xC;yC]; K=[0; kyPQ];
XA1=T*(XA-K)+K;txA=XA1(1);tyA=XA1(2);
XB1=T*(XB-K)+K;txB=XB1(1);tyB=XB1(2);
XC1=T*(XC-K)+K;txC=XC1(1);tyC=XC1(2);
end;
%txA=-xA; tyA=-yA;
%txB=-xB; tyB=-yB;
%txC=-xC; tyC=-xC;

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


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

% 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 (xC,yC), (txC,tyC) dan cek grs vertikal/horisontal


if xC==txC % jika garisnya vertikal
tyg3=min([yC tyC]):0.1:max([yC tyC]);
n=length(tyg2);
txg3=ones(1,n);
txg3=txg3*xC;
else
if yC==tyC % jika garisnya horisontal
txg3=min([xA txA]):0.1:max([xA txA]);
n=length(txg3);
tyg3=ones(1,n);
tyg3=tyg3*yC;
else
if xC<txC
txg3=xC:0.1:txC;
else
txg3=txC:0.1:xC;
end;
tyg3=yC+(tyC-yC)*(txg3-xC)/(txC-xC);
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;

%Membuat Garis (xB,yB), (xC,yC) dan cek grs vertikal/horisontal


if xB==xC % jika garisnya vertikal
yg23=min([yB yC]):0.1:max([yB yC]);
n=length(yg23);
xg23=ones(1,n);
xg23=xg23*xB;
else
if yB==yC % jika garisnya horisontal
xg23=min([xB xC]):0.1:max([xB xC]);
n=length(xg23);
yg23=ones(1,n);
yg23=yg23*yB;
else
if xB<xC
xg23=xB:0.1:xC;
else
xg23=xC:0.1:xB;
end;
yg23=yB+(yC-yB)*(xg23-xB)/(xC-xB);
end;
end;

%Membuat Garis (txB,tyB), (txC,tyC) dan cek grs vertikal/horisontal


if txB==txC % jika garisnya vertikal
tyg23=min([tyB tyC]):0.1:max([tyB tyC]);
n=length(tyg23);
txg23=ones(1,n);
txg23=txg23*txB;
else
if tyB==tyC % jika garisnya horisontal
txg23=min([txB txC]):0.1:max([txB txC]);
n=length(txg23);
tyg23=ones(1,n);
tyg23=tyg23*tyB;
else
if txB<txC
txg23=txB:0.1:txC;
else
txg23=txC:0.1:txB;
end;
tyg23=tyB+(tyC-tyB)*(txg23-txB)/(txC-txB);
end;
end;

%Membuat Garis (xC,yC), (xA,yA) dan cek grs vertikal/horisontal


if xC==xA % jika garisnya vertikal
yg31=min([yC yA]):0.1:max([yC yA]);
n=length(yg31);
xg31=ones(1,n);
xg31=xg31*xC;
else
if yC==yA % jika garisnya horisontal
xg31=min([xC xA]):0.1:max([xC xA]);
n=length(xg31);
yg31=ones(1,n);
yg31=yg31*yC;
else
if xC<xA
xg31=xC:0.1:xA;
else
xg31=xA:0.1:xC;
end;
yg31=yC+(yA-yC)*(xg31-xC)/(xA-xC);
end;
end;

%Membuat Garis (txC,tyC), (txA,tyA) dan cek grs vertikal/horisontal


if txC==txA % jika garisnya vertikal
tyg31=min([tyC tyA]):0.1:max([tyC tyA]);
n=length(tyg31);
txg31=ones(1,n);
txg31=txg31*txC;
else
if tyC==tyA % jika garisnya horisontal
txg31=min([txC txA]):0.1:max([txC txA]);
n=length(txg31);
tyg31=ones(1,n);
tyg31=tyg31*tyC;
else
if txC<txA
txg31=txC:0.1:txA;
else
txg31=txA:0.1:txC;
end;
tyg31=tyC+(tyA-tyC)*(txg31-txC)/(txA-txC);
end;
end;

set(handles.tx1,'Visible','on');
set(handles.ty1,'Visible','on');
set(handles.thasil,'Visible','on');
set(handles.ta1,'Visible','on');
set(handles.tb1,'Visible','on');
set(handles.tc1,'Visible','on');
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));
set(handles.exc1,'Visible','on');
set(handles.eyc1,'Visible','on');
set(handles.exc1, 'String', num2str(txC));
set(handles.eyc1, 'String', num2str(tyC));

plot(xA,yA,'r*',xB,yB,'r*',xC,yC,'r*',txA,tyA,'b*',txB,tyB,'b*',txC,tyC,'b*',
xx,xy,'k', yx,yy,'k',xg12,yg12,'b',xg23,yg23,'b',xg31,yg31,'b',txg1,tyg1,'g-
.',txg2,tyg2,'g-.',txg3,tyg3,'g-
.',txg12,tyg12,'r',txg23,tyg23,'r',txg31,tyg31,'r',xPQ,yPQ,'b-.');
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;
xC=xC+a1;yC=yC-b1;xC1=txC+a1;yC1=tyC-b1;
text(xA,yA,'A');text(xA1,yA1,'A1');
text(xB,yB,'B');text(xB1,yB1,'B1');
text(xC,yC,'C');text(xC1,yC1,'C1');
text(1,1,'P(a,b), Q(c,d)');

case 5
% REFLEKSI thd P(a,b) dan Q(c,d) --> untuk SEGIEMPAT
Pa=str2double(get(handles.epa1,'String'));
Pb=str2double(get(handles.epb1,'String'));
Qc=str2double(get(handles.epa2,'String'));
Qd=str2double(get(handles.epb2,'String'));
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'));

%cek garis vertikal/lainnya


if Pa==Qc %jika garisnya vertikal
yPQ=-1000:0.1:1000;
n=length(yPQ);
xPQ=ones(1,n);
xPQ=xPQ*Pa;

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


yB];XC=[xC;yC]; XD=[xD;yD];K=[2*Pa; 0];
XA1=K+T*XA; txA=XA1(1);tyA=XA1(2);
XB1=K+T*XB; txB=XB1(1); tyB=XB1(2);
XC1=K+T*XC; txC=XC1(1); tyC=XC1(2);
XD1=K+T*XD; txD=XD1(1); tyD=XD1(2);

else%untuk lainnya
xPQ=-1000:0.1:1000;
yPQ=Qd+(Pb-Qd)*(xPQ-Qc)/(Pa-Qc);

kxPQ=(Pb-Qd)/(Pa-Qc);
kyPQ=(-(Pb-Qd)*Qc/(Pa-Qc))+Qd;
sk=atan(kxPQ);
T=[cos(2*sk) sin(2*sk); sin(2*sk) -cos(2*sk)];
XA=[xA; yA]; XB=[xB;yB];XC=[xC;yC];XD=[xD;yD]; K=[0; kyPQ];
XA1=T*(XA-K)+K;txA=XA1(1);tyA=XA1(2);
XB1=T*(XB-K)+K;txB=XB1(1);tyB=XB1(2);
XC1=T*(XC-K)+K;txC=XC1(1);tyC=XC1(2);
XD1=T*(XD-K)+K;txD=XD1(1);tyD=XD1(2);
end;
%txA=-xA; tyA=-yA;
%txB=-xB; tyB=-yB;
%txC=-xC; tyC=-xC;
%txD= -xD; tyD= -yD;

minx=min([xA xB xC xD Pa txA txB txC txD Qc]);


maxx=max([xA xB xC xD Pa txA txB txC txD Qc]);
miny=min([yA yB yC yD Pb tyA tyB tyC tyD Qd]);
maxy=max([yA yB yC yD Pb tyA tyB tyC tyD Qd]);

% 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([xB txB]):0.1:max([xB txB]);
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 (xC,yC), (txC,tyC) dan cek grs vertikal/horisontal


if xC==txC % jika garisnya vertikal
tyg3=min([yC tyC]):0.1:max([yC tyC]);
n=length(tyg3);
txg3=ones(1,n);
txg3=txg3*xC;
else
if yC==tyC % jika garisnya horisontal
txg3=min([xC txC]):0.1:max([xC txC]);
n=length(txg3);
tyg3=ones(1,n);
tyg3=tyg3*yC;
else
if xC<txC
txg3=xC:0.1:txC;
else
txg3=txC:0.1:xC;
end;
tyg3=yC+(tyC-yC)*(txg3-xC)/(txC-xC);
end;
end;

%Membuat Garis (xD,yD), (txD,tyD) dan cek grs vertikal/horisontal


if xD==txD % jika garisnya vertikal
tyg4=min([yD tyD]):0.1:max([yD tyD]);
n=length(tyg4);
txg4=ones(1,n);
txg4=txg4*xD;
else
if yD==tyD % jika garisnya horisontal
txg4=min([xD txD]):0.1:max([xD txD]);
n=length(txg4);
tyg4=ones(1,n);
tyg4=tyg4*yD;
else
if xD<txD
txg4=xD:0.1:txD;
else
txg4=txD:0.1:xD;
end;
tyg4=yD+(tyD-yD)*(txg4-xD)/(txD-xD);
end;
end;

%Garis Hasil Refleksi


%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 (xB,yB), (xC,yC) dan cek grs vertikal/horisontal


if xB==xC % jika garisnya vertikal
yg23=min([yB yC]):0.1:max([yB yC]);
n=length(yg23);
xg23=ones(1,n);
xg23=xg23*xB;
else
if yB==yC % jika garisnya horisontal
xg23=min([xB xC]):0.1:max([xB xC]);
n=length(xg23);
yg23=ones(1,n);
yg23=yg23*yB;
else
if xB<xC
xg23=xB:0.1:xC;
else
xg23=xC:0.1:xB;
end;
yg23=yB+(yC-yB)*(xg23-xB)/(xC-xB);
end;
end;

%Membuat Garis (xC,yC), (xD,yD) dan cek grs vertikal/horisontal


if xC==xD % jika garisnya vertikal
yg34=min([yC yD]):0.1:max([yC yD]);
n=length(yg34);
xg34=ones(1,n);
xg34=xg34*xC;
else
if yC==yD % jika garisnya horisontal
xg34=min([xC xD]):0.1:max([xC xD]);
n=length(xg34);
yg34=ones(1,n);
yg34=yg34*yC;
else
if xC<xD
xg34=xC:0.1:xD;
else
xg34=xD:0.1:xC;
end;
yg34=yC+(yD-yC)*(xg34-xC)/(xD-xC);
end;
end;
%Membuat Garis (xD,yD), (xA,yA) dan cek grs vertikal/horisontal
if xD==xA % jika garisnya vertikal
yg41=min([yD yA]):0.1:max([yD yA]);
n=length(yg41);
xg41=ones(1,n);
xg41=xg41*xD;
else
if yD==yA % jika garisnya horisontal
xg34=min([xD xA]):0.1:max([xD xA]);
n=length(xg34);
yg34=ones(1,n);
yg34=yg34*yD;
else
if xD<xA
xg41=xD:0.1:xA;
else
xg41=xA:0.1:xD;
end;
yg41=yD+(yA-yD)*(xg41-xD)/(xA-xD);
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;

%Membuat Garis (txB,tyB), (txC,tyC) dan cek grs vertikal/horisontal


if txB==txC % jika garisnya vertikal
tyg23=min([tyB tyC]):0.1:max([tyB tyC]);
n=length(tyg23);
txg23=ones(1,n);
txg23=txg23*txB;
else
if tyB==tyC % jika garisnya horisontal
txg23=min([txB txC]):0.1:max([txB txC]);
n=length(txg23);
tyg23=ones(1,n);
tyg23=tyg23*tyB;
else
if txB<txC
txg23=txB:0.1:txC;
else
txg23=txC:0.1:txB;
end;
tyg23=tyB+(tyC-tyB)*(txg23-txB)/(txC-txB);
end;
end;

%Membuat Garis (txC,tyC), (txD,tyD) dan cek grs vertikal/horisontal


if txC==txD % jika garisnya vertkal
tyg34=min([tyC tyD]):0.1:max([tyC tyD]);
n=length(tyg34);
txg34=ones(1,n);
txg34=txg34*txC;
else
if tyC==tyD % jika garisnya horisontal
txg34=min([txC txD]):0.1:max([txC txD]);
n=length(txg34);
tyg34=ones(1,n);
tyg34=tyg34*tyC;
else
if txC<txD
txg34=txC:0.1:txD;
else
txg34=txD:0.1:txC;
end;
tyg34=tyC+(tyD-tyC)*(txg34-txC)/(txD-txC);
end;
end;

%Membuat Garis (txD,tyD), (txA,tyA) dan cek grs vertikal/horisontal


if txD==txA % jika garisnya vertkal
tyg41=min([tyD tyA]):0.1:max([tyD tyA]);
n=length(tyg41);
txg41=ones(1,n);
txg41=txg41*txD;
else
if tyD==tyA % jika garisnya horisontal
txg41=min([txD txA]):0.1:max([txD txA]);
n=length(txg41);
tyg41=ones(1,n);
tyg41=tyg41*tyD;
else
if txD<txA
txg41=txD:0.1:txA;
else
txg41=txA:0.1:txD;
end;
tyg41=tyD+(tyA-tyD)*(txg41-txD)/(txA-txD);
end;
end;

set(handles.tx1,'Visible','on');
set(handles.ty1,'Visible','on');
set(handles.thasil,'Visible','on');
set(handles.ta1,'Visible','on');
set(handles.tb1,'Visible','on');
set(handles.tc1,'Visible','on');
set(handles.td1,'Visible','on');
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));
set(handles.exc1,'Visible','on');
set(handles.eyc1,'Visible','on');
set(handles.exc1, 'String', num2str(txC));
set(handles.eyc1, 'String', num2str(tyC));
set(handles.exd1,'Visible','on');
set(handles.eyd1,'Visible','on');
set(handles.exd1, 'String', num2str(txD));
set(handles.eyd1, 'String', num2str(tyD));

plot(xA,yA,'r*',xB,yB,'r*',xC,yC,'r*',xD,yD,'r*',Pa,Pb,'r*',Qc,Qd,'r*',txA,ty
A,'b*',txB,tyB,'b*',txC,tyC,'b*',txD,tyD,'b*',xx,xy,'k',
yx,yy,'k',xg12,yg12,'b',xg23,yg23,'b',xg34,yg34,'b',xg41,yg41,'b',txg1,tyg1,'
g-.',txg2,tyg2,'g-.',txg3,tyg3,'g-.',txg4,tyg4,'g-
.',txg12,tyg12,'r',txg23,tyg23,'r',txg34,tyg34,'r',txg41,tyg41,'r',xPQ,yPQ,'b
-.');
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;
xC=xC+a1;yC=yC-b1;xC1=txC+a1;yC1=tyC-b1;
xD=xD+a1;yD=yD-b1;xD1=txD+a1;yD1=tyD-b1;
text(xA,yA,'A');text(xA1,yA1,'A1');
text(xB,yB,'B');text(xB1,yB1,'B1');
text(xC,yC,'C');text(xC1,yC1,'C1');
text(xD,yD,'D');text(xD1,yD1,'D1');
text(1,1,'P(a,b), Q(c,d)');
end;
end;