| 1 |
# SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 |
|
| 3 |
from Metadata import export, constmethod, class_declarations |
| 4 |
from PyObjectBase import PyObjectBase |
| 5 |
from Matrix import Matrix as MatrixPy |
| 6 |
from Rotation import Rotation as RotationPy |
| 7 |
from Vector import Vector |
| 8 |
from typing import Sequence, overload |
| 9 |
|
| 10 |
@export( |
| 11 |
Constructor=True, |
| 12 |
Delete=True, |
| 13 |
NumberProtocol=True, |
| 14 |
RichCompare=True, |
| 15 |
) |
| 16 |
@class_declarations( |
| 17 |
"""public: |
| 18 |
PlacementPy(const Placement & pla, PyTypeObject *T = &Type) |
| 19 |
:PyObjectBase(new Placement(pla),T){} |
| 20 |
Placement value() const |
| 21 |
{ return *(getPlacementPtr()); } |
| 22 |
""" |
| 23 |
) |
| 24 |
class Placement(PyObjectBase): |
| 25 |
""" |
| 26 |
Base.Placement class. |
| 27 |
|
| 28 |
A Placement defines an orientation (rotation) and a position (base) in 3D space. |
| 29 |
It is used when no scaling or other distortion is needed. |
| 30 |
|
| 31 |
The following constructors are supported: |
| 32 |
|
| 33 |
Placement() |
| 34 |
Empty constructor. |
| 35 |
|
| 36 |
Placement(placement) |
| 37 |
Copy constructor. |
| 38 |
placement : Base.Placement |
| 39 |
|
| 40 |
Placement(matrix) |
| 41 |
Define from a 4D matrix consisting of rotation and translation. |
| 42 |
matrix : Base.Matrix |
| 43 |
|
| 44 |
Placement(base, rotation) |
| 45 |
Define from position and rotation. |
| 46 |
base : Base.Vector |
| 47 |
rotation : Base.Rotation |
| 48 |
|
| 49 |
Placement(base, rotation, center) |
| 50 |
Define from position and rotation with center. |
| 51 |
base : Base.Vector |
| 52 |
rotation : Base.Rotation |
| 53 |
center : Base.Vector |
| 54 |
|
| 55 |
Placement(base, axis, angle) |
| 56 |
define position and rotation. |
| 57 |
base : Base.Vector |
| 58 |
axis : Base.Vector |
| 59 |
angle : float |
| 60 |
""" |
| 61 |
|
| 62 |
Base: Vector = None |
| 63 |
"""Vector to the Base Position of the Placement.""" |
| 64 |
|
| 65 |
Rotation: Vector = None |
| 66 |
"""Orientation of the placement expressed as rotation.""" |
| 67 |
|
| 68 |
Matrix: MatrixPy = None |
| 69 |
"""Set/get matrix representation of the placement.""" |
| 70 |
|
| 71 |
# fmt: off |
| 72 |
@overload |
| 73 |
def __init__(self) -> None: ... |
| 74 |
@overload |
| 75 |
def __init__(self, placement: "Placement") -> None: ... |
| 76 |
@overload |
| 77 |
def __init__(self, matrix: MatrixPy) -> None: ... |
| 78 |
@overload |
| 79 |
def __init__(self, base: Vector, rotation: RotationPy) -> None: ... |
| 80 |
@overload |
| 81 |
def __init__(self, base: Vector, rotation: RotationPy, center: Vector) -> None: ... |
| 82 |
@overload |
| 83 |
def __init__(self, base: Vector, axis: Vector, angle: float) -> None: ... |
| 84 |
# fmt: on |
| 85 |
|
| 86 |
@constmethod |
| 87 |
def copy(self) -> "Placement": |
| 88 |
""" |
| 89 |
copy() -> Base.Placement |
| 90 |
|
| 91 |
Returns a copy of this placement. |
| 92 |
""" |
| 93 |
... |
| 94 |
|
| 95 |
def move(self, vector: Vector) -> None: |
| 96 |
""" |
| 97 |
move(vector) -> None |
| 98 |
|
| 99 |
Move the placement along a vector. |
| 100 |
|
| 101 |
vector : Base.Vector |
| 102 |
Vector by which to move the placement. |
| 103 |
""" |
| 104 |
... |
| 105 |
|
| 106 |
def translate(self, vector: Vector) -> None: |
| 107 |
""" |
| 108 |
translate(vector) -> None |
| 109 |
|
| 110 |
Alias to move(), to be compatible with TopoShape.translate(). |
| 111 |
|
| 112 |
vector : Base.Vector |
| 113 |
Vector by which to move the placement. |
| 114 |
""" |
| 115 |
... |
| 116 |
|
| 117 |
@overload |
| 118 |
def rotate( |
| 119 |
self, center: Sequence[float], axis: Sequence[float], angle: float, *, comp: bool = False |
| 120 |
) -> None: ... |
| 121 |
def rotate(self, center: Vector, axis: Vector, angle: float, *, comp: bool = False) -> None: |
| 122 |
""" |
| 123 |
rotate(center, axis, angle, comp) -> None |
| 124 |
|
| 125 |
Rotate the current placement around center and axis with the given angle. |
| 126 |
This method is compatible with TopoShape.rotate() if the (optional) keyword |
| 127 |
argument comp is True (default=False). |
| 128 |
|
| 129 |
center : Base.Vector, sequence of float |
| 130 |
Rotation center. |
| 131 |
axis : Base.Vector, sequence of float |
| 132 |
Rotation axis. |
| 133 |
angle : float |
| 134 |
Rotation angle in degrees. |
| 135 |
comp : bool |
| 136 |
optional keyword only argument, if True (default=False), |
| 137 |
behave like TopoShape.rotate() (i.e. the resulting placements are interchangeable). |
| 138 |
""" |
| 139 |
... |
| 140 |
|
| 141 |
@constmethod |
| 142 |
def multiply(self, placement: "Placement") -> "Placement": |
| 143 |
""" |
| 144 |
multiply(placement) -> Base.Placement |
| 145 |
|
| 146 |
Right multiply this placement with another placement. |
| 147 |
Also available as `*` operator. |
| 148 |
|
| 149 |
placement : Base.Placement |
| 150 |
Placement by which to multiply this placement. |
| 151 |
""" |
| 152 |
... |
| 153 |
|
| 154 |
@constmethod |
| 155 |
def multVec(self, vector: Vector) -> Vector: |
| 156 |
""" |
| 157 |
multVec(vector) -> Base.Vector |
| 158 |
|
| 159 |
Compute the transformed vector using the placement. |
| 160 |
|
| 161 |
vector : Base.Vector |
| 162 |
Vector to be transformed. |
| 163 |
""" |
| 164 |
... |
| 165 |
|
| 166 |
@constmethod |
| 167 |
def toMatrix(self) -> MatrixPy: |
| 168 |
""" |
| 169 |
toMatrix() -> Base.Matrix |
| 170 |
|
| 171 |
Compute the matrix representation of the placement. |
| 172 |
""" |
| 173 |
... |
| 174 |
|
| 175 |
@constmethod |
| 176 |
def inverse(self) -> "Placement": |
| 177 |
""" |
| 178 |
inverse() -> Base.Placement |
| 179 |
|
| 180 |
Compute the inverse placement. |
| 181 |
""" |
| 182 |
... |
| 183 |
|
| 184 |
@constmethod |
| 185 |
def pow(self, t: float, shorten: bool = True) -> "Placement": |
| 186 |
""" |
| 187 |
pow(t, shorten=True) -> Base.Placement |
| 188 |
|
| 189 |
Raise this placement to real power using ScLERP interpolation. |
| 190 |
Also available as `**` operator. |
| 191 |
|
| 192 |
t : float |
| 193 |
Real power. |
| 194 |
shorten : bool |
| 195 |
If True, ensures rotation quaternion is net positive to make |
| 196 |
the path shorter. |
| 197 |
""" |
| 198 |
... |
| 199 |
|
| 200 |
@constmethod |
| 201 |
def sclerp(self, placement2: "Placement", t: float, shorten: bool = True) -> "Placement": |
| 202 |
""" |
| 203 |
sclerp(placement2, t, shorten=True) -> Base.Placement |
| 204 |
|
| 205 |
Screw Linear Interpolation (ScLERP) between this placement and `placement2`. |
| 206 |
Interpolation is a continuous motion along a helical path parametrized by `t` |
| 207 |
made of equal transforms if discretized. |
| 208 |
If quaternions of rotations of the two placements differ in sign, the interpolation |
| 209 |
will take a long path. |
| 210 |
|
| 211 |
placement2 : Base.Placement |
| 212 |
t : float |
| 213 |
Parameter of helical path. t=0 returns this placement, t=1 returns |
| 214 |
`placement2`. t can also be outside of [0, 1] range for extrapolation. |
| 215 |
shorten : bool |
| 216 |
If True, the signs are harmonized before interpolation and the interpolation |
| 217 |
takes the shorter path. |
| 218 |
""" |
| 219 |
... |
| 220 |
|
| 221 |
@constmethod |
| 222 |
def slerp(self, placement2: "Placement", t: float) -> "Placement": |
| 223 |
""" |
| 224 |
slerp(placement2, t) -> Base.Placement |
| 225 |
|
| 226 |
Spherical Linear Interpolation (SLERP) between this placement and `placement2`. |
| 227 |
This function performs independent interpolation of rotation and movement. |
| 228 |
Result of such interpolation might be not what application expects, thus this tool |
| 229 |
might be considered for simple cases or for interpolating between small intervals. |
| 230 |
For more complex cases you better use the advanced sclerp() function. |
| 231 |
|
| 232 |
placement2 : Base.Placement |
| 233 |
t : float |
| 234 |
Parameter of the path. t=0 returns this placement, t=1 returns `placement2`. |
| 235 |
""" |
| 236 |
... |
| 237 |
|
| 238 |
@constmethod |
| 239 |
def isIdentity(self, tol: float = 0.0) -> bool: |
| 240 |
""" |
| 241 |
isIdentity([tol=0.0]) -> bool |
| 242 |
|
| 243 |
Returns True if the placement has no displacement and no rotation. |
| 244 |
Matrix representation is the 4D identity matrix. |
| 245 |
tol : float |
| 246 |
Tolerance used to check for identity. |
| 247 |
If tol is negative or zero, no tolerance is used. |
| 248 |
""" |
| 249 |
... |
| 250 |
|
| 251 |
@constmethod |
| 252 |
def isSame(self, other: "Placement", tol: float = 0.0) -> bool: |
| 253 |
""" |
| 254 |
isSame(Base.Placement, [tol=0.0]) -> bool |
| 255 |
|
| 256 |
Checks whether this and the given placement are the same. |
| 257 |
The default tolerance is set to 0.0 |
| 258 |
""" |
| 259 |
... |