Not necessary. Let me add comments to my code in places where I need  
help. My comments are marked with [DA 6/25].

\startbuffer
numeric w,h;
w=4cm;h=4cm;
% inititialize numerator and denominator of the slope of f
numeric a;
a=1.5;

% initialize choice of function
numeric choice;
choice=2;                     %<=====[DA 6/25]Test to see if code  
works for 1, 2, or 3.

% initialize type of reflection
numeric reflect;
reflect=3;                   %<======[DA 6/25]Test to see if code  
works for 1, 2, 3, or 4

% define linear function f
vardef f(expr x)=
        a*x*x
enddef;

% define linear function g
vardef g(expr x)=
        a*abs(x)
enddef;

% define linear function h
vardef h(expr x)=
        a*x*(x-2)*(x+2)/2
enddef;

% define paths for functions f, g, and h, respectively
path P, F, G, H;

F:=(-5,f(-5));
for x=-5 step .1 until 5:
        F:=F--(x,f(x));
endfor;

G:=(-5,g(-5));
for x=-5 step .1 until 5:
        G:=G--(x,g(x));
endfor;

H:=(-5,h(-5));
for x=-5 step .1 until 5:
        H:=H--(x,h(x));
endfor;

% choose the function to use, f, g, or h
if (choice=1):
        P:=F;
elseif (choice=2):
        P:=G;
else:
        P:=H;
fi;

% choose the type of reflection
if (reflect=1):
        P:=P;
elseif (reflect=2):
        P:=P reflectedabout((0,0),(1,1));
elseif (reflect=3):
        P:=P reflectedabout((0,0),(1,-1));
else:
        P:=P reflectedabout((-1,0),(1,0));
fi;

% initialize scale
numeric u; 10u=w;

% scale and draw graph
P:=P scaled u;
draw P withcolor blue;

% clipping path
path cpath;
cpath:=(-5,-5)--(5,-5)--(5,5)--(-5,5)--cycle;
cpath:=cpath scaled 1u;


%[DA 6/25]<========Replace this code from here to next mark with new  
clipping routine
% clip and save current picture
picture pic;
clip currentpicture to cpath;
pic:=currentpicture;

% erase currentpicture
currentpicture:=nullpicture;
%[DA 6/25]<========End of code to replace with new clipping routine

%[DA 6/25] Put new clipping routine here. It should return P clipped  
to clipping path
%[DA 6/25] for all choices of "choice" and "reflect:

% draw grid
for k=-5u step 1u until 5u:
        draw (-5u,k)--(5u,k) withcolor mygridcolor;
        draw (k,-5u)--(k,5u) withcolor mygridcolor;
endfor;

% draw axes
drawarrow (-5u,0)--(5u,0);
drawarrow (0,-5u)--(0,5u);

% label axes
label.rt(btex $x$ etex, (5.2u,0));
label.top(btex $y$ etex, (0,5.2.u));
label.bot(btex $5$ etex, (5u,0));
label.lft(btex $5$ etex, (0,5u));

%[DA 6/25]<==========Replace with "draw pic" command with  
"drawdblarrow P"
% redraw line
draw pic;

\stopbuffer

\startlinecorrection[blank]
\midaligned{\processMPbuffer}
\stoplinecorrection





On Jun 25, 2006, at 1:14 PM, Mojca Miklavec wrote:

> On 6/25/06, David Arnold wrote:
>> That is, I would choose a boundary that would present arrow heads at
>> each end of the curve. In the case of rational functions, I would
>> clip each branch separately.
>>
>> I hope this answers the question.
>
> So that necessary means an arrowhead each time when a function crosses
> the boundary if I understand correctly (i.e. 1/x would have 4
> arrowheads)?
>
> Mojca
> _______________________________________________
> ntg-context mailing list
> ntg-context@ntg.nl
> http://www.ntg.nl/mailman/listinfo/ntg-context

_______________________________________________
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context

Reply via email to