@@ -309,24 +309,40 @@ extension Quaternion {
309
309
}
310
310
}
311
311
312
- /// Rotates given vector by this quaternion.
312
+ /// Transforms a vector by this quaternion.
313
313
///
314
- /// As quaternions can be used to represent three-dimensional rotations, it is
315
- /// is possible to also rotate a three-dimensional vector by a quaternion. The
316
- /// rotation of an arbitrary vector by a quaternion is known as an action.
314
+ /// Quaternions are frequently used to represent three-dimensional
315
+ /// transformations, and thus are used to transform vectors in
316
+ /// three-dimensional space. The transformation of an arbitrary vector
317
+ /// by a quaternion is known as an action.
318
+ ///
319
+ /// The canonical way of transforming an arbitrary three-dimensional vector
320
+ /// `v` by a quaternion `q` is given by the following [formula][wiki]
321
+ ///
322
+ /// p' = qpq⁻¹
323
+ ///
324
+ /// where `p` is a *pure* quaternion (`real == .zero`) with imaginary part equal
325
+ /// to vector `v`, and where `p'` is another pure quaternion with imaginary
326
+ /// part equal to the transformed vector `v'`. The implementation uses this
327
+ /// formular but boils down to a simpler and faster implementation as `p` is
328
+ /// known to be pure and `q` is assumed to have unit length – which allows
329
+ /// simplification.
317
330
///
318
331
/// - Note: This method assumes this quaternion is of unit length.
319
332
///
320
333
/// Edge cases:
321
334
/// -
322
- /// - If `vector` is `.infinity` in any of the lanes or all, the returning
335
+ /// - For any quaternion `q`, even `.zero` or `.infinity`, if `vector` is
336
+ /// `.infinity` or `-.infinity` in any of the lanes or all, the returning
323
337
/// vector is `.infinity` in all lanes:
324
338
/// ```
325
- /// Quaternion(rotation: .zero) == .zero
339
+ /// SIMD3(-.infinity,0,0) * q == SIMD3(.infinity,.infinity,.infinity)
326
340
/// ```
327
341
///
328
342
/// - Parameter vector: A vector to rotate by this quaternion
329
343
/// - Returns: The vector rotated by this quaternion
344
+ ///
345
+ /// [wiki]: https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation#Using_quaternion_as_rotations
330
346
@inlinable
331
347
public func act( on vector: SIMD3 < RealType > ) -> SIMD3 < RealType > {
332
348
guard vector. isFinite else { return SIMD3 ( repeating: . infinity) }
0 commit comments