-
Notifications
You must be signed in to change notification settings - Fork 637
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
138 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.. _pyexample_matrices: | ||
|
||
==================================================== | ||
Python example: matrices.py | ||
==================================================== | ||
|
||
This example shows how to create, manipulate, and print MRPT matrix classes in Python, | ||
as well as converting from/to numpy matrices. | ||
|
||
.. literalinclude:: ../../python-examples/matrices.py | ||
:language: python | ||
:linenos: | ||
|
||
|
||
Output: | ||
|
||
.. literalinclude:: ../../python-examples/matrices.out | ||
:linenos: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
l1 : P=[ 0.00000, 0.00000, 0.00000] u=[ 1.00000, 0.00000, 0.00000] | ||
l2 : P=[ 1.00000, 1.00000, 1.00000] u=[ 1.00000, 1.00000, -1.00000] | ||
dist(l1,l2) : 1.414213562373095 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
m1_np : | ||
[[1 2 3] | ||
[4 5 6] | ||
[7 8 9]] | ||
|
||
m1_mrpt : | ||
11 12 13 | ||
14 15 16 | ||
17 18 19 | ||
m1_mrpt.size() :(3, 3) | ||
|
||
m2_data: [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]] | ||
m2_np: | ||
[[1. 0. 0.] | ||
[0. 1. 0.] | ||
[0. 0. 1.]] | ||
|
||
m2 modified: | ||
1 0 99 | ||
0 1 0 | ||
0 0 1 | ||
m2[1,1]=1.0 | ||
|
||
m3_np: | ||
[[1 2] | ||
[3 4]] | ||
m3_mrpt: | ||
1 2 | ||
3 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# --------------------------------------------------------------------- | ||
# Install python3-pymrpt, ros-$ROS_DISTRO-mrpt2, or test with a local build with: | ||
# export PYTHONPATH=$HOME/code/mrpt/build-Release/:$PYTHONPATH | ||
# --------------------------------------------------------------------- | ||
|
||
# More matrix classes available in the module mrpt.math. | ||
# See: https://mrpt.github.io/pymrpt-docs/mrpt.pymrpt.mrpt.math.html | ||
|
||
from mrpt import pymrpt | ||
import numpy as np | ||
mrpt = pymrpt.mrpt | ||
|
||
# Create a numpy matrix from a list: | ||
m1_np = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) | ||
|
||
print('m1_np :\n' + str(m1_np)) | ||
print() | ||
|
||
# Create an MRPT matrix from a list: | ||
m1_mrpt = mrpt.math.CMatrixDynamic_double_t( | ||
[[11, 12, 13], [14, 15, 16], [17, 18, 19]]) | ||
|
||
print('m1_mrpt :\n' + str(m1_mrpt)) | ||
print('m1_mrpt.size() :' + str(m1_mrpt.size())) | ||
print() | ||
|
||
# Convert an MRPT matrix to numpy via an intermediary list: | ||
m2_mrpt = mrpt.math.CMatrixDynamic_double_t.Identity(3) | ||
m2_data = m2_mrpt.to_list() | ||
print('m2_data: {}'.format(m2_data)) | ||
m2_np = np.array(m2_data) | ||
print('m2_np:\n{}'.format(m2_np)) | ||
print() | ||
|
||
# Read/write access an MRPT matrix (0-based indices) | ||
m2_mrpt[0, 2] = 99.0 # modify the entry (0,2) | ||
print('m2 modified:\n{}'.format(m2_mrpt)) | ||
m2_mrpt[0, 2] = 99.0 # modify the entry (0,2) | ||
print('m2[1,1]={}'.format(m2_mrpt[1, 1])) | ||
print() | ||
|
||
# Convert a numpy matrix to MRPT: | ||
m3_np = np.array([[1, 2], [3, 4]]) | ||
m3_mrpt = mrpt.math.CMatrixDynamic_double_t(m3_np.tolist()) | ||
print('m3_np:\n{}'.format(m3_np)) | ||
print('m3_mrpt:\n{}'.format(m3_mrpt)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
p1 : (1.000,2.000,90.00deg) | ||
p2 : (3.000,0.000,0.00deg) | ||
p1(+)p2 : (1.000,5.000,90.00deg) | ||
(p1(+)p2)(-)p1 : (3.000,-0.000,0.00deg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
p1 : (x,y,z,yaw,pitch,roll)=(1.0000,2.0000,0.0000,90.00deg,0.00deg,0.00deg) | ||
p2 : (x,y,z,yaw,pitch,roll)=(3.0000,0.0000,0.0000,0.00deg,0.00deg,0.00deg) | ||
p1(+)p2 : (x,y,z,yaw,pitch,roll)=(1.0000,5.0000,0.0000,90.00deg,-0.00deg,0.00deg) | ||
(p1(+)p2)(-)p1 : (x,y,z,yaw,pitch,roll)=(3.0000,-0.0000,0.0000,0.00deg,-0.00deg,0.00deg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters