From df8023314e7633c83a7accc1a9fb834e76662929 Mon Sep 17 00:00:00 2001 From: Federico Pichi Date: Wed, 14 Oct 2020 10:53:30 +0200 Subject: [PATCH] Add tutorial-1-ffd.py --- tutorials/tutorial-1-ffd.py | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tutorials/tutorial-1-ffd.py diff --git a/tutorials/tutorial-1-ffd.py b/tutorials/tutorial-1-ffd.py new file mode 100644 index 0000000..7cec4cc --- /dev/null +++ b/tutorials/tutorial-1-ffd.py @@ -0,0 +1,40 @@ +import numpy as np +import mpl_toolkits.mplot3d +import matplotlib.pyplot as plt + +from pygem import FFD + + +def mesh_points(num_pts=2000): + indices = np.arange(0, num_pts, dtype=float) + 0.5 + + phi = np.arccos(1 - 2*indices/num_pts) + theta = np.pi * (1 + 5**0.5) * indices + + return np.array([np.cos(theta) * np.sin(phi), np.sin(theta) * np.sin(phi), np.cos(phi)]).T + + +mesh = mesh_points() +plt.figure(figsize=(8, 8)).add_subplot(111, projection='3d').scatter(*mesh.T) +plt.show() + +ffd = FFD([2, 2, 2]) +print(ffd) + +print('Movements of point[{}, {}, {}] along x: {}'.format(1, 1, 1, ffd.array_mu_x[1, 1, 1])) +print('Movements of point[{}, {}, {}] along z: {}'.format(1, 1, 1, ffd.array_mu_z[1, 1, 1])) + +ffd.array_mu_x[1, 1, 1] = 2 +ffd.array_mu_z[1, 1, 1] = 0.8 +print() +print('Movements of point[{}, {}, {}] along x: {}'.format(1, 1, 1, ffd.array_mu_x[1, 1, 1])) +print('Movements of point[{}, {}, {}] along z: {}'.format(1, 1, 1, ffd.array_mu_z[1, 1, 1])) + +new_mesh = ffd(mesh) +print(type(new_mesh), new_mesh.shape) + + +ax = plt.figure(figsize=(8, 8)).add_subplot(111, projection='3d') +ax.scatter(*new_mesh.T) +ax.scatter(*ffd.control_points().T, s=50, c='red') +plt.show()