3D Model of the Stanley Thermos

2025-05-07

```{r setup_chunk, include=FALSE} # Changed label to setup_chunk # Load required libraries knitr::opts_chunk$set(echo = FALSE) # Set echo to FALSE to hide code by default library(plotly) library(pracma)

Define geometric parameters

altura_total <- 358 # mm radio_externo <- 47 # mm

Function to calculate the radius based on height

radio <- function(y) { sapply(y, function(y_val) { if (y_val < radio_externo) { # Semiesfera inferior return(sqrt(radio_externo^2 - (y_val - radio_externo)^2)) } else if (y_val > altura_total - radio_externo) { # Semiesfera superior return(sqrt(radio_externo^2 - (y_val - (altura_total - radio_externo))^2)) } else { # Cuerpo cilíndrico return(radio_externo) } }) }

Generate data for 3D plot

y_vals <- seq(0, altura_total, length.out = 500) theta <- seq(0, 2 * pi, length.out = 100) X <- sapply(y_vals, function(y) radio(y) * cos(theta)) Z <- sapply(y_vals, function(y) radio(y) * sin(theta)) Y <- outer(y_vals, rep(1, length(theta)), FUN = function(y, theta) y)

Create 3D plot

p <- plot_ly(x = ~X, y = ~Y, z = ~Z, type = “surface”, colorscale = “Viridis”, showscale = FALSE) %>% layout(title = “3D Model of the Stanley Thermos”, scene = list(xaxis = list(title = “X (mm)”), yaxis = list(title = “Y (mm)”), zaxis = list(title = “Z (mm)”)))

p # This will display the plot in the slide