### Install from GitHub
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/README.md
Commands to clone the repository from GitHub and install the package in editable mode.
```bash
git clone https://github.com/rai-opensource/spatialmath-python.git
cd spatialmath-python
pip install -e .
```
--------------------------------
### Install from PyPI
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/README.md
Command to install the spatialmath-python package using pip.
```bash
pip install spatialmath-python
```
--------------------------------
### Symbolic support example
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/docs/source/intro.md
Examples demonstrating the use of symbolic variables in spatialmath-python, showing the conversion of symbolic constants back to Python numeric types and the conversion of numeric values to symbolic constants.
```python
Traceback (most recent call last):
File "", line 1, in
AttributeError: module 'spatialmath.base.symbolic' has no attribute 'symbol'
Traceback (most recent call last):
File "", line 1, in
NameError: name 'theta' is not defined
```
```python
Traceback (most recent call last):
File "", line 1, in
AttributeError: module 'spatialmath.base.symbolic' has no attribute 'symbol'
Traceback (most recent call last):
File "", line 1, in
NameError: name 'theta' is not defined
Traceback (most recent call last):
File "", line 1, in
NameError: name 'T' is not defined
Traceback (most recent call last):
File "", line 1, in
NameError: name 'a' is not defined
Traceback (most recent call last):
File "", line 1, in
NameError: name 'a' is not defined
Traceback (most recent call last):
File "", line 1, in
NameError: name 'T' is not defined
Traceback (most recent call last):
File "", line 1, in
NameError: name 'a' is not defined
Traceback (most recent call last):
File "", line 1, in
NameError: name 'a' is not defined
```
```python
Traceback (most recent call last):
File "", line 1, in
AttributeError: module 'spatialmath.base.symbolic' has no attribute 'symbol'
Traceback (most recent call last):
File "", line 1, in
NameError: name 'theta' is not defined
Traceback (most recent call last):
File "", line 1, in
NameError: name 'T' is not defined
Traceback (most recent call last):
File "", line 1, in
NameError: name 'T' is not defined
```
--------------------------------
### Pre-commit installation
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/README.md
Command to install pre-commit for contributing code changes.
```bash
pre-commit install
```
--------------------------------
### Colab Widget Backend Setup
Source: https://github.com/rai-opensource/spatialmath-python/wiki/Using-Jupyter-and-Colab
Setup commands for using the '%matplotlib widget' backend in Google Colab.
```python
!pip install ipympl
%matplotlib widget
from google.colab import output
output.enable_custom_widget_manager()
```
--------------------------------
### SE3 composition and inversion example
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/introduction.ipynb
Illustrates the composition and inversion of SE3 objects with specific transformations.
```python
T2 = SE3(4, 5, 6) * SE3.Ry(-40, 'deg')
T12 = SE3(0, -2, -1) * SE3.Rz(70, 'deg')
T1 * T2.inv()
```
--------------------------------
### Install with ROS2 Humble support
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/README.md
Command to install spatialmath-python with optional version pinning for ROS2 Humble.
```bash
pip install spatialmath-python[ros-humble]
```
--------------------------------
### Quick example: SO3 rotation
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/spatialmath/base/README.md
Demonstrates creating a rotation matrix about the x-axis using the SO3 class.
```python
import spatialmath as sm
R = sm.SO3.Rx(30, 'deg')
print(R)
1 0 0
0 0.866025 -0.5
0 0.5 0.866025
```
--------------------------------
### High-level classes: SO2 example
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/spatialmath/base/README.md
Demonstrates creating an SO2 object.
```python
from spatialmath import *
SO2(.1)
[[ 0.99500417 -0.09983342]
[ 0.09983342 0.99500417]]
```
--------------------------------
### SE3 exponentiation example
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/introduction.ipynb
Demonstrates the exponentiation operator (**) for SE3 objects, representing repeated composition.
```python
T1 ** 2
```
--------------------------------
### Quaternion Multiplication
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/docs/source/intro.md
Example of quaternion multiplication using `qqmul` and displaying the result with `qprint`.
```pycon
>>> from spatialmath.base import *
>>> q = qqmul([1,2,3,4], [5,6,7,8])
>>> q
array([-60., 12., 30., 24.])
>>> qprint(q)
-60.0000 < 12.0000, 30.0000, 24.0000 >
>>> qnorm(q)
np.float64(72.24956747275377)
```
--------------------------------
### Controlling colorization
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/docs/source/intro.md
Example of changing the rotation color to green.
```default
>>> SE3._rotcolor = 'green' # rotation part in green
```
--------------------------------
### Class-specific value constructors
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/docs/source/intro.md
Examples of creating SE2 and UnitQuaternion objects with class-specific values.
```pycon
>>> from spatialmath import *
>>> SE2(1, 2, 0.3)
SE2(array([[ 0.95533649, -0.29552021, 1. ],
[ 0.29552021, 0.95533649, 2. ],
[ 0. , 0. , 1. ]]))
>>> UnitQuaternion([1, 0, 0, 0])
UnitQuaternion(array([1., 0., 0., 0.]))
```
--------------------------------
### Create a translation in the x-direction
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Example of creating a translation of 1 unit in the x-direction using SE3.Tx().
```python
T1 = SE3.Tx(1)
```
--------------------------------
### Suppressing color
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/docs/source/intro.md
Example of suppressing colorization, useful for documentation.
```default
>>> SE3._color = False
```
--------------------------------
### List of SE3 objects
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/docs/source/intro.md
Example of creating a list of SE3 objects, highlighting the potential for non-homogeneous elements if not carefully managed.
```default
>>> X = [SE3.Rx(0), SE3.Rx(0.2), SE3.Rx(0.4), SE3.Rx(0.6)]
```
--------------------------------
### Variant Constructors Example
Source: https://github.com/rai-opensource/spatialmath-python/wiki/Home
Illustrates the use of class methods as alternative constructors for different parametric representations.
```python
SO3.RPY(roll, pitch, yaw)
SO3.Eul(phi, theta, psi)
SO3.AngVec(angle, vector)
SO3.Exp(twist)
```
--------------------------------
### Create a SE3 class instance
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/docs/source/intro.md
Example of creating a SE3 class instance representing a rotation about the x-axis of 30 degrees, demonstrating its type and printed representation.
```python
>>> from spatialmath import *
>>> T = SE3.Rx(30, 'deg')
>>> type(T)
>>> print(T)
1 0 0 0
0 0.866 -0.5 0
0 0.5 0.866 0
0 0 0 1
```
--------------------------------
### SE3 division (inversion) example
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/introduction.ipynb
Shows the use of the division operator (/) as a shorthand for inversion in SE3 operations.
```python
T1 / T2
```
--------------------------------
### Animation with Notebook Backend
Source: https://github.com/rai-opensource/spatialmath-python/wiki/Using-Jupyter-and-Colab
Example of animating a transformation using '%matplotlib notebook'.
```python
tranimate(transl(1,2,3))
```
--------------------------------
### List capability example
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/docs/source/intro.md
Demonstrates the list-like behavior of SO3 objects, including length, indexing, slicing, and iteration.
```pycon
>>> from spatialmath import *
>>> import numpy as np
>>> R = SO3.Rx(0.3)
>>> len(R)
1
>>> R = SO3.Rx(np.arange(0, 2*np.pi, 0.2))
>>> len(R)
32
>>> R[0]
SO3(array([[1., 0., 0.],
[0., 1., 0.],
[0., 0., 1.]]))
>>> R[-1]
SO3(array([[ 1. , 0. , 0. ],
[ 0. , 0.9965421, 0.0830894],
[ 0. , -0.0830894, 0.9965421]]))
>>> R[2:4]
SO3([
array([[ 1. , 0. , 0. ],
[ 0. , 0.92106099, -0.38941834],
[ 0. , 0.38941834, 0.92106099]]),
array([[ 1. , 0. , 0. ],
[ 0. , 0.82533561, -0.56464247],
[ 0. , 0.56464247, 0.82533561]]) ])
```
--------------------------------
### Low-level spatial math: Translation examples
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/spatialmath/base/README.md
Demonstrates different ways to provide vector information for translation functions.
```python
transl2(1, 2)
Out[442]:
array([[1., 0., 1.],
[0., 1., 2.],
[0., 0., 1.]])
transl2( [1,2] )
Out[443]:
array([[1., 0., 1.],
[0., 1., 2.],
[0., 0., 1.]])
transl2( (1,2) )
Out[444]:
array([[1., 0., 1.],
[0., 1., 2.],
[0., 0., 1.]])
transl2( np.array([1,2]) )
Out[445]:
array([[1., 0., 1.],
[0., 1., 2.],
[0., 0., 1.]])
```
--------------------------------
### Iteration and comprehensions example
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/docs/source/intro.md
Shows how to iterate over SO3 objects and use list comprehensions to extract data.
```pycon
>>> from spatialmath import *
>>> import numpy as np
>>> R = SO3.Rx(np.arange(0, 2*np.pi, 0.2))
>>> len(R)
32
>>> eul = [x.eul() for x in R]
>>> len(eul)
32
>>> eul[10]
array([-1.57079633, 2. , 1.57079633])
```
--------------------------------
### Animation to HTML Fragment
Source: https://github.com/rai-opensource/spatialmath-python/wiki/Using-Jupyter-and-Colab
Example of rendering an animation to an HTML5/Javascript fragment for the 'inline' backend.
```python
html = tranimate(transl(1,2,3), movie=True)
from IPython.core.display import HTML
HTML(html)
```
--------------------------------
### Low-level spatial math: Rotation examples
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/spatialmath/base/README.md
Shows how to use low-level transform functions for rotations with different units.
```python
from spatialmath.base.transforms import *
rotx(0.3)
array([[ 1. , 0. , 0. ],
[ 0. , 0.95533649, -0.29552021],
[ 0. , 0.29552021, 0.95533649]])
rotx(30, unit='deg')
Out[438]:
array([[ 1. , 0. , 0. ],
[ 0. , 0.8660254, -0.5 ],
[ 0. , 0.5 , 0.8660254]])
```
--------------------------------
### Represent as Numpy Array
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Shows how to get the quaternion's representation as a numpy array.
```python
q1.vec
```
--------------------------------
### Widget Matplotlib Backend
Source: https://github.com/rai-opensource/spatialmath-python/wiki/Using-Jupyter-and-Colab
Example of using the '%matplotlib widget' magic command for interactive plots with ipympl.
```python
%matplotlib widget
```
--------------------------------
### SO3 Class - Rotation Examples
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/README.md
Demonstrates creating SO3 objects for rotations around the x and z axes, and their composition.
```python
>>> from spatialmath import SO3, SE3
>>> R1 = SO3.Rx(0.3)
>>> R1
1 0 0
0 0.955336 -0.29552
0 0.29552 0.955336
>>> R2 = SO3.Rz(30, 'deg')
>>> R2
0.866025 -0.5 0
0.5 0.866025 0
0 0 1
>>> R = R1 * R2
0.866025 -0.5 0
0.433013 0.75 -0.5
0.25 0.433013 0.866025
```
--------------------------------
### Creating an SE3 object with a specific rotation
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Example of creating an SE3 object representing a rotation around the Y-axis by 40 degrees.
```python
T2 = SE3.Ry(40, 'deg')
```
--------------------------------
### Importing classic functions from base
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/docs/source/intro.md
Example of importing classic spatial math functions like rotx and trotx from the spatialmath.base package, which work with NumPy arrays.
```python
from spatialmath.base import rotx, trotx
```
--------------------------------
### Notebook Matplotlib Backend
Source: https://github.com/rai-opensource/spatialmath-python/wiki/Using-Jupyter-and-Colab
Example of using the '%matplotlib notebook' magic command for interactive plots in Jupyter.
```python
%matplotlib notebook
import matplotlib.pyplot as plt
from spatialmath.base import *
trplot(transl(1,2,3))
trplot(transl(2,3,4))
```
--------------------------------
### Colorized text output
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/docs/source/intro.md
Shows how to get colorized text output for SE3 objects, with rotational elements in red, translational in blue, and constants in grey.
```default
>>> T = SE3()
>>> T.print()
```
--------------------------------
### Creating a list of SE3 objects
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Demonstrates creating a list of SE3 objects using a loop.
```python
T = [ SE3.Rx(0), SE3.Rx(0.1), SE3.Rx(0.2), SE3.Rx(0.3), SE3.Rx(0.4)]
```
--------------------------------
### Creating a MATLAB-like environment
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/docs/source/intro.md
Demonstrates how to create a MATLAB-like environment in Python by importing all functions from spatialmath and spatialmath.base, making classic functions and classes readily available.
```python
from spatialmath import *
from spatialmath.base import *
R = rotx(0.3)
R2 = rpy2r(0.1, 0.2, 0.3)
T = SE3(1, 2, 3)
```
--------------------------------
### Conventional Matplotlib Plotting
Source: https://github.com/rai-opensource/spatialmath-python/wiki/Animation
Example of conventional matplotlib plotting.
```python
ax.plot(1,2)
```
--------------------------------
### SE3 Constructor Pattern
Source: https://github.com/rai-opensource/spatialmath-python/wiki/The-constructor-process
Illustrates the general pattern of the __init__ method for the SE3 constructor, showing how it handles different argument scenarios.
```python
def __init(self, arg1=None, arg2=None, arg3=None, ... check=True):
if arg2 is None and arg3 is None:
# zero or one arguments passed
if super().arghandler(self, arg1, check=check, convertfrom=(Z,)):
return
else:
# deal with other one argument cases
elif ....
# process two and three argument cases
else:
# no idea how to handle what was passed
raise ValueError('bad argument to constructor')
```
--------------------------------
### Create a Pure Quaternion
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Demonstrates the creation of a pure quaternion (scalar part is zero) from a vector.
```python
Quaternion.Pure([1, 2, 3])
```
--------------------------------
### Spatialmath Animation Plotting
Source: https://github.com/rai-opensource/spatialmath-python/wiki/Animation
Example of plotting using the spatialmath animation framework.
```python
anim = Animate(ax)
anim.plot(1,2)
```
--------------------------------
### 2D Rotation Matrix (SO(2))
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/spatialmath/base/base.ipynb
Example of creating a 2D rotation matrix.
```python
R = rot2(math.pi/4)
R
```
```python
rot2(45, 'deg')
```
--------------------------------
### Unit quaternion
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Demonstrates the creation and manipulation of SE2 objects.
```python
T = SE2(1, 2) * SE2(45, unit='deg')
T
```
```python
plt.figure() # create a new figure
T.plot()
plt.grid(True)
```
--------------------------------
### Create Quaternions
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Demonstrates how to create two quaternion objects, q1 and q2, with specified scalar and vector parts.
```python
q1 = Quaternion([1,2,3,4])
q1
```
```python
q2 = Quaternion([5,6,7,8])
q2
```
--------------------------------
### Getting the dimension of the space
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/introduction.ipynb
Returns the dimension N of the space in which the transformation operates.
```python
T1.N
```
--------------------------------
### SO3 Class - Vectorized Operators
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/README.md
Examples of vectorized operations with SO3 objects.
```python
>>> A = R * SO3.Ry(0.5)
>>> len(R)
32
>>> A = SO3.Ry(0.5) * R
>>> len(R)
32
>>> A = R * R
>>> len(R)
32
```
--------------------------------
### Unit Quaternion Creation
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Demonstrates creating a unit quaternion representing a 30-degree rotation around the X-axis.
```python
q1 = UnitQuaternion.Rx(30, 'deg')
q1
```
--------------------------------
### Creating a Twist3 Object
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/introduction.ipynb
Demonstrates the creation of a `Twist3` object from an SE3 matrix.
```python
tw = Twist3(T)
tw
```
--------------------------------
### Specify a Python interpreter
Source: https://github.com/rai-opensource/spatialmath-python/wiki/Calling-from-MATLAB
Example of how to specify a Python interpreter from a conda environment.
```matlab
>> pyenv(Version="~/opt/miniconda3/envs/dev/bin/python")
```
--------------------------------
### Plotting a pose
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/docs/source/intro.md
Demonstrates plotting a SE3 pose as a coordinate frame.
```default
>>> X = SE3.Rand()
>>> X.plot()
```
--------------------------------
### Create Rotation using OA Constructor
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Creates a rotation matrix using orientation and approach vectors.
```python
SO3.OA(o=[0,0,-1], a=[1,0,0])
```
--------------------------------
### Group composition and inversion for SE3
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/introduction.ipynb
Demonstrates the composition (*) and inversion (inv()) operators for SE3 objects, showing that the results remain SE3 objects.
```python
T1 = SE3(1, 2, 3) * SE3.Rx(30, 'deg')
[type(T1), type(T1.inv()), type(T1*T1)]
```
--------------------------------
### Generating a Random SE3 Matrix and its Logarithm
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/introduction.ipynb
Demonstrates how to generate a random SE3 matrix and then compute its logarithmic representation (twist).
```python
T = SE3.Rand()
T
```
```python
T.log()
```
--------------------------------
### Translational Transformation in 2D
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/docs/source/intro.md
Shows how to create a 2D translation matrix using `transl2` with separate arguments.
```pycon
>>> from spatialmath.base import *
>>> transl2(1, 2)
array([[1., 0., 1.],
[0., 1., 2.],
[0., 0., 1.]])
```
--------------------------------
### 3D Rotation Matrix (SO(3))
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/spatialmath/base/base.ipynb
Example of creating a 3D rotation matrix around the x-axis.
```python
rotx(45, 'deg')
```
--------------------------------
### SE3 composition: translation then rotation
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Demonstrates composing a translation and a rotation using SE3 objects.
```python
T1 = SE3(1, 2, 3) * SE3.Rx(30, 'deg')
```
--------------------------------
### Getting the shape of the SE(3) matrix
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/introduction.ipynb
Returns the shape of the underlying SE(3) matrix.
```python
T1.shape
```
--------------------------------
### Displaying the multi-valued SE3 object
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/introduction.ipynb
Illustrates how the multi-valued SE3 object is displayed, showing each individual pose.
```python
T
```
--------------------------------
### 2D Homogeneous Transformation Matrix (SE(2))
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/spatialmath/base/base.ipynb
Example of creating a 2D homogeneous transformation matrix.
```python
T = transl2(1, 2)
T
```
```python
T = transl2([1, 2])
```
```python
plt.figure() # create a new figure
trplot2(T)
plt.grid(True)
```
```python
T = transl2(1, 2) @ trot2(45, 'deg')
T
```
```python
plt.figure() # create a new figure
trplot2(T)
plt.grid(True)
```
--------------------------------
### Recreating Unit Quaternion from Vector
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Recreates a unit quaternion from its vector components.
```python
UnitQuaternion.Vec3(a)
```
--------------------------------
### Vector Transformation
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/docs/source/intro.md
Demonstrates vector transformation using SO3, SE3, and UnitQuaternion objects.
```python
>>> from spatialmath import *
>>> v = [1, 2, 3]
>>> SO3.Rx(0.3) * v
array([[1. ],
[1.02411236],
[3.45704988]])
>>> SE3.Rx(0.3) * v
array([[1. ],
[1.02411236],
[3.45704988]])
>>> UnitQuaternion.Rx(0.3) * v
array([1. , 1.02411236, 3.45704988])
```
--------------------------------
### Inline Matplotlib Backend
Source: https://github.com/rai-opensource/spatialmath-python/wiki/Using-Jupyter-and-Colab
Example of using the '%matplotlib inline' magic command for static plots in Jupyter.
```python
%matplotlib inline
import matplotlib.pyplot as plt
from spatialmath.base import *
trplot(transl(1,2,3))
trplot(transl(2,3,4))
```
--------------------------------
### In-place operators for SE3
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/introduction.ipynb
Demonstrates the availability and usage of in-place operators (*=, **=) for SE3 objects.
```python
T = T1
T *= T2
T **= 2
```
--------------------------------
### Quaternion Creation
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/introduction.ipynb
Demonstrates how to create a quaternion object from a list of four numbers (scalar and vector components).
```python
q1 = Quaternion([1,2,3,4])
q1
```
--------------------------------
### Transforming Cube Vertices
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Applies a transformation (T1) to the cube vertices (P) to get new coordinates (Q).
```python
Q = T1 * P
```
--------------------------------
### List All Matplotlib Options
Source: https://github.com/rai-opensource/spatialmath-python/wiki/Using-Jupyter-and-Colab
Command to list all available matplotlib options.
```python
%matplotlib --list
```
--------------------------------
### Indexing a multi-valued SE3 object
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Shows how to access individual pose objects within a multi-valued SE3 object using indexing.
```python
T[3]
```
--------------------------------
### 3D Homogeneous Transformation Matrix (SE(3))
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/spatialmath/base/base.ipynb
Example of creating a 3D homogeneous transformation matrix, promoting SO(3) to SE(3).
```python
trotx(45, 'deg')
```
--------------------------------
### Plotting the second SE3 transformation
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Visualizes the second SE3 transformation.
```python
T2.plot(frame='2', color='red')
```
--------------------------------
### Basic Rotation and Matrix Multiplication
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/docs/source/intro.md
Demonstrates the use of `rotx` and `roty` for creating rotation matrices and the `@` operator for matrix multiplication.
```pycon
>>> from spatialmath.base import *
>>> rotx(0.3)
array([[ 1. , 0. , 0. ],
[ 0. , 0.95533649, -0.29552021],
[ 0. , 0.29552021, 0.95533649]])
>>> rotx(30, unit='deg')
array([[ 1. , 0. , 0. ],
[ 0. , 0.8660254, -0.5 ],
[ 0. , 0.5 , 0.8660254]])
>>> R = rotx(0.3) @ roty(0.2)
>>> R
array([[ 0.98006658, 0. , 0.19866933],
[ 0.0587108 , 0.95533649, -0.28962948],
[-0.18979606, 0.29552021, 0.93629336]])
```
--------------------------------
### Access SO(3) NumPy array from SE3 object
Source: https://github.com/rai-opensource/spatialmath-python/wiki/FAQ
Explains how to get the SO(3) rotation matrix as a NumPy array from an SE3 object using the .R property.
```python
>>> T.R
array([[ 1, 0, 0],
[ 0, 0.9553, -0.2955],
[ 0, 0.2955, 0.9553]])
```
--------------------------------
### Fastest way to build an SE(3) matrix
Source: https://github.com/rai-opensource/spatialmath-python/wiki/Timing
Code snippet demonstrating the fastest method to build an SE(3) matrix.
```python
T = np.zeros((4,4))
T[3,3] = 1
T[:3,:3] = R
T[:3,3] = t
```
--------------------------------
### Create Rotation using AngVec Constructor (Degrees)
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Creates a rotation matrix using angle-axis notation with degrees.
```python
SO3.AngVec(30, [1,2,3], unit='deg')
```
--------------------------------
### SE3 instance creation from NumPy matrix
Source: https://github.com/rai-opensource/spatialmath-python/wiki/Timing
Timing comparison for creating an SE3 instance from a NumPy matrix, with and without value checking.
```text
SE3(T1): 36.4 μs
SE3(T1 check=False): 1.35 μs
```
--------------------------------
### Quaternion Division
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Demonstrates quaternion division, which is equivalent to multiplying by the inverse.
```python
q1 / q2
```
--------------------------------
### Create a rigid-body transformation (rotation about x-axis)
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/docs/source/intro.md
Example of creating a rigid-body transformation that is a rotation about the x-axis of 30 degrees using the rotx function, resulting in a NumPy array.
```python
>>> from spatialmath.base import *
>>> rotx(30, 'deg')
array([[ 1. , 0. , 0. ],
[ 0. , 0.8660254, -0.5 ],
[ 0. , 0.5 , 0.8660254]])
```
--------------------------------
### Displaying values with printline
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/docs/source/intro.md
Demonstrates the compact text representation of a SE3 object using the printline method.
```pycon
>>> from spatialmath import *
>>> X = SE3.Rand()
>>> _ = X.printline()
t = -0.673, -0.759, 0.19; rpy/zyx = 64.9°, 35.8°, -4.69°
```
--------------------------------
### Create Rotation using AngVec Constructor (Radians)
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Creates a rotation matrix using angle-axis notation with radians.
```python
SO3.AngVec(pi/4, [1,0,0])
```
--------------------------------
### SE3 composition: rotation then translation
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Demonstrates composing a rotation and then a translation using SE3 objects, showing a different result from the previous order.
```python
T2 = SE3.Rx(30, 'deg') * SE3(1, 2, 3)
```
--------------------------------
### Exponentiating a Logarithm to Reconstitute an SE3 Matrix
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/introduction.ipynb
Shows how to exponentiate a logarithmic representation (twist) to obtain the original SE3 matrix, verifying the logarithm operation.
```python
lg = T.log()
SE3.Exp(lg)
```
--------------------------------
### Inverse motion
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Demonstrates how to find the inverse of a motion (translation) using the .inv() method.
```python
SE3.Ty(2).inv()
```
--------------------------------
### Animating a coordinate frame
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/docs/source/intro.md
Shows how to animate the motion of a coordinate frame from the null-pose.
```pycon
>>> X = SE3.Rand()
>>> X.animate(frame='A', arrow=False)
```
--------------------------------
### Creating an SE3 object with multiple values
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Shows how to create an SE3 object that holds multiple pose values, similar to a Python list.
```python
T = SE3( [ SE3.Rx(0), SE3.Rx(0.1), SE3.Rx(0.2), SE3.Rx(0.3), SE3.Rx(0.4)] )
```
--------------------------------
### Composing Twists
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/introduction.ipynb
Shows how twists can be composed, and that the result is equivalent to composing the corresponding SE3 transforms.
```python
T = SE3(1, 2, 3) * SE3.Rx(0.3)
tw = Twist3(T)
tw
```
```python
tw2 = tw * tw
tw2
```
```python
Twist3(T * T)
```
--------------------------------
### Visualize Orientation
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Visualizes the resulting orientation using matplotlib.
```python
plt.figure() # create a new figure
SE3().plot(frame='0', color='black', dims=[0,2])
R3.plot(frame='3')
```
--------------------------------
### Visualize composed motion
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Visualizing the composed motion T2.
```python
plt.figure() # create a new figure
SE3().plot(frame='0', dims=[-3,3], color='black')
T1.plot(frame='1', color='red')
T2.plot(frame='2')
```
--------------------------------
### Finding a Point on the Line of Action
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/introduction.ipynb
Demonstrates how to find a point that lies on the line of action of a twist.
```python
tw.pole()
```
--------------------------------
### Iterating through pose objects
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Demonstrates iterating through a pose object using a for loop and applying transformations to a coordinate vector within the loop.
```python
for x in T:
Q = x * P
# plot(Q)
```
--------------------------------
### Create a motion in x, y, and z directions
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Creating a motion with specified displacements in the X, Y, and Z directions.
```python
SE3(7, 8, 9)
```
--------------------------------
### Display the SO(3) matrix
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/introduction.ipynb
Displays the SO(3) matrix representing the rotation.
```python
R1
```
--------------------------------
### Creating a multi-valued SE3 object using linspace
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
A more concise way to create a multi-valued SE3 object using numpy.linspace for rotation angles.
```python
T = SE3.Rx( np.linspace(0, 0.5, 5) )
len(T)
```
--------------------------------
### Slicing a multi-valued SE3 object
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Illustrates slicing a multi-valued SE3 object to extract a sub-sequence of poses.
```python
T[1:-1:2]
```
--------------------------------
### Second Quaternion Creation
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/introduction.ipynb
Creates a second quaternion object for demonstrating operations.
```python
q2 = Quaternion([5,6,7,8])
q2
```
--------------------------------
### Creating an empty multi-valued SE3 object
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/introduction.ipynb
Shows how to create an empty SE3 object that can hold multiple values, equivalent to an empty list.
```python
T = SE3.Empty()
len(T)
```
--------------------------------
### Quaternion printing
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/README.md
Demonstrates printing a quaternion in a specific format using qprint.
```python
>>> qprint(q)
-60.000000 < 12.000000, 30.000000, 24.000000 >
```
--------------------------------
### Group Operations: Multiplication by Inverse
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/docs/source/intro.md
Demonstrates multiplication by the inverse using the '/' operator.
```python
>>> from spatialmath import *
>>> T = SE3.Rx(0.3)
>>> T / T
SE3(array([[1., 0., 0., 0.],
[0., 1., 0., 0.],
[0., 0., 1., 0.],
[0., 0., 0., 1.]]))
```
--------------------------------
### Group Operations: Inverse
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/docs/source/intro.md
Demonstrates the group inverse operation using the 'inv()' method and verifies it by composing with the original transform.
```python
>>> from spatialmath import *
>>> T = SE3.Rx(0.3)
>>> T * T.inv()
SE3(array([[1., 0., 0., 0.],
[0., 1., 0., 0.],
[0., 0., 1., 0.],
[0., 0., 0., 1.]]))
```
--------------------------------
### Visualizing composed rotations
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Visualizes the world coordinate frame, R1, and R2 to show the effect of composing rotations.
```python
fig = plt.figure() # create a new figure
SE3().plot(frame='0', color='black', dims=[0,2])
R1.plot(frame='1', color='red')
R2.plot(frame='2')
```
--------------------------------
### Translational Transformation in 2D with List/Tuple
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/docs/source/intro.md
Demonstrates `transl2` accepting a list or tuple for translation vectors.
```pycon
>>> from spatialmath.base import *
>>> transl2( [1,2] )
array([[1., 0., 1.],
[0., 1., 2.],
[0., 0., 1.]])
>>> transl2( (1,2) )
array([[1., 0., 1.],
[0., 1., 2.],
[0., 0., 1.]])
```
--------------------------------
### Calculating the Pitch of a Twist
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/introduction.ipynb
Shows how to calculate the pitch of a screw motion represented by a twist.
```python
tw.pitch()
```
--------------------------------
### Pose objects in list comprehensions
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Shows how to use pose objects within list comprehensions to apply transformations to coordinate vectors.
```python
np.array([ x * [0,1,0] for x in T])
```
--------------------------------
### Subtract Quaternions
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Illustrates the subtraction of quaternion q2 from q1, also performed element-wise.
```python
q1 - q2
```
--------------------------------
### Constructor overhead breakdown
Source: https://github.com/rai-opensource/spatialmath-python/wiki/Timing
Breakdown of constructor overhead, including getvector and SE3 instantiation.
```text
getvector(x): 1.46 μs
SE3(): 2.93 μs
```
--------------------------------
### Symbolic Matrix Creation
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/spatialmath/base/README.md
Demonstrates creating a symbolic rotation matrix using sympy and printing its elements.
```python
import sympy
theta = sym.symbols('theta')
print(rotx(theta))
[[1 0 0]
[0 cos(theta) -sin(theta)]
[0 sin(theta) cos(theta)]]
```
--------------------------------
### Identity element constructor
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/docs/source/intro.md
Creating identity elements for UnitQuaternion and SE3 using constructors with no arguments.
```pycon
>>> from spatialmath import *
>>> UnitQuaternion()
UnitQuaternion(array([1., 0., 0., 0.]))
>>> SE3()
SE3(array([[1., 0., 0., 0.],
[0., 1., 0., 0.],
[0., 0., 1., 0.],
[0., 0., 0., 1.]]))
```
--------------------------------
### Creating SE2 from List
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Creates an SE(2) transformation matrix using a list of translation components.
```python
T = SE2([1, 2])
```
--------------------------------
### Creating SE2 Homogeneous Transformation Matrix
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Creates a 3x3 homogeneous transformation matrix for SE(2) with translation.
```python
T = SE2(1, 2)
T
```
--------------------------------
### Plotting SE3 transformations
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Visualizes the SE3 transformation using matplotlib.
```python
plt.figure() # create a new figure
SE3().plot(frame='0', dims=[0,3], color='black')
T1.plot(frame='1')
```
--------------------------------
### Creating a translation and rotation matrix
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/introduction.ipynb
Creates a transformation by first translating and then rotating about the X-axis by 30 degrees.
```python
T1 = SE3(1, 2, 3) * SE3.Rx(30, 'deg')
T1
```
--------------------------------
### Extract Vector Part
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Demonstrates how to access the vector part of a quaternion object.
```python
q1.v
```
--------------------------------
### Spatial math class overhead
Source: https://github.com/rai-opensource/spatialmath-python/wiki/Timing
Timing for SE3.Rx, showing overhead in the instance constructor.
```text
SE3.Rx: 10.9 μs
```
--------------------------------
### Animating a transform
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/README.md
Demonstrates creating an animation of a transform using tranimate.
```python
tranimate(transl(4, 3, 4)@trotx(2)@troty(-2), frame='A', arrow=False, dims=[0, 5], nframes=200)
```
--------------------------------
### Converting Quaternion to SO3 Object
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Converts a unit quaternion to an SO3 object.
```python
q1.SO3()
```
--------------------------------
### Calculating the Logarithm of the Adjoint Matrix
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/introduction.ipynb
Shows how to compute the logarithm of the adjoint matrix for a twist.
```python
tw.ad()
```
--------------------------------
### Add Quaternions
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Shows the addition of two quaternion objects, q1 and q2, which is performed element-wise.
```python
q1 + q2
```
--------------------------------
### Displaying animation in Jupyter/Colab
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/README.md
Demonstrates how to display an animation inline in a Jupyter notebook or Colab using tranimate with movie=True and IPython.core.display.HTML.
```python
from IPython.core.display import HTML
HTML(tranimate(transl(4, 3, 4)@trotx(2)@troty(-2), frame='A', arrow=False, dims=[0, 5], nframes=200, movie=True))
```
--------------------------------
### Calculating the Adjoint Matrix of a Twist
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/introduction.ipynb
Demonstrates how to compute the adjoint matrix of a twist, which relates velocities.
```python
tw.Ad()
```
--------------------------------
### Visualizing a rotation
Source: https://github.com/rai-opensource/spatialmath-python/blob/master/notebooks/gentle-introduction.ipynb
Visualizes the world coordinate frame and a frame rotated by R1 around the x-axis.
```python
fig = plt.figure() # create a new figure
SE3().plot(frame='0', color='black', dims=[0,2])
R1.plot(frame='1')
```
--------------------------------
### Convert SE3 to SO3
Source: https://github.com/rai-opensource/spatialmath-python/wiki/FAQ
Shows how to convert an SE3 object to an SO3 object using the SO3 constructor.
```python
>>> SO3(T)
1 0 0
0 0.9553 -0.2955
0 0.2955 0.9553
```