[R] to draw a smooth arc
Greg Snow
Greg.Snow at intermountainmail.org
Tue May 1 16:53:54 CEST 2007
There is the grid.xspline function in the grid package that allows for
things like this (the control points, though more general than what you
state). I don't know if it uses the postscript curveto, or approximates
using line segments.
You can also use the xfig device, then use xfig, winfig, or jfig to
explicitly convert any polylines to xslpines, adjust any parameters of
the spline that you want, then export to other formats.
Hope this helps,
--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at intermountainmail.org
(801) 408-8111
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of
> ted.harding at nessie.mcc.ac.uk
> Sent: Tuesday, May 01, 2007 7:51 AM
> To: r-help at stat.math.ethz.ch
> Subject: Re: [R] to draw a smooth arc
>
> This thread prompts me to ask about something I've been
> pondering for a while, as to whether there's an
> implementation somewhere ticked away in the R resources.
>
> So far, people have been responding to the original query in
> terms of increasing the numbers of points, and joining these by lines.
>
> However, if you're using PostScript output, you can draw
> really smooth curves by exploiting PS's "curveto" operator.
> This draws a cubic-curve segment in the following way:
>
> The two points you want to join with a curve will be denoted
> by (X0,Y0) and (X3,Y3) in the following (for reasons which
> will appear). The PS command is of the form
>
> x1 y1 x2 y2 X3 Y3 curevto
>
> At (X0,Y0) the tangent to the curve (as it departs from
> (X0,Y0) is in the direction of the directed line from (X0,Y0)
> to (x1,y1), and at (X3,Y3) (as it arrives) the tangent to the
> curve is in the direction of the directed line from (x2,y3)
> to (X3,Y3).
>
> The location of (X0,Y0) is not part of the command, since it
> is implicit in the PS "currentpoint" which is the starting
> point of the curve.
>
> The result is (in theory, and in practice to within the
> resolution of the output device) a perfectly smooth curve,
> provided the consecutive cubic segments have the same tangent
> at each of the points being joined. This can be achieved by
> appropriate choice of the "intermediate" points -- (x1,y2),
> (x2,y2) above.
>
> So far, when I've done this myself (including when using the
> output from R to give the points being joined), I've done the
> computation of the "intermediate" points "by hand". This
> basically involves deciding, at each of the points being
> joined, what the tangent to the smooth curve shouold be.
>
> Of course, there is an element of arbitrariness in this,
> unless there is an analytic representation of the curve on
> which the points lie (e.g. you're plotting sin(x)/x every
> pi/8, and want to join them smoothly), when all you need is
> the derivatives at the points.
>
> Crudely, you might evaluate the direction at a point in terms
> os a weighted average of the directions to its two immediate
> neighbours (the nearer meghbour ges the greater weight); less
> crudely, you might fit a quadratic through the point and its
> 2 neighbours and use the gradient at the middle point; and so on.
>
> Once you've decided on the tangent at each point, it's then
> straightforward to compute suitable "intermediate points"
> to serve as (x1,y2) and (x2,y2).
>
> (One application where this sort of approach is needed is in
> joining computed points on iso-contours, where the individual
> points have been determined by interpolation of
> spot-measurements at nearby measuring stations).
>
> Anyway. The Question: is there a general function for the
> above kind of smooth curve-drawing?
>
> With thanks,
> Ted.
>
> --------------------------------------------------------------------
> E-Mail: (Ted Harding) <ted.harding at nessie.mcc.ac.uk>
> Fax-to-email: +44 (0)870 094 0861
> Date: 01-May-07 Time: 14:50:38
> ------------------------------ XFMail ------------------------------
>
> ______________________________________________
> 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.
>
More information about the R-help
mailing list