R: Converting cartesian coordinates to polar coordinates, and then calculating distance from origin

后端 未结 5 1746
梦如初夏
梦如初夏 2021-02-15 23:39

I\'ve been looking for a solution to convert cartesian coordinates (lat, long) that I have to polar coordinates in order to facilitate a simulation that I want to run, but I hav

5条回答
  •  旧巷少年郎
    2021-02-16 00:13

    I think you can do transformation bewteen catesian and polar this way:

    polar2cart <- function(r, theta) {
      data.frame(x = r * cos(theta), y = r * sin(theta))
    }
    
    cart2polar <- function(x, y) {
      data.frame(r = sqrt(x^2 + y^2), theta = atan2(y, x))
    }
    

提交回复
热议问题