Zum Inhalt

Rotation

A class representing a cube rotation of a face by n 90° turns.

Attributes:

Name Type Description
rotation scipy.spatial.transform.Rotation

the rotation matrix to apply to 3d coordinates

face FacePosition

the face to rotate

n int

the number of clockwise turns.

apply(self, to_item)

Applies the rotation to the given item (e.g. vector or matrix).

Parameters:

Name Type Description Default
to_item ndarray

the item to rotate

required

Returns:

Type Description
ndarray

the rotated item

Source code in core/spatial/Rotation.py
23
24
25
26
27
28
29
30
31
32
33
34
35
def apply(self, to_item: np.ndarray) -> np.ndarray:
    """Applies the rotation to the given item (e.g. vector or matrix).

    Args:
        to_item: the item to rotate

    Returns:
        the rotated item
    """
    if self.rotation is None:
        self.rotation = self.face.to_rotation(self.n * -90)

    return self.rotation.apply(to_item)

from_string_notation(string) staticmethod

Parses a list of cuber notation rotations and converts them to the internal representation.

Parameters:

Name Type Description Default
string str

the cuber notation formatted string

required

Returns:

Type Description
List[Rotation]

a list of Rotation objects

Source code in core/spatial/Rotation.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
@staticmethod
def from_string_notation(string: str) -> List['Rotation']:
    """Parses a list of cuber notation rotations and converts them to the internal representation.

    Args:
        string: the cuber notation formatted string

    Returns:
        a list of `Rotation` objects
    """
    from .. import cube

    items = string.strip().split(' ')
    rotations = []
    for item in items:
        face = cube.FacePosition.from_string_notation(item[0])
        n = 1
        if len(item) == 2:
            if item[1] == "'":
                n = -1
            elif item[1] == '2':
                n = 2

        rotations.append(Rotation(face, n))

    return rotations

reverse_multiple(rotations) staticmethod

Reverse a list of rotations by reversing the order but also each rotation individually. This creates the inverse set of rotations to apply to a cube to bring it back to its initial state.

Parameters:

Name Type Description Default
rotations List[Rotation]

the rotations to reverse

required

Returns:

Type Description
List[Rotation]

the resulting list of rotations

Source code in core/spatial/Rotation.py
78
79
80
81
82
83
84
85
86
87
88
89
@staticmethod
def reverse_multiple(rotations: List['Rotation']) -> List['Rotation']:
    """Reverse a list of rotations by reversing the order but also each rotation individually.
    This creates the inverse set of rotations to apply to a cube to bring it back to its initial state.

    Args:
        rotations: the rotations to reverse

    Returns:
        the resulting list of rotations
    """
    return list(map(lambda rotation: rotation.reversed(), reversed(rotations)))

reversed(self)

Returns a reversed Rotation which basically undoes the original one.

Source code in core/spatial/Rotation.py
47
48
49
def reversed(self) -> 'Rotation':
    """Returns a reversed `Rotation` which basically undoes the original one."""
    return Rotation(self.face, -self.n)