Zum Inhalt

CoordinateSystem

A class representing a 3d coordinate system.

Attributes:

Name Type Description
origin np.ndarray

the origin of this coordinate system (relative to its parent)

base np.ndarray

the base of this coordinate system (relative to its parent)

assume_base(self)

Assumes the base of this segment if not enough base vectors are set. The assumption is based on the right-hand-rule cross product if two base vectors are given.

Source code in core/spatial/CoordinateSystem.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
def assume_base(self):
    """
    Assumes the base of this segment if not enough base vectors are set.
    The assumption is based on the right-hand-rule cross product if two base vectors are given.
    """
    # assume a base if only two vectors are given according to the right-hand-rule
    nans_columns   = np.unique(np.where(np.isnan(self.base))[1])
    values_columns = np.unique(np.where(np.logical_not(np.isnan(self.base)))[1])

    if len(values_columns) == 1 and len(nans_columns) == 2:
        # this is a middle face (only 1 vector found), which should never be rotated -> identity
        self.base = np.eye(3)

    if len(values_columns) == 2 and len(nans_columns) == 1:
        # we need to assume the third vector
        base_vector_1 = self.base[:, values_columns[0]]
        base_vector_2 = self.base[:, values_columns[1]]

        index_1 = np.where(abs(base_vector_1) > 0.5)[0][0]
        index_2 = np.where(abs(base_vector_2) > 0.5)[0][0]

        # x cross y = z; y cross z = x; z cross x = y
        # the order needs to be preserved for the right hand rule
        if index_2 == 2 and index_1 == 0:
            self.base[:, nans_columns[0]] = np.cross(base_vector_2, base_vector_1)
        else:
            self.base[:, nans_columns[0]] = np.cross(base_vector_1, base_vector_2)

clear_base(self)

Clears the base of this segment.

Source code in core/spatial/CoordinateSystem.py
44
45
46
47
48
49
def clear_base(self):
    """
    Clears the base of this segment.

    """
    self.base = np.full((3, 3), fill_value=np.nan)

rotate(self, rotation, inplace=False)

Rotates the coordinate system according to the given rotation.

Parameters:

Name Type Description Default
rotation Rotation

the rotation to apply

required
inplace bool

flag, indicating whether to rotate in place or around its origin

False
Source code in core/spatial/CoordinateSystem.py
32
33
34
35
36
37
38
39
40
41
42
def rotate(self, rotation: Rotation, inplace: bool = False):
    """Rotates the coordinate system according to the given rotation.

    Args:
        rotation: the rotation to apply
        inplace: flag, indicating whether to rotate in place or around its origin
    """
    # IMPROVEMENT: Could we combine those rotations using the homogeneous matrix?
    if not inplace:
        self.origin = rotation.apply(self.origin).round()
    self.base = rotation.apply(self.base.T).round().T

translate(self, vector)

Translates the coordinate system by the given 3d vector.

Parameters:

Name Type Description Default
vector ndarray

the translation vector to apply

required
Source code in core/spatial/CoordinateSystem.py
24
25
26
27
28
29
30
def translate(self, vector: np.ndarray):
    """Translates the coordinate system by the given 3d vector.

    Args:
        vector: the translation vector to apply
    """
    self.origin += vector