groff
[Top][All Lists]

## Re: [Groff] Bug in pic? And how to do this right?

 From: Ted Harding Subject: Re: [Groff] Bug in pic? And how to do this right? Date: Fri, 12 Dec 2003 18:11:06 -0000 (GMT)

``` Greg 'groggy' Lehey wrote:
>1.  Am I correct in my assumption that I can draw only whole ellipses?
>    Is there any other way to draw the correct partial ellipse?  It
>    seems that it would be nice to have a feature in pic to draw
>    arbitrary curves (specified by a formula), but I can't quite see
>    how to do it.  If it's not there, and people think it's a good
>    idea, I'm prepared to have a crack at it some time.  In that case,
>    can anybody give me an idea how to go about it?  I've had a look
>    in the code, and it doesn't look impossibly difficult or
>    convoluted.
>
>Greg

Yes, you can draw according to a formula, since pic is equipped
with quite a useful numerical computation engine, as well as
looping and branching operators.[*] However, it only has the most basic
mathematical functions, so you may have to go to some trouble to
get it to compute anything else.
Example of using pic to draw a graph according to a formula:

.LP
.PS 4i
pi=4*atan2(1,1)
x0 = 0; y0 = 1
for i=1 to 10000 do {
x1 = i*2*pi/2000
y1 = cos(x1)/(1+x1/5)
line from (x0,10*y0) to (x1,10*y1)
x0 = x1 ; y0 = y1
}
.PE

So you can draw "arbitrary" curves by using a lot of very short
line segments. If all else fails, you could do your arc this way.

Ted.

[*] I've used pic in a troff document to read in a data file
of (x,y) values, plot the points, compute a linear (or quadratic)
regression of y on x, draw the regression line (or curve) on the
graph and annotate it with the fitted formula, and compute the
sums of squares needed for an analysis of variance and pass
resulting numbers to troff in number registers so that it
can format an ANOVA table. Mind you, this was only as a demo
of what can be done: in real life I do my statistical analysis
by other means!

--------------------------------------------------------------------