Funkcije dvije varijable

Funkcije dviju varijabli - vizualni primjeri u 3D-u

Vulkanska funkcija

library(plotly)
Loading required package: ggplot2

Attaching package: 'plotly'
The following object is masked from 'package:ggplot2':

    last_plot
The following object is masked from 'package:stats':

    filter
The following object is masked from 'package:graphics':

    layout
# Definiramo mrežu
x <- seq(-3, 3, length.out = 200)
y <- seq(-3, 3, length.out = 200)
grid <- expand.grid(x = x, y = y)
z <- matrix(exp(-(grid$x^2 + grid$y^2)) * sin(5 * sqrt(grid$x^2 + grid$y^2)), nrow = 200, ncol = 200)

# 3D površina
plot_ly(x = x, y = y, z = z) %>%
  add_surface(colorscale = "Plasma") %>%
  layout(scene = list(
    xaxis = list(title = ""),
    yaxis = list(title = ""),
    zaxis = list(title = "Height")
  ))

Ripple / Wave funkcija u 3D

z <- matrix(sin(sqrt(grid$x^2 + grid$y^2)), nrow = 200, ncol = 200)

plot_ly(x = x, y = y, z = z) %>%
  add_surface(colorscale = "Magma") %>%
  layout(scene = list(
    xaxis = list(title = ""),
    yaxis = list(title = ""),
    zaxis = list(title = "Amplitude")
  ))

Fraktalni teren / planine (Perlin noise)

library(ambient)

grid_noise <- long_grid(x = seq(-3, 3, length.out = 200),
                        y = seq(-3, 3, length.out = 200))

grid_noise$z <- fracture(
  noise = gen_perlin,
  fractal = fbm,
  octaves = 5,
  frequency = 1,
  x = grid_noise$x,
  y = grid_noise$y
)

z <- matrix(grid_noise$z, nrow = 200, ncol = 200)

plot_ly(x = x, y = y, z = z) %>%
  add_surface(colorscale = "Cividis") %>%
  layout(scene = list(
    xaxis = list(title = ""),
    yaxis = list(title = ""),
    zaxis = list(title = "Height")
  ))