<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> import numpy as np <EOL> from multipledispatch import dispatch <EOL> from . base import BaseObject , BaseQuaternion , BaseMatrix , BaseVector , NpProxy <EOL> from . . import quaternion <EOL> class Quaternion ( BaseQuaternion ) : <EOL> _module = quaternion <EOL> _shape = ( <NUM_LIT:4> , ) <EOL> x = NpProxy ( <NUM_LIT:0> ) <EOL> y = NpProxy ( <NUM_LIT:1> ) <EOL> z = NpProxy ( <NUM_LIT:2> ) <EOL> w = NpProxy ( <NUM_LIT:3> ) <EOL> xy = NpProxy ( [ <NUM_LIT:0> , <NUM_LIT:1> ] ) <EOL> xyz = NpProxy ( [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> xyzw = NpProxy ( [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> xz = NpProxy ( [ <NUM_LIT:0> , <NUM_LIT:2> ] ) <EOL> xzw = NpProxy ( [ <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> xyw = NpProxy ( [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:3> ] ) <EOL> xw = NpProxy ( [ <NUM_LIT:0> , <NUM_LIT:3> ] ) <EOL> @ classmethod <EOL> def from_x_rotation ( cls , theta , dtype = None ) : <EOL> """<STR_LIT>""" <EOL> return cls ( quaternion . create_from_x_rotation ( theta , dtype ) ) <EOL> @ classmethod <EOL> def from_y_rotation ( cls , theta , dtype = None ) : <EOL> """<STR_LIT>""" <EOL> return cls ( quaternion . create_from_y_rotation ( theta , dtype ) ) <EOL> @ classmethod <EOL> def from_z_rotation ( cls , theta , dtype = None ) : <EOL> """<STR_LIT>""" <EOL> return cls ( quaternion . create_from_z_rotation ( theta , dtype ) ) <EOL> @ classmethod <EOL> def from_axis_rotation ( cls , axis , theta , dtype = None ) : <EOL> """<STR_LIT>""" <EOL> return cls ( quaternion . create_from_axis_rotation ( axis , theta , dtype ) ) <EOL> @ classmethod <EOL> def from_matrix ( cls , matrix , dtype = None ) : <EOL> """<STR_LIT>""" <EOL> return cls ( quaternion . create_from_matrix ( matrix , dtype ) ) <EOL> @ classmethod <EOL> def from_eulers ( cls , eulers , dtype = None ) : <EOL> """<STR_LIT>""" <EOL> return cls ( quaternion . create_from_eulers ( eulers , dtype ) ) <EOL> @ classmethod <EOL> def from_inverse_of_eulers ( cls , eulers , dtype = None ) : <EOL> """<STR_LIT>""" <EOL> return cls ( quaternion . create_from_inverse_of_eulers ( eulers , dtype ) ) <EOL> def __new__ ( cls , value = None , dtype = None ) : <EOL> if value is not None : <EOL> obj = value <EOL> if not isinstance ( value , np . ndarray ) : <EOL> obj = np . array ( value , dtype = dtype ) <EOL> if obj . shape in ( ( <NUM_LIT:4> , <NUM_LIT:4> , ) , ( <NUM_LIT:3> , <NUM_LIT:3> , ) ) or isinstance ( obj , ( Matrix33 , Matrix44 ) ) : <EOL> obj = quaternion . create_from_matrix ( obj , dtype = dtype ) <EOL> else : <EOL> obj = quaternion . create ( dtype = dtype ) <EOL> obj = obj . view ( cls ) <EOL> return super ( Quaternion , cls ) . __new__ ( cls , obj ) <EOL> @ dispatch ( BaseObject ) <EOL> def __add__ ( self , other ) : <EOL> self . _unsupported_type ( '<STR_LIT>' , other ) <EOL> @ dispatch ( BaseObject ) <EOL> def __sub__ ( self , other ) : <EOL> self . _unsupported_type ( '<STR_LIT>' , other ) <EOL> @ dispatch ( BaseObject ) <EOL> def __mul__ ( self , other ) : <EOL> self . _unsupported_type ( '<STR_LIT>' , other ) <EOL> @ dispatch ( BaseObject ) <EOL> def __truediv__ ( self , other ) : <EOL> self . _unsupported_type ( '<STR_LIT>' , other ) <EOL> @ dispatch ( BaseObject ) <EOL> def __div__ ( self , other ) : <EOL> self . _unsupported_type ( '<STR_LIT>' , other ) <EOL> @ dispatch ( ( BaseQuaternion , np . ndarray , list ) ) <EOL> def __sub__ ( self , other ) : <EOL> return Quaternion ( super ( Quaternion , self ) . __sub__ ( other ) ) <EOL> @ dispatch ( ( BaseQuaternion , list ) ) <EOL> def __mul__ ( self , other ) : <EOL> return self . cross ( other ) <EOL> @ dispatch ( ( BaseQuaternion , list ) ) <EOL> def __or__ ( self , other ) : <EOL> return self . dot ( other ) <EOL> def __invert__ ( self ) : <EOL> return self . conjugate <EOL> @ dispatch ( BaseMatrix ) <EOL> def __mul__ ( self , other ) : <EOL> return self * Quaternion ( other ) <EOL> @ dispatch ( BaseVector ) <EOL> def __mul__ ( self , other ) : <EOL> return type ( other ) ( quaternion . apply_to_vector ( self , other ) ) <EOL> @ property <EOL> def length ( self ) : <EOL> """<STR_LIT>""" <EOL> return quaternion . length ( self ) <EOL> def normalise ( self ) : <EOL> """<STR_LIT>""" <EOL> self [ : ] = quaternion . normalise ( self ) <EOL> @ property <EOL> def normalised ( self ) : <EOL> """<STR_LIT>""" <EOL> return Quaternion ( quaternion . normalise ( self ) ) <EOL> @ property <EOL> def angle ( self ) : <EOL> """<STR_LIT>""" <EOL> return quaternion . rotation_angle ( self ) <EOL> @ property <EOL> def axis ( self ) : <EOL> """<STR_LIT>""" <EOL> return Vector3 ( quaternion . rotation_axis ( self ) ) <EOL> def cross ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return Quaternion ( quaternion . cross ( self , other ) ) <EOL> def dot ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return quaternion . dot ( self , other ) <EOL> @ property <EOL> def conjugate ( self ) : <EOL> """<STR_LIT>""" <EOL> return Quaternion ( quaternion . conjugate ( self ) ) <EOL> @ property <EOL> def inverse ( self ) : <EOL> """<STR_LIT>""" <EOL> return Quaternion ( quaternion . inverse ( self ) ) <EOL> def power ( self , exponent ) : <EOL> """<STR_LIT>""" <EOL> return Quaternion ( quaternion . power ( self , exponent ) ) <EOL> @ property <EOL> def negative ( self ) : <EOL> """<STR_LIT>""" <EOL> return Quaternion ( quaternion . negate ( self ) ) <EOL> @ property <EOL> def is_identity ( self ) : <EOL> """<STR_LIT>""" <EOL> return quaternion . is_identity ( self ) <EOL> @ property <EOL> def matrix44 ( self ) : <EOL> """<STR_LIT>""" <EOL> return Matrix44 . from_quaternion ( self ) <EOL> @ property <EOL> def matrix33 ( self ) : <EOL> """<STR_LIT>""" <EOL> return Matrix33 . from_quaternion ( self ) <EOL> from . vector3 import Vector3 <EOL> from . matrix33 import Matrix33 <EOL> from . matrix44 import Matrix44 </s>
