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


i've been looking solution convert cartesian coordinates (lat, long) have polar coordinates in order facilitate simulation want run, haven't found questions or answers here doing in r. there number of options, including built in function cart2pol in matlab, of data in r , i'd continue getting comfortable working in framework.

question:

i have lat/long coordinates tagging data, , want convert these polar coordinates (meaning jump size , angle: http://en.wikipedia.org/wiki/polar_coordinate_system) can shuffle or bootstrap them (haven't decided which) 1,000 times, , calculate straight-line distance of each simulated track starting point. have true track, , i'm interested in determining if animal exhibiting site affinity simulating 1,000 random tracks same jump sizes , turning angles, in different orders , combinations. need 1,000 straight-line distances origin create distribution of distances , compare true data set's straight-line distance.

i'm comfortable doing bootstrapping, i'm stuck @ first step, converting cartesian lat/long coordinates polar coordinates (jump size , turning angle). know there built in functions in other programs such matlab, can't find way in r. manually hand in for-loop, if there's package out there or easier way it, i'd prefer that.

ideally i'd convert data polar coordinates, run simulation, , each random track output end point cartesian coordinates, lat/long, can calculate straight-line distance traveled.

i didn't post sample data, two-column data frame of lat , long coordinates.

thanks can provide! if there's easy explanation somewhere on site or others missed, please point me in direction! couldn't find anything.

cheers

for x-y coordinates in same units (e.g. meters rather degrees of latitude , degrees of longitude), can use function data.frame of jump sizes , turning angles (in degrees).

getsteps <- function(x,y) {     d <- diff(complex(real = x, imaginary = y))     data.frame(size = mod(d),                 angle = c(na, diff(arg(d)) %% (2*pi)) * 360/(2*pi)) }  ## try out    set.seed(1) x <- rnorm(10) y <- rnorm(10) getsteps(x, y) #        size     angle # 1 1.3838360        na # 2 1.4356900 278.93771 # 3 2.9066189 101.98625 # 4 3.5714584 144.00231 # 5 1.6404354 114.73369 # 6 1.3082132 135.76778 # 7 0.9922699  74.09479 # 8 0.2036045 141.67541 # 9 0.9100189 337.43632  ## plot helps check works plot(x, y, type = "n", asp = 1) text(x, y, labels = 1:10) 

enter image description here


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -