library(ggplot2)

a <- 150
b <- 75

atan_ba <- atan(b / a)
theta1 <- seq(-atan_ba, atan_ba, length.out = 100)
theta2 <- seq(atan_ba, pi - atan_ba, length.out = 100)
theta3 <- seq(pi - atan_ba, pi + atan_ba, length.out = 100)
theta4 <- seq(pi + atan_ba, 2 * pi - atan_ba, length.out = 100)

r1 <- a / abs(cos(theta1))
r2 <- b / abs(sin(theta2))
r3 <- a / abs(cos(theta3))
r4 <- b / abs(sin(theta4))

theta <- c(theta1, theta2, theta3, theta4)
r <- c(r1, r2, r3, r4)

x <- r * cos(theta)
y <- r * sin(theta)

data <- data.frame(x = x, y = y)

ggplot(data, aes(x = x, y = y)) +
  geom_path(color = "blue", size = 1.2) +
  coord_equal() +
  theme_minimal() +
  labs(title = "Rectangle using polar/parametric equations",
       x = "x",
       y = "y") +
  theme(plot.title = element_text(hjust = 0.5))

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: