SO(3) Math Module Documentation
This module provides functions to work in the special orthogonal group SO(3) and its Lie algebra so(3).
Functions:
| Name | Description |
|---|---|
rot_inv |
Compute the inverse of a rotation matrix. |
hpr2quat |
Convert Heading, Pitch and Roll (HPR) angles to quaternion using the ZYX Euler angles convention. |
rph2quat |
Convert Roll, Pitch, Heading (RPH) angles to quaternion using the ZYX Euler angles convention. |
quat2hpr |
Convert quaternion to Heading, Pitch and Roll (HPR) angles using the ZYX Euler angles convention. |
quat2rph |
Convert quaternion to Roll, Pitch, Heading (RPH) angles using the ZYX Euler angles convention. |
hpr2rot |
Convert Heading, Pitch and Roll (HPR) angles to SO(3) rotation matrix using the ZYX Euler angles convention. |
rph2rot |
Convert Roll, Pitch, Heading (RPH) angles to SO(3) rotation matrix using the ZYX Euler angles convention. |
quat2rot |
Convert quaternion to a rotation matrix in SO(3) using the ZYX Euler angles convention. |
rot2hpr |
Convert SO(3) rotation matrix to Roll, Pitch, Heading (RPH) angles using the ZYX Euler angles convention. |
rot2rph |
Convert SO(3) rotation matrix to Roll, Pitch, Heading (RPH) angles using the ZYX Euler angles convention. |
rot2quat |
Convert SO(3) rotation matrix to quaternion using the ZYX Euler angles convention. |
rot_diff |
Compute the relative rotation between two matrices. |
vec_to_so3 |
Compute the skew-symmetric representation for a vector of R3. |
so3_to_vec |
Convert a so3 matrix into a R3 vector. |
axis_ang3 |
Converts a R3 representing a rotation into a exponential coordinates parametrization. |
matrix_exp3 |
Compute the matrix exponential of a matrix in so(3) representing the exponential coordinates for rotation. |
matrix_log3 |
Compute the matrix logarithm of a matrix in SO(3) representing the exponential coordinates for rotation. |
project_to_so3 |
Project a matrix in R3 to SO(3). |
distance_to_so3 |
Compute the distance between two matrices in SO(3). |
left_quat_product_matrix |
Compute the left quaternion product matrix for a quaternion. |
right_quat_product_matrix |
Compute the right quaternion product matrix for a quaternion. |
axis_ang3(vec)
Converts a \(\mathbf{R}^3\) representing a rotation into a exponential coordinates parametrization, i.e., a unit vector representing the axis (w) and an angle theta.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vec
|
Union[Iterable[float], ndarray]
|
R3 vector representing a rotation in so3. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
axis |
ndarray
|
Unit vector representing the axis of rotation as a numpy array. |
angle |
float
|
Angle of rotation in radians. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input vector is not a numpy array or a list. |
ValueError
|
If the input vector does not have 3 components. |
Examples:
>>> vec = np.array([1, 2, 3])
>>> axis, angle = axis_ang_3(vec)
>>> print(axis)
[0.26726124 0.53452248 0.80178373]
>>> print(angle)
3.7416573867739413
Source code in navlib/math/so3.py
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 | |
distance_to_so3(mat)
Compute the frobenius norm to describe the distance of a matrix from the SO(3) manifold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mat
|
ndarray
|
The matrix as a (3,3) numpy array. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dist_so3 |
float
|
The frobenius norm as a float. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input matrix is not a (3,3) numpy array. |
Examples:
>>> mat = np.array([[ 0.675, 0.150, 0.720],
[ 0.370, 0.771, -0.511],
[-0.630, 0.619, 0.472]])
>>> dist = distanceToSO3(mat)
>>> print(dist)
0.0663128178912833
Source code in navlib/math/so3.py
842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 | |
hpr2quat(hpr)
Convert Heading, Pitch and Roll (HPR) angles to quaternion using the ZYX Euler angles convention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hpr
|
Union[ndarray, Iterable[float]]
|
hpr angles in radians as a numpy array or as a list. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
quat |
ndarray
|
The quaternion using hpr with the convention ZYX in order (x, y, z, w) |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input HPR angles are not a 3-element numpy array or list. |
Examples:
>>> hpr = np.array([0.3, 0.2, 0.1])
>>> quat = hpr2quat(hpr)
>>> print(quat)
[0.93629336 0.28962948 0.19866933 0.0978434 ]
Notes
The HPR angles represent rotations around the Z, Y, and X axes, respectively. The resulting quaternion represents a rotation of the input HPR angles using the ZYX Euler angles convention.
Source code in navlib/math/so3.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
hpr2rot(hpr)
Convert Heading, Pitch and Roll (HPR) angles to SO(3) rotation matrix using the ZYX Euler angles convention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hpr
|
Union[ndarray, Iterable[float]]
|
hpr angles in radians as a numpy array or as a list. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
rot |
ndarray
|
The rotation matrix using hpr with the convention ZYX |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input HPR angles are not a 3-element numpy array or list. |
Examples:
>>> hpr = np.array([0.3, 0.2, 0.1])
>>> rot_mat = hpr2rot(hpr)
>>> print(rot_mat)
[[ 0.93629336 -0.27509585 0.21835066]
[ 0.28962948 0.95642509 -0.03695701]
[-0.19866933 0.0978434 0.97517033]]
Notes
The HPR angles represent rotations around the Z, Y, and X axes, respectively. The resulting rotation matrix represents a rotation of the input HPR angles using the ZYX Euler angles convention.
Source code in navlib/math/so3.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | |
left_quat_product_matrix(quat)
Compute the left quaternion product matrix for a given quaternion, such that q * p = L(q) * p. For a quaternion q = (x, y, z, w), the left quaternion product matrix is defined as:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quat
|
Union[ndarray, Iterable[float]]
|
The quaternion as a numpy array or as a list in the order (x, y, z, w). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
left_quat_product_matrix |
ndarray
|
The left quaternion product matrix as a (4, 4) numpy array. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input quaternion is not a 4-element numpy array or list. |
ValueError
|
If the input quaternion is not normalized. |
TypeError
|
If the input quaternion is not a numpy array or list. |
Source code in navlib/math/so3.py
929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 | |
matrix_exp3(mat)
Compute the matrix exponential of a matrix in so(3) representing the exponential coordinates for rotation, i.e., [w]*theta, where [w] is the skew-symmetric matrix of the unitary rotation axis. To compute the exponential matrix, the Rodrigues' formula is used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mat
|
ndarray
|
Skew-symmetric matrix representing the exponential coordinates of rotation as a (3, 3) numpy array. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
mat_exp3 |
ndarray
|
Matrix exponential of the exponential coordinates as a numpy array. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input matrix is not a (3,3) numpy array. |
ValueError
|
If the input matrix is not a skew-symmetric matrix. |
Examples:
>>> skew_sym = np.array([[0, -3, 2], [3, 0, -1], [-2, 1, 0]])
>>> exp_mat = matrix_exp_3(skew_sym)
>>> print(exp_mat)
[[-0.69492056 0.71352099 0.08929286]
[-0.19200697 -0.30378504 0.93319235]
[ 0.69297817 0.63134970 0.34810748]]
Source code in navlib/math/so3.py
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 | |
matrix_log3(R)
Computes the matrix logarithm of a rotation matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
R
|
ndarray
|
Rotation matrix as a (3, 3) numpy array. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
mat_log3 |
ndarray
|
Matrix logarithm of the rotation matrix as a numpy array. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input matrix is not a (3,3) numpy array. |
ValueError
|
If the input matrix is not a rotation matrix. |
Examples:
>>> rot_mat = np.array([[0.93629336, -0.27509585, 0.21835066],
[0.28962948, 0.95642509, -0.03695701],
[-0.19866933, 0.0978434, 0.97517033]])
>>> log_mat = matrix_log_3(rot_mat)
>>> print(log_mat)
[[ 0. , -0.28874894, 0.21322592],
[ 0.28874894, 0. , -0.06892461],
[-0.21322592, 0.06892461, 0. ]]
Source code in navlib/math/so3.py
738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 | |
project_to_so3(mat)
Projects a matrix to the closest matrix in SO(3) using singular value decomposition. Source: http://hades.mech.northwestern.edu/index.php/Modern_Robotics_Linear_Algebra_Review
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mat
|
ndarray
|
The matrix as a (3,3) numpy array. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
mat_so3 |
ndarray
|
The closest matrix in SO(3) as a numpy array. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input matrix is not a (3,3) numpy array. |
Examples:
>>> mat = np.array([[ 0.675, 0.150, 0.720],
[ 0.370, 0.771, -0.511],
[-0.630, 0.619, 0.472]])
>>> proj_mat = projectToSO3(mat)
>>> print(proj_mat)
[[ 0.67901136, 0.14894516, 0.71885945],
[ 0.37320708, 0.77319584, -0.51272279],
[-0.63218672, 0.61642804, 0.46942137]]
Source code in navlib/math/so3.py
799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 | |
quat2hpr(quat)
Convert quaternion to Heading, Pitch and Roll (HPR) angles using the ZYX Euler angles convention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quat
|
Union[ndarray, Iterable[float]]
|
The quaternion as a numpy array or as a list in the order (x, y, z, w). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
hpr |
ndarray
|
The HPR angles in radians as a numpy array with the convention ZYX. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input quaternion is not a 4-element numpy array or list. |
ValueError
|
If the input quaternion is not normalized. |
Examples:
>>> quat = np.array([0.93629336, 0.28962948, 0.19866933, 0.0978434])
>>> hpr = quat2hpr(quat)
>>> print(hpr)
[0.3 0.2 0.1]
Notes
The resulting HPR angles represent rotations around the Z, Y, and X axes, respectively. The input quaternion must be normalized to represent a valid rotation.
Source code in navlib/math/so3.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
quat2rot(quat)
Convert quaternion to a rotation matrix in SO(3) using the ZYX Euler angles convention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quat
|
Union[ndarray, Iterable[float]]
|
The quaternion as a numpy array or as a list in the order (x, y, z, w). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
rot |
ndarray
|
The RPH angles in radians as a numpy array with the convention ZYX. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input quaternion is not a 4-element numpy array or list. |
ValueError
|
If the input quaternion is not normalized. |
Examples:
>>> quat = np.array([0.93629336, 0.28962948, 0.19866933, 0.0978434])
>>> rotmat = quat2rot(quat)
>>> print(rotmat)
[[ 0.93629336 -0.27509585 0.21835066]
[ 0.28962948 0.95642509 -0.03695701]
[-0.19866933 0.0978434 0.97517033]]
Notes
The input quaternion must be normalized to represent a valid rotation.
Source code in navlib/math/so3.py
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | |
quat2rph(quat)
Convert quaternion to Roll, Pitch, Heading (RPH) angles using the ZYX Euler angles convention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quat
|
Union[ndarray, Iterable[float]]
|
The quaternion as a numpy array or as a list in the order (x, y, z, w). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
rph |
ndarray
|
The RPH angles in radians as a numpy array with the convention ZYX. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input quaternion is not a 4-element numpy array or list. |
ValueError
|
If the input quaternion is not normalized. |
Examples:
>>> quat = np.array([0.93629336, 0.28962948, 0.19866933, 0.0978434])
>>> rph = quat2rph(quat)
>>> print(rph)
[0.1 0.2 0.3]
Notes
The resulting RPH angles represent rotations around the X, Y, and Z axes, respectively. The input quaternion must be normalized to represent a valid rotation.
Source code in navlib/math/so3.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | |
right_quat_product_matrix(quat)
Compute the right quaternion product matrix for a given quaternion, such that q * p = R(p) * q For a quaternion q = (x, y, z, w), the right quaternion product matrix is defined as:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quat
|
Union[ndarray, Iterable[float]]
|
The quaternion as a numpy array or as a list in the order (x, y, z, w). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
right_quat_product_matrix |
ndarray
|
The right quaternion product matrix as a (4, 4) numpy array. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input quaternion is not a 4-element numpy array or list. |
ValueError
|
If the input quaternion is not normalized. |
TypeError
|
If the input quaternion is not a numpy array or list. |
Source code in navlib/math/so3.py
991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 | |
rot2hpr(rot)
Convert SO(3) rotation matrix to Roll, Pitch, Heading (RPH) angles using the ZYX Euler angles convention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rot
|
ndarray
|
The rotation matrix as a (3,3) numpy array. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
hpr |
ndarray
|
The RPH angles in radians as a numpy array with the convention ZYX. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input rotation matrix is not a (3,3) numpy array or list. |
Examples:
>>> rot_mat = np.array([[0.93629336, -0.27509585, 0.21835066],
[0.28962948, 0.95642509, -0.03695701],
[-0.19866933, 0.0978434, 0.97517033]])
>>> hpr = rot2hpr(rot_mat)
>>> print(hpr)
[0.3 0.2 0.1]
Notes
The resulting RPH angles represent rotations around the X, Y, and Z axes, respectively. The input rotation matrix must be orthonormal and have a determinant of +1 to represent a valid rotation.
Source code in navlib/math/so3.py
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 | |
rot2quat(rot)
Convert SO(3) rotation matrix to quaternion using the ZYX Euler angles convention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rot
|
ndarray
|
The rotation matrix as a (3,3) numpy array. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
quat |
ndarray
|
The quaternion as a numpy array with the convention ZYX in order (x, y, z, w) |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input rotation matrix is not a (3,3) numpy array. |
Examples:
>>> rot_mat = np.array([[0.50000000, -0.1464466, 0.8535534],
[0.50000000, 0.8535534, -0.1464466],
[-0.7071068, 0.5000000, 0.5000000]])
>>> quat = rot2quat(rot_mat)
>>> print(quat)
[0.1913417, 0.4619398, 0.1913417, 0.8446232]
Notes
The input rotation matrix must be orthonormal and have a determinant of +1 to represent a valid rotation.
Source code in navlib/math/so3.py
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 | |
rot2rph(rot)
Convert SO(3) rotation matrix to Roll, Pitch, Heading (RPH) angles using the ZYX Euler angles convention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rot
|
ndarray
|
The rotation matrix as a (3,3) numpy array. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
rph |
ndarray
|
The RPH angles in radians as a numpy array with the convention ZYX. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input rotation matrix is not a (3,3) numpy array. |
Examples:
>>> rot_mat = np.array([[0.93629336, -0.27509585, 0.21835066],
[0.28962948, 0.95642509, -0.03695701],
[-0.19866933, 0.0978434, 0.97517033]])
>>> rph = rot2rph(rot_mat)
>>> print(rph)
[0.1 0.2 0.3]
Notes
The resulting RPH angles represent rotations around the X, Y, and Z axes, respectively. The input rotation matrix must be orthonormal and have a determinant of +1 to represent a valid rotation.
Source code in navlib/math/so3.py
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 | |
rot_diff(rot_1, rot_2)
Compute the relative rotation between two matrices.
The returned matrix is the attitude of 2 with respect to 1:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rot_1
|
ndarray
|
Rotation matrix for attitude 1 as a numpy array. |
required |
rot_2
|
ndarray
|
Rotation matrix for attitude 2 as a numpy array. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
rot_1_2 |
ndarray
|
The attitude of 2 with respect to 1 as a numpy array. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input rotation matrices are not (3,3) numpy arrays. |
Examples:
>>> rot_mat_1 = np.array([[0.93629336, -0.27509585, 0.21835066],
[0.28962948, 0.95642509, -0.03695701],
[-0.19866933, 0.0978434, 0.97517033]])
>>> rot_mat_2 = np.array([[0.82298387, -0.41998535, 0.38175244],
[0.56975033, 0.81758362, -0.08209422],
[-0.0, 0.3939193, 0.91914503]])
>>> rot_diff = rotDiff(rot_mat_1, rot_mat_2)
>>> print(rot_diff)
[[ 0.93557083, -0.23469286, 0.15104944],
[ 0.31852406, 0.93603611, -0.09360322],
[ 0.1586428 , 0.26221888, 0.98271281]]
Notes
The input rotation matrices must be orthonormal and have a determinant of +1 to represent valid rotations.
Source code in navlib/math/so3.py
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 | |
rot_inv(rot)
Compute the inverse of a rotation matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rot
|
ndarray
|
The rotation matrix as a (3,3) numpy array. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
rot_mat |
ndarray
|
The inverse of the rotation matrix as a (3,3) numpy array. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input rotation matrix is not a (3,3) numpy array. |
Examples:
>>> rot_mat = np.array([[0.93629336, -0.27509585, 0.21835066],
[0.28962948, 0.95642509, -0.03695701],
[-0.19866933, 0.0978434, 0.97517033]])
>>> rot_inv = rot_inv(rot_mat)
>>> print(rot_inv)
[[ 0.93629336 0.28962948 -0.19866933]
[-0.27509585 0.95642509 0.0978434 ]
[ 0.21835066 -0.03695701 0.97517033]]
Notes
The input rotation matrix must be orthonormal and have a determinant of +1 to represent a valid rotation.
Source code in navlib/math/so3.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
rph2quat(rph)
Convert Roll, Pitch, Heading (RPH) angles to quaternion using the ZYX Euler angles convention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rph
|
Union[ndarray, Iterable[float]]
|
rph angles in radians as a numpy array or as a list. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
quat |
ndarray
|
The quaternion using rph with the convention ZYX in order (x, y, z, w) |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input RPH angles are not a 3-element numpy array or list. |
Examples:
>>> rph = np.array([0.1, 0.2, 0.3])
>>> quat = rph2quat(rph)
>>> print(quat)
[0.93629336 0.28962948 0.19866933 0.0978434 ]
Notes
The RPH angles represent rotations around the X, Y, and Z axes, respectively. The resulting quaternion represents a rotation of the input RPH angles using the ZYX Euler angles convention.
Source code in navlib/math/so3.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
rph2rot(rph)
Convert Roll, Pitch, Heading (RPH) angles to SO(3) rotation matrix using the ZYX Euler angles convention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rph
|
Union[ndarray, Iterable[float]]
|
rph angles in radians as a numpy array or as a list. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
rot |
ndarray
|
The rotation matrix using rph with the convention ZYX |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input RPH angles are not a 3-element numpy array or list. |
Examples:
>>> rph = np.array([0.1, 0.2, 0.3])
>>> rot_mat = rph2rot(rph)
>>> print(rot_mat)
[[ 0.93629336 -0.27509585 0.21835066]
[ 0.28962948 0.95642509 -0.03695701]
[-0.19866933 0.0978434 0.97517033]]
Notes
The RPH angles represent rotations around the X, Y, and Z axes, respectively. The resulting rotation matrix represents a rotation of the input RPH angles using the ZYX Euler angles convention.
Source code in navlib/math/so3.py
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 | |
so3_optimization(objective_function, *args, **kwargs)
Perform optimization on the Special Orthogonal Group (SO(3)). This function uses the pymanopt library to optimize a given objective function on the SO(3) manifold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
objective_function
|
Callable
|
The objective function to be optimized. If the cost function uses numpy for computations, it MUST use the numpy module from autograd, i.e., autograd.numpy. Also, the function must return a scalar value. |
required |
*args
|
Any
|
Positional arguments to be passed to the objective function. |
()
|
**kwargs
|
Any
|
Keyword arguments to be passed to the objective function. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
mat_so3_opt |
ndarray
|
The optimized SO(3) matrix as a numpy array. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the objective_function is not callable. |
ValueError
|
If the optimization does not return a valid SO(3) matrix. |
ValueError
|
If the result is not a (3,3) numpy array. |
Notes
For the cost function you can use import autograd.numpy as np to
use numpy functions.
Source code in navlib/math/so3.py
880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 | |
so3_to_vec(mat)
Convert a so3 matrix into a \(\mathbf{R}^3\) vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mat
|
ndarray
|
The skew-symmetric matrix as a (3,3) numpy array. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
vec |
ndarray
|
The vector as a (3, ) numpy array. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input matrix is not a (3,3) numpy array. |
Examples:
>>> skew_sym = np.array([[0, -3, 2], [3, 0, -1], [-2, 1, 0]])
>>> vec = so3_to_vec(skew_sym)
>>> print(vec)
[1. 2. 3.]
Source code in navlib/math/so3.py
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 | |
vec_to_so3(vec)
Compute the skew-symmetric representation for a vector of \(\mathbf{R}^3\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vec
|
Union[ndarray, Iterable[float]]
|
The vector as a numpy array or a list. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
skew |
ndarray
|
The skew-symmetric matrix as a numpy array. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input vector is not a numpy array or a list. |
ValueError
|
If the input vector does not have 3 components. |
Examples:
>>> vec = np.array([1, 2, 3])
>>> skew_sym = vec_to_so3(vec)
>>> print(skew_sym)
[[ 0. -3. 2.]
[ 3. 0. -1.]
[-2. 1. 0.]]
Source code in navlib/math/so3.py
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 | |