Created
October 2, 2022 21:43
-
-
Save matpalm/ff9d7313826d5f30a2afd8cb09c72b3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def slerp(p0, p1, n): | |
# https://en.wikipedia.org/wiki/Slerp | |
norm = np.linalg.norm(p0) * np.linalg.norm(p1) | |
dot = np.sum(p0 * p1 / norm) | |
theta_0 = np.arccos(dot) | |
sin_theta_0 = np.sin(theta_0) | |
interp = [] | |
for t in np.linspace(0.0, 1.0, n): | |
theta_t = theta_0 * t | |
s0 = np.sin(theta_0 - theta_t) / sin_theta_0 | |
s1 = np.sin(theta_t) / sin_theta_0 | |
interp.append(p0*s0 + p1*s1) | |
return np.stack(interp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
good one @cemoody ! hope you're well!