Last active
August 21, 2025 18:55
-
-
Save ericnovik/a7e8faad9c4c84ae4378c384e1a3b044 to your computer and use it in GitHub Desktop.
Uniform circular motion
This file contains hidden or 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
| # x direction | |
| x_t <- function(R, omega, t) { R * cos(omega * t) } | |
| v_x <- function(R, omega, t) { -R * omega * sin(omega * t) } | |
| a_x <- function(R, omega, t) { -R * omega^2 * cos(omega * t) } | |
| # y direction | |
| y_t <- function(R, omega, t) { R * sin(omega * t) } | |
| v_y <- function(R, omega, t) { R * omega * cos(omega * t) } | |
| a_y <- function(R, omega, t) { -R * omega^2 * sin(omega * t) } | |
| # Radius of orbit | |
| R <- 1 | |
| # Angular speed | |
| w <- 2 # radians per second | |
| # full cycle when T = 2*pi/omega | |
| T <- 2*pi/w | |
| L <- 100 | |
| t <- seq(0, T, len = L) | |
| library(tidyverse) | |
| d <- tibble(t = t, | |
| x = x_t(R, w, t), | |
| vx = v_x(R, w, t), | |
| ax = a_x(R, w, t), | |
| y = y_t(R, w, t), | |
| vy = v_y(R, w, t), | |
| ay = a_y(R, w, t)) | |
| theme_set(theme_minimal()) | |
| ggplot(data = d, aes(t, x)) + geom_line() + | |
| geom_line(aes(t, y), color = 'red') | |
| ggplot(d, aes(x, y)) + geom_path(linewidth = 0.2) | |
| library(grid) | |
| d_sub <- d |> filter(row_number() %% 2 != 1) | |
| ggplot(d_sub, aes(x = x, y = y)) + | |
| geom_segment(aes(xend = x + vx/4, yend = y + vy/4), | |
| arrow = arrow(length = unit(0.1, "cm")), | |
| color = 'green') + | |
| geom_segment(aes(xend = x + ax/16, yend = y + ay/16), | |
| arrow = arrow(length = unit(0.1, "cm")), | |
| color = 'red', linewidth = 0.2) + | |
| geom_point(x = 0, y = 0) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment