6fbec8f3创建于 2022年6月24日历史提交

Function Surface

Examples

  1. Plotting a simple function.

::

fsurf({x, y => sin(x) + cos(y)})

Result:

.. image:: ../../../tests/imgs/function_surface/function_surface_1.png :align: center :width: 360

  1. Plotting two functions side-by-side in the same axis.

::

fsurf({x, y => erf(x) + cos(y)}, xmin:-5.0, xmax:0.0, ymin:-5.0, ymax:5.0)
hold(true)
fsurf({x, y => sin(x) + cos(y)}, xmin:0.0, xmax:5.0, ymin:-5.0, ymax:5.0)
hold(false)

Result:

.. image:: ../../../tests/imgs/function_surface/function_surface_2.png :align: center :width: 360

  1. Plotting a parameterized surface.

::

let r = {u: Float64, v: Float64 => 2.0 + sin(7.0 * u + 5.0 * v)}
let fx = {u: Float64, v: Float64 => r(u, v) * cos(u) * sin(v)}
let fy = {u: Float64, v: Float64 => r(u, v) * sin(u) * sin(v)}
let fz = {u: Float64, v: Float64 => r(u, v) * cos(v)}
fsurf(fx, fy, fz, smin: 0.0, smax: 2.0 * PI64, tmin: 0.0, tmax: PI64).lighting(true)

Result:

.. image:: ../../../tests/imgs/function_surface/function_surface_3.png :align: center :width: 360

  1. Plotting with custom title, label, ticks, and tick-labels.

::

fsurf({x, y => y * sin(x) - x * cos(y)}, xmin:-2.0*PI64, xmax:2.0*PI64, ymin:-2.0*PI64, ymax:2.0*PI64)
title("ysin(x) - xcos(y) for x and y in [-2π,2π]")
xlabel("x")
ylabel("y")
zlabel("z")
box(true)

xticks(linspace(-2.0 * PI64, 2.0 * PI64, num: 9))
xticklabels(["-2π", "-3π/2", "-π", "-π/2", "0", "π/2", "π", "3π/2", "2π"])
yticks(linspace(-2.0 * PI64, 2.0 * PI64, num: 9))
yticklabels(["-2π", "-3π/2", "-π", "-π/2", "0", "π/2", "π", "3π/2", "2π"])

Result:

.. image:: ../../../tests/imgs/function_surface/function_surface_4.png :align: center :width: 360

  1. Plotting a parameterized surface with custom edge color.

::

let fx = {u: Float64, v: Float64 => u * sin(v)}
let fy = {u: Float64, v: Float64 => -u * cos(v)}
let fz = {u: Float64, v: Float64 => v}
fsurf(fx, fy, fz, smin:-5.0, smax:5.0, tmin:-5.0, tmax:-2.0).edge_color("g")
hold(true)
fsurf(fx, fy, fz, smin:-5.0, smax:5.0, tmin:-2.0, tmax:2.0).edge_color("none")
hold(false)

Result:

.. image:: ../../../tests/imgs/function_surface/function_surface_5.png :align: center :width: 360

  1. Plotting a parameterized surface with custom face alpha.

::

let fx = {u: Float64, v: Float64 => exp(-abs(u) / 10.0) * sin(5.0 * abs(v))}
let fy = {u: Float64, v: Float64 => exp(-abs(u) / 10.0) * cos(5.0 * abs(v))}
let fz = {u: Float64, v: Float64 => u}
fsurf(fx, fy, fz, smin:-30.0, smax:30.0, tmin:-30.0, tmax:30.0).face_alpha(0.5)

Result:

.. image:: ../../../tests/imgs/function_surface/function_surface_6.png :align: center :width: 360

  1. Plotting a surface with contour base.

::

fsurf(peaks, xmin:-3.0, xmax:3.0, ymin:-3.0, ymax:3.0).contour_base(true)

Result:

.. image:: ../../../tests/imgs/function_surface/function_surface_7.png :align: center :width: 360

  1. Comparison of different settings of mesh density.

::

let fx = {s: Float64, t: Float64 => sin(s)}
let fy = {s: Float64, t: Float64 => cos(s)}
let fz = {s: Float64, t: Float64 => t / 10.0 * sin(1.0 / s)}
tiledlayout(2, 1)
nexttile()
fsurf(fx, fy, fz, smin:-5.0, smax:5.0, tmin:-5.0, tmax:5.0, mesh_density:20)
view(-172.0, 25.0)
title("Decreased Mesh Density")

nexttile()
fsurf(fx, fy, fz, smin:-5.0, smax:5.0, tmin:-5.0, tmax:5.0, mesh_density:50)
view(-172.0, 25.0)
title("Increased Mesh Density")

Result:

.. image:: ../../../tests/imgs/function_surface/function_surface_8.png :align: center :width: 360