Created
July 5, 2021 08:19
-
-
Save k-hench/b43fb0dbe56f592bf42a93fb9dcd824c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(ggforce) | |
n <- 6 | |
tibble(t = seq(0, 2*pi,length.out = n+1)[0:(n+1)], | |
x = sin(t), y = cos(t), z = x + 1i * y) %>% | |
mutate(angle = Arg(z - lag(z)), | |
len = Mod(z - lag(z)), | |
shift_x = cos(angle) * len, | |
shift_y = sin(angle) * len) %>% | |
ggplot(aes(x = Re(z), y = Im(z))) + | |
ggforce::geom_circle(inherit.aes = FALSE, | |
aes(x0 = Re(z), y0 = Im(z), r = len), | |
color = "lightgray") + | |
geom_point()+ | |
geom_segment(aes(xend = Re(z) + sqrt(len^2/2), | |
yend = Im(z) + sqrt(len^2/2)), | |
color = "red") + | |
geom_segment(aes(xend = Re(z) - shift_x, | |
yend = Im(z) - shift_y), | |
color = "black") + | |
coord_equal() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment