Generate meshes
In the following, we show how to generate meshes for various manifolds using the utilities in jnlr.utils.meshes.
3D Explicit parameterization
The following examples take in a parameterization function and generate a mesh by evaluating the function on a grid.
The functions must be in the form f(U) where U is a tuple of parameters (u, v) and the output is either a scalar or a 3D point (x, y, z).
3D Explicit, scalar output, standard parametrization
The following example generates a mesh for the Shubert function, which is a standard test function for optimization.
The parametrization is the standard euclidean one, i.e., the output is a scalar value z = f(x, y).
from jnlr.utils.plot_utils import plot_mesh_plotly
from jnlr.utils.meshes import get_mesh
from jnlr.utils.manifolds import f_shubert
import os
PLOT_W = 400
PLOT_H = 400
os.environ['JAX_PLATFORMS'] = "cpu" # use "cuda" if you have a GPU
os.environ['JAX_ENABLE_X64'] = "1"
V, F = get_mesh(f_shubert, 'explicit', nu=50, nv=50, grid_ranges=((-1, 1), (-1, 1)))
plot_mesh_plotly(V, F, title="Shubert function", width=PLOT_W, height=PLOT_H)
3D Explicit, angular parametrization
The following example generates a mesh for a torus, which is a standard example of a manifold with angular parameters.
The parametrization is given by the function phi_torus(U) below, which maps the angular parameters u and v to 3D coordinates (x, y, z).
import numpy as np
import jax.numpy as jnp
R, r = 2.0, 0.7
def phi_torus(U):
u, v = U
cu, su = jnp.cos(u), jnp.sin(u)
cv, sv = jnp.cos(v), jnp.sin(v)
x = (R + r*cv) * cu
y = (R + r*cv) * su
z = r * sv
return jnp.stack([x, y, z])
V, F = get_mesh(phi_torus, 'explicit', nu=50, nv=50, grid_ranges=((0, 2*np.pi), (0, 2*np.pi)))
plot_mesh_plotly(V, F, title="Torus function", width=PLOT_W, height=PLOT_H)