10 KiB
10 KiB
In [1]:
import numpy as np
import igl
import meshplot as mp
import sys as _sys
_sys.path.append("../src")
from elasticsolid import *
from eigendecomposition_metric import *
shadingOptions = {
"flat":True,
"wireframe":False,
}
rot = np.array(
[[1, 0, 0 ],
[0, 0, 1],
[0, -1, 0 ]]
)In [2]:
v, _, _, t, _, _ = igl.read_obj("../data/dinosaur.obj")
# t = np.array([
# [0, 1, 2, 3],
# [1, 2, 3, 4]
# ])
# v = np.array([
# [0., 0., 0.],
# [1., 0., 0.],
# [0., 1., 0.],
# [0., 0., 1.],
# [2/3, 2/3, 2/3]
# ])
aabb = np.max(v, axis=0) - np.min(v, axis=0)
length_scale = np.mean(aabb)
p = mp.plot(v @ rot.T, t, shading=shadingOptions)Renderer(camera=PerspectiveCamera(children=(DirectionalLight(color='white', intensity=0.6, position=(-1.987469…
In [3]:
rho = 131 # [kg.m-3]
solid = ElasticSolid(v, t, rho=rho)In [4]:
v_def = v.copy()
v_def[:, 2] *= 2.
solid.update_def_shape(v_def)
mp.plot(solid.v_def @ rot.T, solid.t, shading=shadingOptions)Out [4]:
Renderer(camera=PerspectiveCamera(children=(DirectionalLight(color='white', intensity=0.6, position=(-1.987469…
<meshplot.Viewer.Viewer at 0x7fa7dc789070>
In [11]:
# We limit ourselves to stretching the mesh in the z direction
# Feel free to experiment with other kinds of deformations!
v_def = v.copy()
v_def[:, 2] *= 2.0
solid.update_def_shape(v_def)
squared_eigvals, eigvecs = compute_eigendecomposition_metric(solid.F)
plot_eigendecomposition_metric(solid, squared_eigvals, eigvecs, rot, scale=0.05)Renderer(camera=PerspectiveCamera(children=(DirectionalLight(color='white', intensity=0.6, position=(-1.987469…
In [6]:
maxZ = np.max(solid.v_rest[:, 2])
pin_idx = np.arange(solid.v_rest.shape[0])[solid.v_rest[:, 2] > maxZ - 0.1 * aabb[2]]
v_def = v.copy()
v_def[:, 2] -= 0.1 * aabb[2]
solid.update_def_shape(v_def)
solid_pinned = ElasticSolid(v, t, rho=rho, pin_idx=pin_idx)
solid_pinned.update_def_shape(v_def)In [7]:
p = mp.plot(solid_pinned.v_def @ rot.T, t, shading=shadingOptions)
p.add_points(solid_pinned.v_def[pin_idx, :] @ rot.T, shading={"point_color":"black", "point_size": 0.1 * length_scale})Out [7]:
Renderer(camera=PerspectiveCamera(children=(DirectionalLight(color='white', intensity=0.6, position=(-1.987469…
1
In [ ]: