R?的圆上等距n点的坐标? [英] Coordinates of equally distanced n points on a circle in R?

查看:174
本文介绍了R?的圆上等距n点的坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取R中圆上的等距 n个点的坐标。




I want to get the coordinates of the equally distanced n points on a circle in R.

Mathematically the solution is: exp((2*pi * i)*(k/n)) where 0 <= k < n

There are many SOF questions to handle this problem. All the solutions are in non-R environments:

Evenly distributing n points on a sphere (java, python solutions presented)

Generating points on a circle (non-R solution)

calculate pixel coordinates for 8 equidistant points on a circle (python solution)

drawing points evenly distributed on a circle (non-R solution)

How to plot points around a circle in R (no equally distancing)

Coordinates of every point on a circle's circumference (non-R solution)

Coordinates of points dividing circle into n equal halves in Pebble

How to efficiently draw exactly N points on screen? (python solution)

Approximate position on circle for n points (non-R solution)

Determining Vector points on a circle

What I did for solution:

# For 4 points, 0<=k<4    
exp((2*pi*sqrt(-1))*(0/4)); exp((2*pi*sqrt(-1))*(1/4)); exp((2*pi*sqrt(-1))*(2/4)); exp((2*pi*sqrt(-1))*(3/4)) 

Complex number i is not defined in R. There is no such constant as opposite to pi (3.14). The trick sqrt(-1) to similate i does not work; the error:

[1] NaN 
Warning message: In sqrt(-1) : NaNs produced

解决方案

Yo can try this too (and avoid complex arithmetic) to have points on the unit circle on the real plane:

n <- 50 # number of points you want on the unit circle
pts.circle <- t(sapply(1:n,function(r)c(cos(2*r*pi/n),sin(2*r*pi/n))))
plot(pts.circle, col='red', pch=19, xlab='x', ylab='y')

这篇关于R?的圆上等距n点的坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆