@@ -216,6 +216,9 @@ def vec(self):
216
216
- 1, return a NumPy array shape=(4,)
217
217
- N>1, return a NumPy array shape=(N,4).
218
218
219
+ The quaternion coefficients are in the order (s, vx, vy, vz), ie. with
220
+ the scalar (real part) first.
221
+
219
222
Example:
220
223
221
224
.. runblock:: pycon
@@ -229,6 +232,36 @@ def vec(self):
229
232
else :
230
233
return np .array ([q ._A for q in self ])
231
234
235
+ @property
236
+ def vec_xyzs (self ):
237
+ """
238
+ Quaternion as a vector
239
+
240
+ :return: quaternion expressed as a 4-vector
241
+ :rtype: numpy ndarray, shape=(4,)
242
+
243
+ ``q.vec`` is the quaternion as a vector. If `len(q)` is:
244
+
245
+ - 1, return a NumPy array shape=(4,)
246
+ - N>1, return a NumPy array shape=(N,4).
247
+
248
+ The quaternion coefficients are in the order (vx, vy, vz, s), ie. with
249
+ the scalar (real part) last. This is useful when exporting to other
250
+ packages like three.js or pybullet.
251
+
252
+ Example:
253
+
254
+ .. runblock:: pycon
255
+
256
+ >>> from spatialmath import Quaternion
257
+ >>> Quaternion([1,2,3,4]).vec_xyzs
258
+ >>> Quaternion([np.r_[1,2,3,4], np.r_[5,6,7,8]]).vec_xyzs
259
+ """
260
+ if len (self ) == 1 :
261
+ return self ._A
262
+ else :
263
+ return np .array ([q ._A for q in self ])
264
+
232
265
@property
233
266
def matrix (self ):
234
267
"""
0 commit comments