示例#1
0
 def _loads(self, contents: Mapping[str, Mapping[str, float]]) -> None:
     self._translation = Vector3D.loads(contents["translation"])
     rotation_contents = contents["rotation"]
     self._rotation = Quaternion(
         rotation_contents["w"],
         rotation_contents["x"],
         rotation_contents["y"],
         rotation_contents["z"],
     )
示例#2
0
    def __rmul__(self: _T, other: Quaternion) -> _T:
        try:
            if isinstance(other, Quaternion):
                return self._create(
                    Vector3D(*rotate_vectors(other, self._translation)),
                    other * self._rotation,
                )
        except ValueError:
            pass

        return NotImplemented
示例#3
0
 def __init__(
     self,
     size: Iterable[float],
     translation: Iterable[float] = (0, 0, 0),
     rotation: Transform3D.RotationType = (1, 0, 0, 0),
     *,
     transform_matrix: Optional[MatrixType] = None,
 ) -> None:
     self._transform = Transform3D(translation,
                                   rotation,
                                   matrix=transform_matrix)
     self._size = Vector3D(*size)
示例#4
0
    def __init__(
        self,
        translation: Iterable[float] = (0, 0, 0),
        rotation: RotationType = (1, 0, 0, 0),
        *,
        matrix: Optional[MatrixType] = None,
    ) -> None:
        if matrix is not None:
            try:
                self._translation = Vector3D(matrix[0][3], matrix[1][3],
                                             matrix[2][3])
                self._rotation = from_rotation_matrix(matrix)
                return
            except (IndexError, TypeError) as error:
                raise ValueError(
                    "The shape of input transform matrix must be 3x4 or 4x4."
                ) from error

        self._translation = Vector3D(*translation)
        if isinstance(rotation, Quaternion):
            self._rotation = Quaternion(rotation)
        else:
            self._rotation = Quaternion(*rotation)
示例#5
0
    def inverse(self: _T) -> _T:
        """Return the inverse of the transform.

        Returns:
            A :class:`Transform3D` object representing the inverse of this :class:`Transform3D`.

        Examples:
            >>> transform = Transform3D([1, 2, 3], [0, 1, 0, 0])
            >>> transform.inverse()
            Transform3D(
              (translation): Vector3D(-1.0, 2.0, 3.0),
              (rotation): quaternion(0, -1, -0, -0)
            )

        """
        rotation = self._rotation.inverse()
        translation = Vector3D(*rotate_vectors(rotation, -self._translation))
        return self._create(translation, rotation)
示例#6
0
    def set_translation(self, x: float, y: float, z: float) -> None:
        """Set the translation of the transform.

        Arguments:
            x: The x coordinate of the translation.
            y: The y coordinate of the translation.
            z: The z coordinate of the translation.

        Examples:
            >>> transform = Transform3D([1, 1, 1], [1, 0, 0, 0])
            >>> transform.set_translation(3, 4, 5)
            >>> transform
            Transform3D(
              (translation): Vector3D(3, 4, 5),
              (rotation): quaternion(1, 0, 0, 0)
            )

        """
        self._translation = Vector3D(x, y, z)
示例#7
0
 def _loads(self, contents: Mapping[str, Mapping[str, float]]) -> None:
     self._size = Vector3D.loads(contents["size"])
     self._transform = Transform3D.loads(contents)