From 22fc1b363b5d8815e7ccb9f4219d4b2a77b537f4 Mon Sep 17 00:00:00 2001 From: mdroe Date: Fri, 1 Jun 2012 18:09:08 +0000 Subject: Use slerp interpolation git-svn-id: http://svn.stsci.edu/svn/ssb/stsci_python/stsci_python/branches/sphere@17193 fe389314-cf27-0410-b35b-8c050e845b92 Former-commit-id: 4354d548cccf590779e982a7eaa5eb227f034ff5 --- lib/great_circle_arc.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'lib/great_circle_arc.py') diff --git a/lib/great_circle_arc.py b/lib/great_circle_arc.py index 93d9ad2..e12a8f8 100644 --- a/lib/great_circle_arc.py +++ b/lib/great_circle_arc.py @@ -54,7 +54,8 @@ except ImportError: HAS_C_UFUNCS = False -__all__ = ['angle', 'intersection', 'intersects', 'length', 'midpoint'] +__all__ = ['angle', 'intersection', 'intersects', 'length', 'midpoint', + 'interpolate'] if not HAS_C_UFUNCS: @@ -318,7 +319,7 @@ def midpoint(A, B): def interpolate(A, B, steps=50): - """ + ur""" Interpolate along the great circle arc. Parameters @@ -334,7 +335,21 @@ def interpolate(A, B, steps=50): ------- array : (*x*, *y*, *z*) triples The points interpolated along the great circle arc + + Notes + ----- + + This uses Slerp interpolation where *Ω* is the angle subtended by + the arc, and *t* is the parameter 0 <= *t* <= 1. + + .. math:: + + \frac{\sin((1 - t)\Omega)}{\sin \Omega}A + \frac{\sin(t \Omega)}{\sin \Omega}B """ - t = np.linspace(0, 1.0, steps, endpoint=True).reshape((steps, 1)) + t = np.linspace(0.0, 1.0, steps, endpoint=True).reshape((steps, 1)) + + omega = length(A, B, degrees=False) + sin_omega = np.sin(omega) + offsets = np.sin(t * omega) / sin_omega - return (t * A) + ((1.0 - t) * B) + return offsets[::-1] * A + offsets * B -- cgit