DF <-read.csv("Toma3.csv")
View(DF)
library(ggplot2)

*Graficas theta vs t, w vs t y alpha vs t

colnames(DF)[colnames(DF) == "Último..Tiempo..s."] <- "tiempo"
colnames(DF)[colnames(DF) == "Último..Angulo..rad."] <- "angulo"

ggplot(DF, aes(x = tiempo, y = angulo)) +
  geom_line(color = "red") +
  labs(title = "Ángulo vs Tiempo",
       x = "Tiempo (s)",
       y = "Ángulo (rad)") +
  theme_minimal()

colnames(DF)[colnames(DF) == "Último..Velocidad..rad.s."] <- "velocidad_angular"
colnames(DF)[colnames(DF) == "Último..Aceleración..rad.s.."] <- "aceleracion_angular"

ggplot(DF, aes(x = tiempo, y = velocidad_angular)) +
  geom_line(color = "green") +
  labs(title = "Velocidad angular vs Tiempo",
       x = "Tiempo (s)",
       y = "Velocidad angular (rad/s)") +
  theme_minimal()

ggplot(DF, aes(x = tiempo, y = aceleracion_angular)) +
  geom_line(color = "blue") +
  labs(title = "Aceleración angular vs Tiempo",
       x = "Tiempo (s)",
       y = "Aceleración angular (rad/s²)") +
  theme_minimal()

idx_max <- which.max(DF$angulo)

# 2. Crea un nuevo data frame con sólo las filas hasta ese instante
DF_trimmed <- DF[1:idx_max, ]

# (Opcional) Si prefieres sobrescribir DF:
DF <- DF[1:idx_max, ]

*Datos

m_c      <- 1.02068

m_disco_inercia <- 0.10614
r_disco_inercia <- 0.0417

r1_pf <- 0.02368
r2_pf <- 0.014145
m_pf <- 0.00769

r_pm <-  0.02368
m_pm <- 0.02368
I_pm <- 1.16e-6

m_pp <- 0.04972

m_mad <- 0.01992

*Energía cinética del carrito

DF$v_cart     <- r1_pf * DF$velocidad_angular

DF$K_cart_tras <- 0.5 * (m_c + m_pm) * DF$v_cart^2

DF$K_pm_rot   <- 0.5 * I_pm * (DF$velocidad_angular * r1_pf / r_pm)^2

DF$K_cart     <- DF$K_cart_tras + DF$K_pm_rot

DF$DeltaK     <- DF$K_cart - DF$K_cart[1]

ggplot(DF, aes(x = tiempo, y = DeltaK)) +
  geom_line(color = "purple", size = 1) +
  labs(
    title = "Cambio de Energía Cinética del Carrito",
    x     = "Tiempo (s)",
    y     = expression(Delta~K[carrito]~"(J)")
  ) +
  theme_minimal()
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.

*Energía cinética de la polea fija y el disco de inercia

DF$k_pf <- 0.25 * m_pf * (r1_pf^2 + r2_pf^2) * DF$velocidad_angular^2
DF$k_disco_inercia <- 0.25 * m_disco_inercia * r_disco_inercia^2 * DF$velocidad_angular^2

DF$k_dpf <- DF$k_pf + DF$k_disco_inercia

DF$DeltaK_dpf <- DF$k_dpf - DF$k_dpf[1]

ggplot(DF, aes(x = tiempo, y = DeltaK_dpf)) +
  geom_line(color = "red", size = 1) +
  labs(
    title = "Cambio de Energía Cinética (Disco de inercia + Polea fija)",
    x     = "Tiempo (s)",
    y     = expression(Delta~K[disco+polea]~"(J)")
  ) +
  theme_minimal()

*Energía cinética del porta-pesa y la masa adicional

DF$v_masa <- r2_pf*DF$velocidad_angular
DF$K_masa_ppesa <- 0.5*(m_mad + m_pp)*DF$v_masa^2
DF$DeltaK_mpp    <- DF$K_masa_ppesa - DF$K_masa_ppesa[1]

ggplot(DF, aes(x = tiempo, y = DeltaK_mpp)) +
  geom_line(color = "orange", size = 1) +
  labs(
    title = "Cambio de Energía Cinética (Masa Adicional + Porta-Pesa)",
    x     = "Tiempo (s)",
    y     = expression(Delta~K[masa+pp]~"(J)")
  ) +
  theme_minimal()

*Trabajo neto del sistema

DF$K_total <- DF$K_cart + DF$k_dpf + DF$K_masa_ppesa

DF$W_net <- DF$K_total - DF$K_total[1]


ggplot(DF, aes(x = tiempo, y = W_net)) +
  geom_line(color = "darkred", size = 1) +
  labs(
    title = "Trabajo Neto del Sistema vs. Tiempo",
    x     = "Tiempo (s)",
    y     = expression(W[net]~"(J)")
  ) +
  theme_minimal()

*t vs v pesa y masa adicional

ggplot(DF, aes(x = tiempo, y = v_masa)) +
  geom_line(color = "darkblue", size = 1) +
  labs(
    title = "Velocidad de la masa vs. Tiempo",
    x     = "Tiempo (s)",
    y     = expression(v[masa]~"(m/s)")
  ) +
  theme_minimal()