RosettaCodeData/Task/Draw-a-sphere/R/draw-a-sphere.r
2026-04-30 12:34:36 -04:00

12 lines
384 B
R

library(lattice)
theta <- seq(0, pi, length.out=100)
phi <- seq(0, 2*pi, length.out=100)
x <- outer(sin(theta), cos(phi))
y <- outer(sin(theta), sin(phi))
z <- sqrt(1-x^2-y^2)
xx <- kronecker(matrix(1, 2, 2), x)
yy <- kronecker(matrix(1, 2, 2), y)
zz <- kronecker(matrix(c(1, -1, -1, 1), 2, 2), z)
png(filename="Sphere-R.png", width=1000, height=1000)
wireframe(zz ~ xx*yy)
dev.off()