Files
epfl-archive/cs457-gc/assignment_3_1/notebook/smooth_surfaces.ipynb
T
2022-04-07 18:46:57 +02:00

18 KiB

Assignment 3.1: Differential Geometry of smooth surfaces

In [1]:
import numpy as np
import sys
print(sys.executable)
import meshplot as mp
sys.path.append('../src/')
from smooth_surfaces import *
from utils import *
/opt/conda/bin/python

Paraboloid surface

To evaluate the paraboloid surface, we first sample the domain \Omega with a regular grid. For that, we specify the u and v intervals, and the sampling in the two directions:

In [2]:
u_interval = [-1, 1]
v_interval = [-1, 1]
u_sampling = 21
v_sampling = 21

We use now the following provided function that creates the points p\in\Omega\subseteq\mathbb R^2, collected in the array P, and a triangulation F for visualization:

In [3]:
P, F = uv_grid(u_interval, v_interval, u_sampling, v_sampling)

We can now choose the parameters of the paraboloid:

In [164]:
a = 0.2
b = 0.2
c = -0.2
d = -0.2
e = 0

Try to change the parameters to get and then compute the corresponding paraboloid points \mathbf x(p)\in\mathbb R^3 and the derivatives of the parametrization at that points:

In [165]:
x = compute_paraboloid_points(P, a, b, c, d, e)

x_u, x_v = compute_paraboloid_first_derivatives(P, a, b, c, d, e)

x_uu, x_uv, x_vv = compute_paraboloid_second_derivatives(P, a, b, c, d, e)

Principal curvatures

We define now a function that computes the principal curvatures of the surface at the points by using your functions:

In [166]:
def principal_curvatures(x_u, x_v, x_uu, x_uv, x_vv):

    n = compute_surface_normal(x_u, x_v)

    I = compute_first_fundamental_form(x_u, x_v)

    II = compute_second_fundamental_form(x_uu, x_uv, x_vv, n)

    S = compute_shape_operator(I, II)

    return compute_principal_curvatures(S, x_u, x_v)

and use it to evaluate the principal curvatures \kappa_1 and \kappa_2 with the corresponding principal directions \mathbf e_1 and \mathbf e_2 at each surface point:

In [167]:
k_1, k_2, e_1, e_2 = principal_curvatures(x_u, x_v, x_uu, x_uv, x_vv)

We can compute now the Gaussian curvature K and the mean curvature H as

In [168]:
K = k_1 * k_2

H = (k_1 + k_2)/2

To display the surface and the curvature, we define a plot function that colors points according to the curvature values with a blue-green-red color scale, with blue for negative values, green for zero, and red for positive values.

In [169]:
def plot_curvature(x, F, values):
    color = bgr_color(values)
    shading_options = {
        "flat":False,
        "wireframe":False,
        "metalness": 0,
    }
    mp.plot(x, F, c=color, shading=shading_options)

and use it to visualize the Gaussian curvature of the surface

In [170]:
plot_curvature(x, F, K)
Renderer(camera=PerspectiveCamera(children=(DirectionalLight(color='white', intensity=0.6, position=(3.1415927…

and the mean curvature

In [171]:
plot_curvature(x, F, H)
Renderer(camera=PerspectiveCamera(children=(DirectionalLight(color='white', intensity=0.6, position=(3.1415927…

We want now to visualize directions on the surface. For that define the plot function

In [172]:
def plot_directions(x, F, d_1, d_2, scale=0.1):
    color = np.ones((len(x), 3))
    shading_options = {
        "flat": False,
        "wireframe":False,
        "metalness": 0.05,
    }
    p = mp.plot(x, F, c=color, shading=shading_options)
    p.add_lines(x+d_1*scale, x-d_1*scale, shading={"line_color": "red"})
    p.add_lines(x+d_2*scale, x-d_2*scale, shading={"line_color": "blue"})
    p.update_object()

We can now display the principal curvature directions.

In [173]:
plot_directions(x, F, e_1, e_2, scale=0.08)
Renderer(camera=PerspectiveCamera(children=(DirectionalLight(color='white', intensity=0.6, position=(3.1415927…

Asymptotic directions

We estimate now the asymptotic directions

In [174]:
a_1, a_2 = compute_asymptotic_directions(k_1, k_2, e_1, e_2)

and display them

In [175]:
plot_directions(x, F, a_1, a_2, scale=0.08)
Renderer(camera=PerspectiveCamera(children=(DirectionalLight(color='white', intensity=0.6, position=(3.1415927…

Torus surface

We display now the same quantities for thr torus surface, and start defining the domain interval and sampling

In [16]:
u_interval = [0, 2*np.pi]
v_interval = [0, 2*np.pi]
u_sampling = 33
v_sampling = 33

We now create an $u$-v grid

In [17]:
P, F = uv_grid(u_interval, v_interval, u_sampling, v_sampling)

and choose the torus radii

In [18]:
R = 2

r = 1

We can now proceed as for the paraboloid:

In [19]:
x = compute_torus_points(P, R, r)

x_u, x_v = compute_torus_first_derivatives(P, R, r)

x_uu, x_uv, x_vv = compute_torus_second_derivatives(P, R, r)

Principal curvatures

In [20]:
k_1, k_2, e_1, e_2 = principal_curvatures(x_u, x_v, x_uu, x_uv, x_vv)
In [21]:
K = k_1 * k_2

H = (k_1 + k_2)/2

We plot now the Gaussian curvature K

In [22]:
plot_curvature(x, F, K)
Renderer(camera=PerspectiveCamera(children=(DirectionalLight(color='white', intensity=0.6, position=(0.0, 0.0,…

the mean curvature H

In [23]:
plot_curvature(x, F, H)
Renderer(camera=PerspectiveCamera(children=(DirectionalLight(color='white', intensity=0.6, position=(0.0, 0.0,…

and the principal curvature directions \mathbf e_1 and \mathbf e_2

In [24]:
plot_directions(x, F, e_1, e_2, scale=0.12)
Renderer(camera=PerspectiveCamera(children=(DirectionalLight(color='white', intensity=0.6, position=(0.0, 0.0,…

Asymptotic directions

Finally, we can plot the asymptotic directions

In [25]:
a_1, a_2 = compute_asymptotic_directions(k_1, k_2, e_1, e_2)
../src/smooth_surfaces.py:418: RuntimeWarning: invalid value encountered in sqrt
  sinT = np.sqrt(f)
In [26]:
plot_directions(x, F, a_1, a_2, scale=0.12)
Renderer(camera=PerspectiveCamera(children=(DirectionalLight(color='white', intensity=0.6, position=(0.0, 0.0,…
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: