[英]Draw Radians/Degrees in Circle in R
我很难生成一个圆的X,Y坐标,然后绘制线段。 基本上我想做的是从圆心到圆外以完美的间距绘制360线。 这是我目前正在执行的操作,但无法正常工作。 如果有其他方法可以做到,那么效果也很好! 我也希望0度从圆的左侧开始。
t <- seq(0,2*pi,length=360)
coords <- t(rbind( sin(t)*127.28125, cos(t)*127.28125))
plot(coords,type='n',xlim=c(-63.625625,63.625625),ylim=c(0,127.28125))
lines(coords)
deg=data.frame(coords[,1],coords[,2])
head(deg)
deg$count=1
deg$degree=1
for(i in 1:nrow(coords)){
if(deg$count[i]<=270){
deg$degree[i]=i-1+90-45
} else {
deg$degree[i]=i-1-270-45
}
}
names(deg)[1] <- "X"
names(deg)[2] <- "Y"
i=1
for(i in 1:19){
segments(0,0,deg$X[deg$degree==((5*(i-1)))],deg$Y[deg$degree==((5*(i-1)))])
cat(((5*(i-1))),'\t')
}
更新:
我在绘制线条的地方遇到一些问题。 基本上,当我们绕圆旋转时,误差会变大,因此当pi / 2弧度发生并且直线上升时,该值稍微位于x = 0的右侧。 这可能无法实现,但我想请教一下是否有解决方法! 45 90和135应该都匹配。
这个怎么样
th <- seq(0, 2*pi, length.out=360)
r <- 2
x <- r*cos(th)
y <- r*sin(th)
plot(x,y, type="n")
segments(0,0,x,y)
基本上,我在极空间中选择th
和r
并转换为笛卡尔坐标。
如果要从左侧的0开始,请使用
x <- -r*cos(th)
代替。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.