Skip to content

Instantly share code, notes, and snippets.

@abikoushi
Created December 3, 2024 23:06
Show Gist options
  • Save abikoushi/0506f7dd409e1756f84e4c8016564296 to your computer and use it in GitHub Desktop.
Save abikoushi/0506f7dd409e1756f84e4c8016564296 to your computer and use it in GitHub Desktop.
rotation matrix with dino
library(datasauRus)
library(ggplot2)
library(dplyr)
library(gganimate)
rot <-function(th) {
matrix(c(cos(th),-sin(th),
sin(th),cos(th)), byrow = TRUE, nrow = 2)
}
dino <- dplyr::filter(datasaurus_dozen, dataset=="dino") %>%
dplyr::select(-dataset) %>%
as.matrix()
rotate_dino <- function(theta){
data.frame(dino%*%rot(theta), theta=theta)
}
theta <- seq(0,2*pi, length.out=16)
dinos <- bind_rows(lapply(theta, rotate_dino))
ggplot(data = dinos, aes(x = X1, y = X2))+
geom_point()+
theme_classic()+
coord_fixed()+
transition_time(theta)
anim_save("rotate_dino.gif")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment