add getAverageOrientation() to Orientation class as class method.

This commit is contained in:
Chen Zhang 2015-04-02 19:15:09 +00:00
parent 86f39de462
commit 43b665ba48
1 changed files with 50 additions and 26 deletions

View File

@ -1,5 +1,9 @@
# -*- coding: UTF-8 no BOM -*-
###################################################
# NOTE: everything here needs to be a numpy array #
###################################################
import numpy,math,random
# ******************************************************************************************
@ -849,3 +853,23 @@ class Orientation:
if inSST: break
return color
@classmethod
def getAverageOrientation(cls, orientationList):
"""RETURN THE AVERAGE ORIENTATION
ref: F. Landis Markley, Yang Cheng, John Lucas Crassidis, and Yaakov Oshman.
Averaging Quaternions,
Journal of Guidance, Control, and Dynamics, Vol. 30, No. 4 (2007), pp. 1193-1197.
doi: 10.2514/1.28949
usage:
a = Orientation(Eulers=np.radians([10, 10, 0]), symmetry='hexagonal')
b = Orientation(Eulers=np.radians([20, 0, 0]), symmetry='hexagonal')
avg = Orientation.getAverageOrientation([a,b])"""
if not all(isinstance(item, Orientation) for item in orientationList):
raise TypeError("Only instances of Orientation can be averaged.")
n = len(orientationList)
tmp_m = orientationList.pop(0).quaternion.asM()
for tmp_o in orientationList:
tmp_m += tmp_o.quaternion.asM()
eig, vec = numpy.linalg.eig(tmp_m/n)
return Orientation( quaternion=Quaternion(quatArray=vec.T[eig.argmax()]) )