[R] to draw a smooth arc
Paul Murrell
p.murrell at auckland.ac.nz
Wed May 2 01:03:45 CEST 2007
Hi
Paulo Barata wrote:
> Dr. Murrell and all,
>
> One final suggestion: a future function arc() in package graphics,
> with centre-radius-angle parameterisation, could also include an
> option to draw arrows at either end of the arc, as one can find
> in function arrows().
... and in grid.xspline() and grid.curve().
Paul
> Thank you.
>
> Paulo Barata
>
> -----------------------------------------------------------------------
> Paul Murrell wrote:
>> Hi
>>
>>
>> Paulo Barata wrote:
>>> Dr. Snow and Prof. Ripley,
>>>
>>> Dr. Snow's suggestion, using clipplot (package TeachingDemos),
>>> is maybe a partial solution to the problem of drawing an arc of
>>> a circle (as long as the line width of the arc is not that large,
>>> as pointed out by Prof. Ripley). If the arc is symmetrical around
>>> a vertical line, then it is not so difficult to draw it that way.
>>> But an arc that does not have this kind of symmetry would possibly
>>> require some geometrical computations to find the proper rectangle
>>> to be used for clipping.
>>>
>>> I would like to suggest that in a future version of R some function
>>> be included in the graphics package to draw smooth arcs with
>>> given center, radius, initial and final angles. I suppose
>>> that the basic ingredients are available in function "symbols"
>>> (graphics).
>>
>> Just to back up a few previous posts ...
>>
>> There is something like this facility already available via the
>> grid.xspline() function in the grid package. This provides very
>> flexible curve drawing (including curves very close to Bezier curves)
>> based on the X-Splines implemented in xfig. The grid.curve() function
>> provides a convenience layer that allows for at least certain
>> parameterisations of arcs (you specify the arc end points and the angle).
>>
>> These functions are built on functionality within the core graphics
>> engine, so exposing a similar interface (e.g., an xspline() function)
>> within "traditional" graphics would be relatively straightforward.
>>
>> The core functionality draws the curves as line segments (but
>> automatically figures out how many segments to use so that the curve
>> looks smooth); it does NOT call curve-drawing primitives in the
>> graphics device (like PostScript's curveto).
>>
>> In summary: there is some support for smooth curves, but we could still
>> benefit from a specific arc() function with the standard
>> centre-radius-angle parameterisation and we could also benefit from
>> exposing the native strengths of different graphics devices (rather than
>> the current lowest-common-denominator approach).
>>
>> Paul
>>
>>
>>> Thank you very much.
>>>
>>> Paulo Barata
>>> (Rio de Janeiro - Brazil)
>>>
>>> -----------------------------------------------------------------------
>>> Prof Brian Ripley wrote:
>>>> On Tue, 1 May 2007, Greg Snow wrote:
>>>>
>>>>> Here is an approach that clips the circle you like from symbols down to
>>>>> an arc (this will work as long as the arc is less than half a circle,
>>>>> for arcs greater than half a circle, you could draw the whole circle
>>>>> then use this to draw an arc of the bacground color over the section you
>>>>> don't want):
>>>>>
>>>>> library(TeachingDemos)
>>>>> plot(-5:5, -5:5, type='n')
>>>>> clipplot( symbols(0,0,circles=2, add=TRUE), c(0,5), c(0,5) )
>>>> I had considered this approach: clipping a circle to a rectangle isn't
>>>> strictly an arc, as will be clear if the line width is large.
>>>> Consider
>>>>
>>>> clipplot(symbols(0, 0 ,circles=2, add=TRUE, lwd=5), c(-1,5), c(-1,5))
>>>>
>>>> Note too that what happens with clipping is device-dependent. If R's
>>>> internal clipping is used, the part-circle is converted to a polygon.
>>>>
>>>>
>>> ______________________________________________
>>> R-help at stat.math.ethz.ch mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/
More information about the R-help
mailing list