Commit cbff0cbc authored by Giuseppe Lombardi's avatar Giuseppe Lombardi

Upload New File

parent 861bf435
function S=segmento(x, y)
if x<0
x=-x;
endif
if y<0
y=-y;
endif
S(:,1)=[x, y];
r1=x;
r2=y;
k=2;
while r1 != 0 || r2 != 0
if [r1, r2] == [2, 2]
S(:,k)=[1;0];
S(:,k+1)=[0;2];
S(:,k+2)=[-2;1];
S(:,k+3)=[0;0];
r1=0;
r2=0;
endif
if [r1, r2] == [1, 0] || [r1, r2] == [0, 1]
S(:,k)=[-1;-1];
S(:,k+1)=[-2;1];
S(:,k+2)=[0;0];
r1=0;
r2=0;
endif
if [r1, r2] == [0, 2]
S(:,k)=[-2;1];
S(:,k+1)=[0;0];
r1=0;
r2=0;
endif
if [r1, r2] == [2, 0]
S(:,k)=[1;-2];
S(:,k+1)=[0;0];
r1=0;
r2=0;
endif
if [r1, r2] == [1, 1]
S(:,k)=[2;-1];
S(:,k+1)=[0;0];
r1=0;
r2=0;
endif
if r1 !=0 || r2 != 0
if r1 >= r2
r1 = r1-2;
r2 = r2-1;
else
r1 = r1-1;
r2 = r2-2;
endif
S(:,k)=[r1; r2];
endif
if r1<0
r1=-r1;
endif
if r2<0
r2=-r2;
endif
k=k+1;
endwhile
x=S(1,:);
y=S(2,:);
k=size(S)(2)-1
%set grid xtics (-10,0.5,10);
%set grid ytics (-10,0.5,10);
plot(x,y,"o");
endfunction
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment