This Rpubs is translated from my blog: https://nicolapuletti.wordpress.com/2013/08/23/plant-positioning-from-polar-to-cartesian-coord/.
Polar coordinates are sometimes collected on the field to measure the
position of the trees. They are azimuth and distance from a reference
point (typically the center of a circular plot) to a target tree.
This Rpubs deals with how to transform Polar Coordinates to Cartesian Coordinates, maintaining the y-axis as the North.
Knowing the angle from the North (alpha in the figure) and the distance (d) between the reference point and the target tree, the x-coord (x) and the y-coord can be calculated as follows:
x = d * sin(alpha)
y= d * cos(alpha)
Here following we simulate a field data collection over a 13 meters radius circular plot, with 20 trees found.
library(tidyverse)
n.trees <- 20
plot_radius <- 13
set.seed(5)
field_data = tibble(
tree.id = as.character(1:n.trees),
azimuth_deg = runif(n.trees, min = 0, max = 360),
dist_m = runif(n.trees, min = 0, max = plot_radius)
)
field_data
## # A tibble: 20 × 3
## tree.id azimuth_deg dist_m
## <chr> <dbl> <dbl>
## 1 1 72.1 11.6
## 2 2 247. 9.37
## 3 3 330. 2.75
## 4 4 102. 2.93
## 5 5 37.7 1.82
## 6 6 252. 6.24
## 7 7 190. 5.69
## 8 8 291. 12.6
## 9 9 344. 1.84
## 10 10 39.8 12.4
## 11 11 98.4 5.78
## 12 12 177. 0.772
## 13 13 115. 3.58
## 14 14 201. 0.405
## 15 15 94.5 0.188
## 16 16 72.7 6.33
## 17 17 140. 7.74
## 18 18 320. 7.77
## 19 19 200. 5.17
## 20 20 303. 5.16
Applying the functions for conversion presented here above, the result is:
library(ggforce)
field_data |>
dplyr::mutate(
azimuth_rad = azimuth_deg*pi/180,
x = dist_m*sin(azimuth_rad),
y = dist_m*cos(azimuth_rad)
) |>
ggplot(aes(x, y)) +
geom_point() +
coord_equal() +
xlim(-15,15) +
ylim(-15,15) +
geom_circle(aes(x0 = 0, y0 = 0, r = 13),
linewidth = 1, linetype='dashed', color='red')