Re: Re: [metafont] Graph.mp annoyances

Brian Elmegaard <[email protected]> Wed, 10 Sep 2003 08:31:48 +0200
Newsgroups gmane.comp.tex.metapost,gmane.comp.tex.metafont
Message-ID <[email protected]>
Daniel,

I know from experience that the bezier curves very different from what 
was expected. And, generally I would not want to have make a curved 
graph from a set of data points. However, if I would like to plot the 
sine-function, it would be easier to have just a few points on it and 
still have a curve.

One reason for asking was also, that there might be good reasons for the 
way it was written, so please explain.

The following shows up as a polygonal curve in the .1 (and also shows a 
bad arrowhead):

% -90	0
% -70	0.342
% -50	0.6428
% -30	0.866
% -10	0.9848
% 0	1
% 10	0.9848
% 30	0.866
% 50	0.6428
% 70	0.342
% 90	0

beginfig(1);
draw begingraph(5cm,5cm);
   gdraw "mpgraph.mp";
   gdrawarrow (10,1)--(12,2); % BTW, this shows that even straigth line
                              % arrowheads looks odd.
endgraph;
endfig;

If instead I change the boolean argument to GMcvi_ in Gdraw_ to false:
% Handle the part of a Gdraw command that uses path or data file p.
def Gdraw_ expr p =
   if string p: GMcvi_(false) Mreadpath(p) % argument changed to false
   elseif path p or pair p: Gucvi_ p
   else: Gerr_(p,"gdraw argument should be a data file or a path")
         origin
   fi
   withpen currentpen Gwithlist_ _op_
enddef;

I get a very (very, very IMHO) strange curve.

If in addition, I change the ..controls line in Gscan_ by removing the 
controls it looks as expected:
vardef Gscan_(expr p, c)(suffix tx, ty) =
   if (str tx="") and (str ty=""):  p
   else:
     save r_; path r_;
     forever:
       Gdidsc_ := false;
       r_ := Gpp_(point 0 of p, tx, ty)
       if path p:
         for t=1 upto length p:
           if c: --
           else: .. % looks better for a simple curve
           fi
           Gpp_(point t of p, tx, ty)
         endfor
         if cycle p: &cycle fi
       fi;
       exitunless Gdidsc_;
     endfor
     if pair p: point 0 of fi r_
   fi
enddef;

regards,
Brian



Daniel H. Luecking wrote:
> On Tue, 9 Sep 2003, Brian Elmegaard wrote:
> 
> 
>>Hi all,
>>
>>I am using the metapost graph macro a lot, but it has a few minor
>>annoyances. Maybe some of you have already solved the following problems:
>>
>>* The direction of arrowheads in gdrawarrow does not follow the curve it
>>is on.
> 
> 
> This may be because the direction is undefined at corners of a path. MP
> usually uses (postcontrol - precontrol), which doesn't usually match
> either the in or the out direction. graph.mp uses instead (point -
> precontrol) as the direction, generally a better choice. However, if the
> path is rather curved near the head, it may seem to be incorrect, with
> the edge of the head closer to the path on the inside of the curve.
> Still, the head does point in the direction of the tangent at the
> endpoint of the curve.
> 
> It is really quite difficult to algorithmically choose an arrowhead.
> (I know, I've tried.) The best looking results can be achieved by
> putting the *base* of the arrowhead (rather than the tip) at the path's
> endpoint. But most people don't want to allow that.
> 
> 
>>* Reading data from a file only works if there is exactly one empty line
>>between data for each curve and the error message is not helpful
> 
> 
> All graphing programs I know of require a particular format for the data
> file. Some give no error and simply stop at a double blank line. One
> simply has to know the rquirements for input.
> 
> 
>>* Data with exponent as 1e4 cannot have a capital E.
>>
>>* Curves from data are always polygonal, unless one changes the true
>>argument to GMcvi_ in Gdraw_. If this is set to false a very special
>>kind of curve is created. Why does the branch for false have post- and
>>precontrol of the curve, not just .. which makes a nice, smooth curve?
> 
> 
> Because ".." will often not make a *nice* smooth curve. Without
> selecting the controls, such a connection will often make S-shapes in
> the graph (where the curve turns in the negative horizontal direction
> briefly) if the data varies rapidly. In such cases the graph should not
> be too smooth. Admittedly, I don't know how graph.mp chooses controls,
> nor whether there might be better choices, but for general purposes,
> some choice is unavoidable.
> 
> Regards,
> 


-- 
Brian Elmegaard ([email protected])
Dept. of Mechanical Engineering, Energy Engineering,
Technical University of Denmark, Phone +45 4525 4169  Fax +45 4593 5215
http://www.et.dtu.dk/staff/be