Skip to content

Commit

Permalink
doc
Browse files Browse the repository at this point in the history
  • Loading branch information
maximvochten committed Aug 14, 2024
1 parent 7d5027a commit 87c2bf5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
2 changes: 1 addition & 1 deletion examples/calculate_invariants_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,:,:])
Expand Down
45 changes: 28 additions & 17 deletions invariants_py/invariants_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
R_frames[k+1,:,:] = np.array(R_plus1)

position_init = p_plus1
movingframe_init = R_plus1

return positions, R_frames

0 comments on commit 87c2bf5

Please sign in to comment.