Skip to content

Instantly share code, notes, and snippets.

@onesandzeroes
Created February 14, 2013 03:43
Show Gist options
  • Save onesandzeroes/4950468 to your computer and use it in GitHub Desktop.
Save onesandzeroes/4950468 to your computer and use it in GitHub Desktop.
<3
require(lattice)
hrt <- function(x, y) {
x^2 + (y-(x^2)^(1/3))^2
}
hrt_mat <- matrix(10000, nrow=100, ncol=100)
x_vals <- seq(-1, 1, length.out=100)
y_vals <- seq(-1, 1.5, length.out=100)
for (x in seq(1:nrow(hrt_mat))) {
for (y in seq(1:ncol(hrt_mat))) {
hrt_mat[x, y] <- hrt(x_vals[x], y_vals[y])
}
}
hrt_cols <- colorRampPalette(c("darkred", "pink"))
levelplot(hrt_mat, pretty=TRUE, col.regions=hrt_cols(150), colorkey=FALSE)
library(rgl)
cols_3d <- hrt_cols(length(hrt_mat_m$value))
hrt_mat_m <- hrt_mat_m[order(hrt_mat_m$value), ]
hrt_mat_m$cols_3d <- cols_3d
plot3d(hrt_mat_m$Var1, hrt_mat_m$Var2, hrt_mat_m$value, col=hrt_mat_m$cols_3d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment