Compute unit quaternion from last 3 values
Parameters: | xyz : iterable
w2_thresh : None or float, optional
|
---|---|
Returns: | wxyz : array shape (4,)
|
Notes
If w, x, y, z are the values in the full quaternion, assumes w is positive.
Gives error if w*w is estimated to be negative
w = 0 corresponds to a 180 degree rotation
The unit quaternion specifies that np.dot(wxyz, wxyz) == 1.
If w is positive (assumed here), w is given by:
w = np.sqrt(1.0-(x*x+y*y+z*z))
w2 = 1.0-(x*x+y*y+z*z) can be near zero, which will lead to numerical instability in sqrt. Here we use the system maximum float type to reduce numerical instability
Examples
>>> import numpy as np
>>> wxyz = fillpositive([0,0,0])
>>> np.all(wxyz == [1, 0, 0, 0])
True
>>> wxyz = fillpositive([1,0,0]) # Corner case; w is 0
>>> np.all(wxyz == [0, 1, 0, 0])
True
>>> np.dot(wxyz, wxyz)
1.0