import numpy as np from scipy.optimize import curve_fit import artoolkitplus as ar from keras.models import Sequential from keras.layers import Dense, Dropout from functools import lru_cache @lru_cache(maxsize=1000) def smooth_attitude_interpolation(Cs, Cf, ωs, ωf, T): """ Smoothly interpolates between two attitude matrices Cs and Cf. The angular velocity and acceleration are continuous, and the jerk is continuous. Args: Cs: The initial attitude matrix. Cf: The final attitude matrix. ωs: The initial angular velocity. ωf: The final angular velocity. T: The time interval between Cs and Cf. Returns: A list of attitude matrices that interpolate between Cs and Cf.
θ = np.linspace(0, T, 3) def rotation_vector(t): return np.log(Cs.T @ Cf) θ_poly, _ = curve_fit(rotation_vector, θ, np.zeros_like(θ), maxfev=100000)
ω = np.diff(θ_poly) / θ ω_̇ = np.diff(ω) / θ
ω_̇[0] = ω_̇[-1]
ω = np.linalg.solve(np.diag(1 / θ) + np.diag(ω_̇), ωs - ωf)
C = np.exp(θ_poly @ np.linalg.inv(np.diag(θ)))
C = C * np.exp(-1j * 2 * np.pi * T)
scene = ar.Scene()
for c in C: marker = ar.Marker(c) scene.add_marker(marker)
sphere = ar.Sphere(0.2) sphere.set_position(np.array([0, 0, 0])) scene.add_object(sphere)
def rotate_sphere(t): sphere.set_rotation(C[int(t)])
ar.render_with_metal(scene, animate=rotate_sphere)
analytics.send_event('AR', 'FoldSpace')
rk.render_scene(scene) return ω_pred if name == 'main':
Cs = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) Cf = np.array([[0, 0, 1], [0, 1, 0], [-1, 0, 0]]) ωs = np.array([0, 0, 1]) ωf = np.array([0, 0, -1]) T = 1 ω_pred = smooth_attitude_interpolation(Cs, Cf, ωs, ωf, T) assert np.allclose(Cs, C[0]) assert np.allclose(Cf, C[-1])
scene = ar.Scene() for c in C: marker = ar.Marker(c) scene.add_marker(marker) sphere = ar.Sphere(0.