[Top][All Lists]

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

Re: [Groff] Drawing filled circle segments

From: Ted Harding
Subject: Re: [Groff] Drawing filled circle segments
Date: Sun, 30 Oct 2005 22:09:09 -0000 (GMT)

On 30-Oct-05 Amber Hassaan wrote:
> Hi Werner,
>            Having read solutions posted to the
> forgoing problem by Ted and others,I think the task is
> solved for now.But I would rather that(in coming
> releases of groff):
> 1.pic had some construct like filled arc and filled
> polygon.(in addition to \D request)
> 2.\D'***' request could be enhanced to draw filled
> arcs with \D'A ***' in addition to the original arc
> request \D'a ***'.
> best regards
> amber

This comes back to a general point I made some time earlier
(in the discussion on shaded/coloured boxes with round corners):
that 'pic' lacks (for this particular kind of thing) the facility
to "close" a general object, i.e. you could draw an outline
with joined-up liness and curves, declared it "closed" (which
would correspond to the PostScript command "closepath" in the
background) and then proceed to fill/shade it (just as with
"fill" in PS).

It might seem that 'pic' depends on a somewhat limited class of
primitives, but basically so does PostScript itself at that level,
yet there's no limit to what can be drawn therewith!

Not that I'm suggesting that making 'pic' more usable in the
broad sense is trivial!

There's another development one can make from a point made by Werner
below, for which see at end.

> --- Werner LEMBERG <address@hidden> wrote:
>> > It works well for what I need right now, but the macro approach
>> > makes sense provided groff supports sine, cosine, and tangent
>> > functions...
>> Given that groff doesn't have a `float' data type only ad-hoc
>> solutions for the trigonometric functions, suitable to a specific
>> problem, make sense IMHO.
>>     Werner

While that is true for groff, it's not true for 'pic', and it can
often be useful to use 'pic' in-line for purely compytational work.

For this, however, you have to add an extra option to the ".PS"
and ".PE" macros in whatever package you use, so that their
occurrence will have no visible effect on the page.

For instance, I temporarily ".PS" in the "ms" macro package to
accept the option "T" (for "Tacit" in general, or "Table" which
was what I first used it for):

.de PS
.ie '\\$3'T' \{\
.ds pic*Table T
.el \{\
.ds pic*Table
[all the rest of the normal .PS]


.de PE
.ie '\\*[pic*Table]'T' .rm pic*Table
.el \{\
[all the rest of the normal .PE]

With those planted, you can now do floating-point arithmetic in 'pic',
and make the results available to troff.

Here is an example (including the full ".PS" and ".PE" macros from
"ms" as revised above). Granted, the particular shapes drawn here
in the main graphic can as well be done using "raw pic", but I'm
giving it to illustrate the use of 'pic for "in-line" numerical
computation in groff source: note that 'pic' has not been used to
actually *draw* anything! It's role is purely numerical (and also
to pass the computed commands to groff).


   groff -pe -ms ....

on it (you need the "e" as well, at a couple of points).

.de PS
.ie '\\$3'T' \{\
.ds pic*Table T
.el \{\
.ds pic*Table
.sp \\n[DD]u
.ie \\n[.$]<2 address@hidden bad arguments to PS (not preprocessed with pic?)
.el \{\
.       address@hidden (u;\\$1)+1v
.       in +(u;\\n[.l]-\\n[.i]-\\$2/2>?0)
.de PE
.ie '\\*[pic*Table]'T' .rm pic*Table
.el \{\
.sp \\n[DD]u+.5m
pi = 4*atan2(1,1)
command ".ds s60 " sprintf("%0.3f",sin(pi/3))
command ".ds c60 " sprintf("%0.3f",cos(pi/3))
cos 60\(de $=$ \*[c60] and sin 60\(de $=$ \*[s60],
so here is a nice little polygon:\0\
\Z'\D'p \
\*[c60]n -\*[s60]n   1n 0    \*[c60]n  \*[s60]n \
-\*[c60]n \*[s60]n  -1n 0   -\*[c60]n -\*[s60]n'\
But you can also use \f[CR] .PS T \fP to loop through numbers:
.sp 2i
.ds poly \Z'\D'f \\*[gray]''\Z'\h'3i-\\*[x0]'\D'P \
 \\*[dx] -\\*[dy]   \\*[dh] 0   \\*[dx]  \\*[dy] \
-\\*[dx]  \\*[dy]  -\\*[dh] 0  -\\*[dx] -\\*[dy]''
for j = 1 to 10 do { i = 11-j
command ".ds gray " sprintf("%.0f", 1316 - sqrt(100000*i))
command ".ds x0 " sprintf("%0.3fi",(0.5+cos(pi/3))*sqrt(4*i/10))
command ".ds dx " sprintf("%0.3fi",sqrt(4*i/10)*cos(pi/3))
command ".ds dh " sprintf("%0.3fi",sqrt(4*i/10))
command ".ds dy " sprintf("%0.3fi",sqrt(4*i/10)*sin(pi/3))
command "\*[poly]\c"

For a different effect, change the "for" line in the 'pic'
loop to

  for j = 1 to 100 do { i = (101-j)/10

Best wishes to all,

E-Mail: (Ted Harding) <address@hidden>
Fax-to-email: +44 (0)870 094 0861
Date: 30-Oct-05                                       Time: 22:09:06
------------------------------ XFMail ------------------------------

reply via email to

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