Skip to content
Prev 16611 / 29559 Next

how to draw a new circle/round polygon on existing plot

x = 10 # center x
y = 10 # center y
n = 100 # nr of pts
r = 5 # radius
pts = seq(0, 2 * pi, length.out = n)
plot(sin(pts), cos(pts), type = 'l', asp = 1) # test
require(sp)
xy = cbind(x + r * sin(pts), y + r * cos(pts))
sl= SpatialLines(list(Lines(list(Line(xy)), "line")))
plot(sl, add=FALSE, col = 'red', axes=T )

this draws a circle as a line; if you want a filled polygon, I'd replace
every instance of Line with Polygon (but mind the s).
On 11/06/2012 09:30 PM, Wouter Steenbeek wrote: