Returns the vector rotated by an angle *`theta`* (in radians) in the right-hand direction around the *`axis`* vector (whose length is ignored). You may find the python functions `math.degrees` and `math.radians` useful to convert angles between degrees and radians.
(self, axis, theta)
| 232 | ) |
| 233 | |
| 234 | def rotate(self, axis, theta): |
| 235 | """ |
| 236 | Returns the vector rotated by an angle *`theta`* (in radians) in the right-hand |
| 237 | direction around the *`axis`* vector (whose length is ignored). You may find the |
| 238 | python functions `math.degrees` and `math.radians` useful to convert angles |
| 239 | between degrees and radians. |
| 240 | |
| 241 | ```python |
| 242 | v2 = v1.rotate(axis, theta) |
| 243 | ``` |
| 244 | """ |
| 245 | u = axis.unit() |
| 246 | vpar = u.scale(u.dot(self)) |
| 247 | vcross = u.cross(self) |
| 248 | vperp = self - vpar |
| 249 | return vpar + (vperp.scale(math.cos(theta)) + vcross.scale(math.sin(theta))) |
| 250 | |
| 251 | # rotate vectors in lattice/reciprocal coords (note that the axis |
| 252 | # is also given in the corresponding basis): |