# Color palette
bg_color <- "#FFFFFF"
light_blue <- "#DDEAF5"
mid_blue <- "#9BB8DC"
edge_color <- "#001E44" # Penn State Navy
# Draw a single unit cube at grid position (gx, gy, gz)
# Uses simple axonometric projection: x' = gx + 0.4*gz, y' = gy + 0.4*gz
draw_cube <- function(gx, gy, gz, fill = light_blue) {
s <- 1
dx <- 0.4 * s
dy <- 0.4 * s
px <- gx + dx * gz
py <- gy + dy * gz
# Front face
polygon(c(px, px + s, px + s, px),
c(py, py, py + s, py + s),
col = fill, border = edge_color, lwd = 1.2)
# Top face
polygon(c(px, px + s, px + s + dx, px + dx),
c(py + s, py + s, py + s + dy, py + s + dy),
col = fill, border = edge_color, lwd = 1.2)
# Right face (slightly darker for shading)
shade <- adjustcolor(fill, red.f = 0.92, green.f = 0.92, blue.f = 0.95)
polygon(c(px + s, px + s + dx, px + s + dx, px + s),
c(py, py + dy, py + s + dy, py + s),
col = shade, border = edge_color, lwd = 1.2)
}
# Alternating fill in 3D (checkerboard)
checker_fill <- function(i, j, k = 0) {
if ((i + j + k) %% 2 == 0) light_blue else mid_blue
}
par(mar = c(0, 0, 0, 0), bg = bg_color)
plot.new()
plot.window(xlim = c(0, 18), ylim = c(0, 6), asp = 1)
# 1. Vector: 1 x 3 row
ox <- 1; oy <- 2.2
for (i in 0:2) {
draw_cube(ox + i, oy, 0, fill = checker_fill(i, 0))
}
text(ox + 1.7, oy - 1, "Vector",
cex = 1.4, col = edge_color, font = 2)
# 2. Matrix: 3 x 3 grid
ox <- 7; oy <- 1
for (j in 0:2) {
for (i in 0:2) {
draw_cube(ox + i, oy + j, 0, fill = checker_fill(i, j))
}
}
text(ox + 1.7, oy - 1, "Matrix",
cex = 1.4, col = edge_color, font = 2)
# 3. Array: 3 x 3 x 3 cube — draw back-to-front, bottom-up, left-right
ox <- 13; oy <- 1
for (k in 2:0) {
for (j in 0:2) {
for (i in 0:2) {
draw_cube(ox + i, oy + j, k, fill = checker_fill(i, j, k))
}
}
}
text(ox + 2.3, oy - 1, "Array",
cex = 1.4, col = edge_color, font = 2)