From 87c2bf501913f380c41ae403abd21562177fb0c6 Mon Sep 17 00:00:00 2001 From: Maxim Vochten Date: Wed, 14 Aug 2024 22:17:53 +0200 Subject: [PATCH] doc --- examples/calculate_invariants_position.py | 2 +- invariants_py/invariants_handler.py | 45 ++++++++++++++--------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/examples/calculate_invariants_position.py b/examples/calculate_invariants_position.py index 3959630..c9fe670 100644 --- a/examples/calculate_invariants_position.py +++ b/examples/calculate_invariants_position.py @@ -16,7 +16,7 @@ invariants, progress, calc_trajectory, movingframes, progress_n = invariants_handler.calculate_invariants_translation(trajectory) # (Optional) Reconstruction of the trajectory from the invariants -reconstructed_trajectory, recon_mf = invariants_handler.reconstruct_trajectory(invariants, progress_n, p_init=calc_trajectory[0,:], mf_init=movingframes[0,:,:]) +reconstructed_trajectory, recon_mf = invariants_handler.reconstruct_trajectory(invariants, position_init=calc_trajectory[0,:], movingframe_init=movingframes[0,:,:]) print(recon_mf[1,:,:]) print(movingframes[1,:,:]) diff --git a/invariants_py/invariants_handler.py b/invariants_py/invariants_handler.py index c57c042..c1e479c 100644 --- a/invariants_py/invariants_handler.py +++ b/invariants_py/invariants_handler.py @@ -27,28 +27,39 @@ def calculate_invariants_translation(trajectory, progress_definition="arclength" return invariants, arclength, trajectory, movingframes, arclength_n -def reconstruct_trajectory(invariants, progress, p_init=np.zeros((3,1)), mf_init=np.eye(3)): +def reconstruct_trajectory(invariants, position_init=np.zeros((3,1)), movingframe_init=np.eye(3)): + """ + Reconstructs a position trajectory from its invariant representation starting from an initial position and moving frame. + + The initial position is the starting position of the trajectory. The initial moving frame encodes the starting direction (tangent and normal) of the trajectory. + + Parameters: + - invariants (numpy array of shape (N,3)): Array of vector invariants. + - p_init (numpy array of shape (3,1), optional): Initial position. Defaults to a 3x1 zero array. + - mf_init (numpy array of shape (3,3), optional): Initial frame matrix. Defaults to a 3x3 identity matrix. + + Returns: + - positions (numpy array of shape (N,3)): Array of reconstructed positions. + - R_frames (numpy array of shape (N,3,3)): Array of reconstructed moving frames. + """ - N = len(progress) + N = np.size(invariants, 0) + stepsize = 1/N positions = np.zeros((N,3)) R_frames = np.zeros((N,3,3)) - - stepsize = 1/N - print(stepsize) - - positions[0,:] = p_init - R_frames[0,:,:] = mf_init + + positions[0,:] = position_init + R_frames[0,:,:] = movingframe_init # Use integrator to find the other initial states for k in range(N-1): - - [R_plus1,p_plus1] = dyn.integrate_vector_invariants_position(mf_init, p_init, invariants[k,:], stepsize) - + [R_plus1, p_plus1] = dyn.integrate_vector_invariants_position(movingframe_init, position_init, invariants[k, :], stepsize) + positions[k+1,:] = np.array(p_plus1).T - R_frames[k+1,:,:] = np.array(R_plus1) - - p_init = p_plus1 - mf_init = R_plus1 - - return positions, R_frames \ No newline at end of file + R_frames[k+1,:,:] = np.array(R_plus1) + + position_init = p_plus1 + movingframe_init = R_plus1 + + return positions, R_frames