trying to draw circles based on distance between points

我怕爱的太早我们不能终老 提交于 2019-12-01 16:33:45

问题


I'm trying to draw some circles and I was sort of hoping they would intersect with some points, alas...

library(maptools)
library(plotrix)
xy <- matrix(runif(20, min = -100, max = 100), ncol = 2)
distance <- spDistsN1(xy, xy[1, ])
plot(0,0, xlim = c(-100, 100), ylim = c(-100, 100), type = "n")
points(data.frame(xy))
points(xy[1, 1], xy[1, 2], pch = 16)
draw.circle(xy[1, 1], xy[1, 2], radius = distance)

The above code does the following:

  • Create 10 random points and choose one (first) point that would serve as an "anchor".
  • Calculate distance from anchor to all other points. This will be our "radius"
  • Draw circles around anchor point using above calculated distances for radii.
  • Scratch head why circles don't intersect with points that were used to calculate radii.


回答1:


This is the old aspect ratio problem that comes up from time to time when people are drawing ellipses, circles, etc.

  • Drawing non-intersecting circles

Substituting MASS::eqscplot for plot (edit: or using asp=1: see ?par) appears to solve the problem.



来源:https://stackoverflow.com/questions/6322603/trying-to-draw-circles-based-on-distance-between-points

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!