Skip to content

Instantly share code, notes, and snippets.

@matpalm
Created October 2, 2022 21:43
Show Gist options
  • Save matpalm/ff9d7313826d5f30a2afd8cb09c72b3e to your computer and use it in GitHub Desktop.
Save matpalm/ff9d7313826d5f30a2afd8cb09c72b3e to your computer and use it in GitHub Desktop.
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)
@cemoody
Copy link

cemoody commented Jan 4, 2023

Thanks for writing this Mat! I happen to come across this and recognized you on it!

@matpalm
Copy link
Author

matpalm commented Jan 4, 2023

good one @cemoody ! hope you're well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment