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

后端 未结 2 785
轻奢々
轻奢々 2021-02-15 23:45

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

2条回答
  •  滥情空心
    2021-02-16 00:05

    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)
    }
    

提交回复
热议问题