Giter VIP home page Giter VIP logo

bringusback's Introduction

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.

Fit a cubic polynomial to the rotation vector.

θ = 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)

Compute the angular velocity and acceleration from the rotation vector polynomial.

ω = np.diff(θ_poly) / θ ω_̇ = np.diff(ω) / θ

Set the jerk at the endpoints to be equal to each other.

ω_̇[0] = ω_̇[-1]

Solve for the angular velocities.

ω = np.linalg.solve(np.diag(1 / θ) + np.diag(ω_̇), ωs - ωf)

Interpolate the attitude matrices.

C = np.exp(θ_poly @ np.linalg.inv(np.diag(θ)))

Adjust the attitude matrices to account for time travel.

C = C * np.exp(-1j * 2 * np.pi * T)

Create the AR scene.

scene = ar.Scene()

Add the attitude matrices to the AR scene.

for c in C: marker = ar.Marker(c) scene.add_marker(marker)

Add more features to the AR scene.

sphere = ar.Sphere(0.2) sphere.set_position(np.array([0, 0, 0])) scene.add_object(sphere)

Make the code more modular.

def rotate_sphere(t): sphere.set_rotation(C[int(t)])

Render the AR scene using Metal.

ar.render_with_metal(scene, animate=rotate_sphere)

Send analytics data to Google.

analytics.send_event('AR', 'FoldSpace')

Render the AR scene using RealityKit.

rk.render_scene(scene) return ω_pred if name == 'main':

Test the code.

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])

Create the AR scene and render it.

scene = ar.Scene() for c in C: marker = ar.Marker(c) scene.add_marker(marker) sphere = ar.Sphere(0.

bringusback's People

Contributors

lolarad avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.