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

后端 未结 5 1750
梦如初夏
梦如初夏 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-15 23:59

    Since it is fairly straight forward, you can write your own function. Matlab-like cart2pol function in R:

    cart2pol <- function(x, y)
    {
      r <- sqrt(x^2 + y^2)
      t <- atan(y/x)
    
      c(r,t)
    }
    

提交回复
热议问题