cart2pol | R Documentation |
Converts polar coordinates to cartesian coordinates
cart2pol(x, y, degrees = FALSE)
x |
The x-coordinate of the point |
y |
The y-coordinate of the point |
degrees |
Logical indicating if theta should be returned in degrees |
Converts polar coordinates to cartesian coordinates using a simple conversion. The angle, theta
must be in radians.
Somewhat inspired by http://www.r-bloggers.com/convert-polar-coordinates-to-cartesian/ and https://www.mathsisfun.com/polar-cartesian-coordinates.html
A data.frame holding the polar coordinates and the original (x,y) coordinates
Jared P. Lander
library(dplyr)
x1 <- c(1, sqrt(3)/2, sqrt(2)/2, 1/2, 0)
y1 <- c(0, 1/2, sqrt(2)/2, sqrt(3)/2, 1)
d1 <- tibble::tibble(x=x1, y=y1, Q='I')
x2 <- c(0, -1/2, -sqrt(2)/2, -sqrt(3)/2, -1)
y2 <- c(1, sqrt(3)/2, sqrt(2)/2, 1/2, 0)
d2 <- tibble::tibble(x=x2, y=y2, Q='II')
x3 <- c(-1, -sqrt(3)/2, -sqrt(2)/2, -1/2, 0)
y3 <- c(0, -1/2, -sqrt(2)/2, -sqrt(3)/2, -1)
d3 <- tibble::tibble(x=x3, y=y3, Q='III')
x4 <- c(0, 1/2, sqrt(2)/2, sqrt(3)/2, 1)
y4 <- c(-1, -sqrt(3)/2, -sqrt(2)/2, -1/2, 0)
d4 <- tibble::tibble(x=x4, y=y4, Q='IV')
dAll <- bind_rows(d1, d2, d3, d4)
cart2pol(dAll$x, dAll$y)
cart2pol(dAll$x, dAll$y, degrees=TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.