Reputation: 3260
I'm trying to represent coordinate systems (and transformations between them) in arbitrary dimensions. A coordinate system can be described by its pose (position + orientation) and I am unsure how to best represent its orientation in arbitrary dimensions.
Based on my search, it should be possible to represent an arbitrary pose as a sequence of rotations (source). Further, it should be possible to represent an arbitrary rotation by an angle (amount to rotate), and a plane in which to rotate (source). This means I should be able to do something like this in code
from dataclasses import dataclass
from typing import List
from numpy.typing import ArrayLike
@dataclass
class Rotation:
# amount to rotate
alpha: float
# two vectors spanning the plane
u: ArrayLike
v: ArrayLike
@dataclass
class Orientation:
orientation: List[Rotation]
This seems quite naive and inefficient. Each rotation has to be applied one at a time, which may not be very efficient computationally speaking. It is also non-unique. For example, these three objects represent the same orientation
Orientation(Rotation(np.pi, (0, 1), (1, 0)))
Orientation(Rotation(-np.pi, (1, 0), (0, 1)))
Orientation([Rotation(np.pi, (0, 1), (1, 0)), Rotation(0.42, (0, 1), (1, 0)), Rotation(-0.42, (0, 1), (1, 0))])
How can I improve this and what is the best data structure to use here?
Upvotes: 2
Views: 850
Reputation: 23647
Rotation matrices can represent rotations in arbitrary N dimensions.
It is possible to compose rotation matrices using the matrix product. So you'd need only to store a single matrix to represent an orientation, even if it's constructed from multiple individual rotations.
While a single plane/angle representation is more memory efficient than a full matrix, one matrix can represent the combination of multiple plane/angle rotations. Also, applying a matrix transformation is very efficient - just a couple of dot products.
In 3D space it's often beneficial to represent rotations as quaternions, but I don't think they can be generalized to arbitrary dimensionality. Although they can be generalized to ND space, this is is not very intuitive1.
1Thank you, Spektre, for the clarifying comment.
Upvotes: 2