groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Groff] chop in pic?


From: Ralph Corderoy
Subject: Re: [Groff] chop in pic?
Date: Thu, 04 Oct 2001 14:12:05 +0100

Hi,

Sorry to be late to the party...

> > In the original pic, I believe that I remember that chop would end
> > the arrows at the boundary of the ellipse but GNU pic has never
> > done that.  Is this a known bug?  Is my memory/understanding
> > incorrect?  Thanks.
> 
> According to the original pic manual, it doesn't.  If I read the docs
> correctly, `chop' applies to straight lines only (thus your arc won't
> be chopped anyway), and it will use `circlerad' (0.25) for chopping
> if no other values are given.

It doesn't cope with ellipses either.  There's a bit in the manual
where it says to use the trig functions for other required
intersections and I've ended up doing the maths in the past once I've
dug out the appropriate formula.

    .PS

    w = 3
    h = 1
    a = w / 2
    b = h / 2

    down
    R: box wid w ht h
    move
    E: ellipse wid w ht h

    i = w / 5
    for x = -a + i to a - i by i do {
        y = sqrt((1 - (x^2 / a^2)) * b^2)
        arrow from R.s + (x, 0) to E.c + (x, y)
    }

    .PE

If you've an angle theta in radians instead of an existing x coordinate
then you can get an (x, y) using

    r = sqrt((a^2 * b^2) / (a^2 * sin(theta)^2 + b^2 * cos(theta)^2))
    x = cos(theta) * r
    y = sin(theta) * r

where a and b are the half-width and half-height as in the first
example.

> I could generalize pic's syntax of compass points with something like:
> 
>   deg = atan2(0, -1) / 180 ;
>   move to last ellipse .angle deg * 217 ;
> 
> This would specify a point on the ellipse with an angle of 217 degrees
> (in the mathematical sense, i.e. counter-clockwise from the right).
> 
> Comments?

Not bad.  Do any of the other .pos notations take a parameter?  If not,
perhaps a function would be better.

    ellipseperim(E.c, E.w, E.h, theta)

returning a point.

I'm not sure.  Also, there will always be other things that wouldn't be
handled like the intersection of two lines, or an arc and a line, etc.
Perhaps it's best to leave the simple case to chop and provide examples
showing that the others are up to the author.


Ralph.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]