|
15 | 15 | }, |
16 | 16 | { |
17 | 17 | "cell_type": "code", |
18 | | - "execution_count": null, |
| 18 | + "execution_count": 13, |
19 | 19 | "metadata": {}, |
20 | 20 | "outputs": [], |
21 | 21 | "source": [ |
|
26 | 26 | "%pip install roboticstoolbox-python --break-system-packages" |
27 | 27 | ] |
28 | 28 | }, |
| 29 | + { |
| 30 | + "cell_type": "markdown", |
| 31 | + "metadata": {}, |
| 32 | + "source": [ |
| 33 | + "# Macros\n", |
| 34 | + "\n", |
| 35 | + "$\\providecommand{\\myvec}[1]{{\\mathbf{\\boldsymbol{{#1}}}}}$\n", |
| 36 | + "$\\providecommand{\\mymatrix}[1]{{\\mathbf{\\boldsymbol{{#1}}}}}$" |
| 37 | + ] |
| 38 | + }, |
| 39 | + { |
| 40 | + "cell_type": "raw", |
| 41 | + "metadata": { |
| 42 | + "vscode": { |
| 43 | + "languageId": "raw" |
| 44 | + } |
| 45 | + }, |
| 46 | + "source": [ |
| 47 | + "\\providecommand{\\myvec}[1]{{\\mathbf{\\boldsymbol{{#1}}}}}\n", |
| 48 | + "\\providecommand{\\mymatrix}[1]{{\\mathbf{\\boldsymbol{{#1}}}}}" |
| 49 | + ] |
| 50 | + }, |
29 | 51 | { |
30 | 52 | "cell_type": "markdown", |
31 | 53 | "metadata": {}, |
|
35 | 57 | }, |
36 | 58 | { |
37 | 59 | "cell_type": "code", |
38 | | - "execution_count": null, |
| 60 | + "execution_count": 14, |
39 | 61 | "metadata": {}, |
40 | 62 | "outputs": [], |
41 | 63 | "source": [ |
|
55 | 77 | }, |
56 | 78 | { |
57 | 79 | "cell_type": "code", |
58 | | - "execution_count": null, |
| 80 | + "execution_count": 15, |
59 | 81 | "metadata": {}, |
60 | | - "outputs": [], |
| 82 | + "outputs": [ |
| 83 | + { |
| 84 | + "name": "stdout", |
| 85 | + "output_type": "stream", |
| 86 | + "text": [ |
| 87 | + " \u001b[38;5;1m 0 \u001b[0m \u001b[38;5;1m-1 \u001b[0m \u001b[38;5;4m 1 \u001b[0m \u001b[0m\n", |
| 88 | + " \u001b[38;5;1m 1 \u001b[0m \u001b[38;5;1m 0 \u001b[0m \u001b[38;5;4m 2 \u001b[0m \u001b[0m\n", |
| 89 | + " \u001b[38;5;244m 0 \u001b[0m \u001b[38;5;244m 0 \u001b[0m \u001b[38;5;244m 1 \u001b[0m \u001b[0m\n", |
| 90 | + "\n", |
| 91 | + "The original SE(2) object was \n", |
| 92 | + " \u001b[38;5;1m 0 \u001b[0m \u001b[38;5;1m-1 \u001b[0m \u001b[38;5;4m 1 \u001b[0m \u001b[0m\n", |
| 93 | + " \u001b[38;5;1m 1 \u001b[0m \u001b[38;5;1m 0 \u001b[0m \u001b[38;5;4m 2 \u001b[0m \u001b[0m\n", |
| 94 | + " \u001b[38;5;244m 0 \u001b[0m \u001b[38;5;244m 0 \u001b[0m \u001b[38;5;244m 1 \u001b[0m \u001b[0m\n", |
| 95 | + "\n", |
| 96 | + " and can be converted to: \n", |
| 97 | + "\tA rotation matrix \n", |
| 98 | + "[[ 6.123234e-17 -1.000000e+00]\n", |
| 99 | + " [ 1.000000e+00 6.123234e-17]]\n", |
| 100 | + " that has size = (2, 2).\n", |
| 101 | + "\tA position vector \n", |
| 102 | + "[1. 2.]\n", |
| 103 | + " that has size = (2,).\n", |
| 104 | + "\tA homogenous transformation matrix \n", |
| 105 | + "[[ 6.123234e-17 -1.000000e+00 1.000000e+00]\n", |
| 106 | + " [ 1.000000e+00 6.123234e-17 2.000000e+00]\n", |
| 107 | + " [ 0.000000e+00 0.000000e+00 1.000000e+00]]\n", |
| 108 | + " that has size = (3, 3).\n" |
| 109 | + ] |
| 110 | + } |
| 111 | + ], |
61 | 112 | "source": [ |
62 | 113 | "import numpy as np\n", |
63 | 114 | "import spatialmath as sm\n", |
|
91 | 142 | }, |
92 | 143 | { |
93 | 144 | "cell_type": "code", |
94 | | - "execution_count": null, |
| 145 | + "execution_count": 16, |
95 | 146 | "metadata": {}, |
96 | | - "outputs": [], |
| 147 | + "outputs": [ |
| 148 | + { |
| 149 | + "name": "stdout", |
| 150 | + "output_type": "stream", |
| 151 | + "text": [ |
| 152 | + " \u001b[38;5;1m 0 \u001b[0m \u001b[38;5;1m-1 \u001b[0m \u001b[38;5;1m 0 \u001b[0m \u001b[38;5;4m 1 \u001b[0m \u001b[0m\n", |
| 153 | + " \u001b[38;5;1m 1 \u001b[0m \u001b[38;5;1m 0 \u001b[0m \u001b[38;5;1m 0 \u001b[0m \u001b[38;5;4m 2 \u001b[0m \u001b[0m\n", |
| 154 | + " \u001b[38;5;1m 0 \u001b[0m \u001b[38;5;1m 0 \u001b[0m \u001b[38;5;1m 1 \u001b[0m \u001b[38;5;4m 3 \u001b[0m \u001b[0m\n", |
| 155 | + " \u001b[38;5;244m 0 \u001b[0m \u001b[38;5;244m 0 \u001b[0m \u001b[38;5;244m 0 \u001b[0m \u001b[38;5;244m 1 \u001b[0m \u001b[0m\n", |
| 156 | + "\n", |
| 157 | + "The original SE(2) object was \n", |
| 158 | + " \u001b[38;5;1m 0 \u001b[0m \u001b[38;5;1m-1 \u001b[0m \u001b[38;5;1m 0 \u001b[0m \u001b[38;5;4m 1 \u001b[0m \u001b[0m\n", |
| 159 | + " \u001b[38;5;1m 1 \u001b[0m \u001b[38;5;1m 0 \u001b[0m \u001b[38;5;1m 0 \u001b[0m \u001b[38;5;4m 2 \u001b[0m \u001b[0m\n", |
| 160 | + " \u001b[38;5;1m 0 \u001b[0m \u001b[38;5;1m 0 \u001b[0m \u001b[38;5;1m 1 \u001b[0m \u001b[38;5;4m 3 \u001b[0m \u001b[0m\n", |
| 161 | + " \u001b[38;5;244m 0 \u001b[0m \u001b[38;5;244m 0 \u001b[0m \u001b[38;5;244m 0 \u001b[0m \u001b[38;5;244m 1 \u001b[0m \u001b[0m\n", |
| 162 | + "\n", |
| 163 | + " and can be converted to: \n", |
| 164 | + "\tA rotation matrix \n", |
| 165 | + "[[ 6.123234e-17 -1.000000e+00 0.000000e+00]\n", |
| 166 | + " [ 1.000000e+00 6.123234e-17 0.000000e+00]\n", |
| 167 | + " [ 0.000000e+00 0.000000e+00 1.000000e+00]]\n", |
| 168 | + " that has size = (3, 3).\n", |
| 169 | + "\tA position vector \n", |
| 170 | + "[1. 2. 3.]\n", |
| 171 | + " that has size = (3,).\n", |
| 172 | + "\tA homogenous transformation matrix \n", |
| 173 | + "[[ 6.123234e-17 -1.000000e+00 0.000000e+00 1.000000e+00]\n", |
| 174 | + " [ 1.000000e+00 6.123234e-17 0.000000e+00 2.000000e+00]\n", |
| 175 | + " [ 0.000000e+00 0.000000e+00 1.000000e+00 3.000000e+00]\n", |
| 176 | + " [ 0.000000e+00 0.000000e+00 0.000000e+00 1.000000e+00]]\n", |
| 177 | + " that has size = (4, 4).\n" |
| 178 | + ] |
| 179 | + } |
| 180 | + ], |
97 | 181 | "source": [ |
98 | 182 | "import numpy as np\n", |
99 | 183 | "import spatialmath as sm\n", |
|
128 | 212 | }, |
129 | 213 | { |
130 | 214 | "cell_type": "code", |
131 | | - "execution_count": null, |
| 215 | + "execution_count": 17, |
132 | 216 | "metadata": {}, |
133 | | - "outputs": [], |
| 217 | + "outputs": [ |
| 218 | + { |
| 219 | + "name": "stdout", |
| 220 | + "output_type": "stream", |
| 221 | + "text": [ |
| 222 | + "True\n" |
| 223 | + ] |
| 224 | + } |
| 225 | + ], |
134 | 226 | "source": [ |
135 | 227 | "import numpy as np\n", |
136 | 228 | "import spatialmath as sm\n", |
|
149 | 241 | "# Compare HC.A and HC_np\n", |
150 | 242 | "print(np.allclose(HC.A, HC_np))" |
151 | 243 | ] |
| 244 | + }, |
| 245 | + { |
| 246 | + "cell_type": "markdown", |
| 247 | + "metadata": {}, |
| 248 | + "source": [ |
| 249 | + "If you're having problems comparing matrices with \"similar\" dimesions, try to use `numpy.squeeze` when applicable. \n", |
| 250 | + "\n", |
| 251 | + "To understand the problem, see $\\myvec{v}_1$ and $\\myvec{v}_2$ below" |
| 252 | + ] |
| 253 | + }, |
| 254 | + { |
| 255 | + "cell_type": "code", |
| 256 | + "execution_count": 18, |
| 257 | + "metadata": {}, |
| 258 | + "outputs": [ |
| 259 | + { |
| 260 | + "name": "stdout", |
| 261 | + "output_type": "stream", |
| 262 | + "text": [ |
| 263 | + "Shapes are not equal, notice that in v1 we have [] and in v2 we have [[]].\n", |
| 264 | + "So, v1.shape=(2,) and v2.shape=(1, 2).\n", |
| 265 | + "True\n" |
| 266 | + ] |
| 267 | + } |
| 268 | + ], |
| 269 | + "source": [ |
| 270 | + "import numpy as np\n", |
| 271 | + "from math import pi, sin, cos\n", |
| 272 | + "\n", |
| 273 | + "v1 = np.array([sin(pi/2), cos(pi/2)])\n", |
| 274 | + "v2 = np.array([[sin(pi/2), cos(pi/2)]])\n", |
| 275 | + "\n", |
| 276 | + "print(f\"Shapes are not equal, notice that in v1 we have [] and in v2 we have [[]].\")\n", |
| 277 | + "print(f\"So, v1.shape={v1.shape} and v2.shape={v2.shape}.\")\n", |
| 278 | + "\n", |
| 279 | + "print(np.allclose(v1, v2))" |
| 280 | + ] |
| 281 | + }, |
| 282 | + { |
| 283 | + "cell_type": "markdown", |
| 284 | + "metadata": {}, |
| 285 | + "source": [ |
| 286 | + "To compare, we do" |
| 287 | + ] |
| 288 | + }, |
| 289 | + { |
| 290 | + "cell_type": "code", |
| 291 | + "execution_count": 19, |
| 292 | + "metadata": {}, |
| 293 | + "outputs": [ |
| 294 | + { |
| 295 | + "name": "stdout", |
| 296 | + "output_type": "stream", |
| 297 | + "text": [ |
| 298 | + "True\n" |
| 299 | + ] |
| 300 | + } |
| 301 | + ], |
| 302 | + "source": [ |
| 303 | + "# Compare v1 and v2\n", |
| 304 | + "print(np.allclose(np.squeeze(v1), np.squeeze(v2)))" |
| 305 | + ] |
152 | 306 | } |
153 | 307 | ], |
154 | 308 | "metadata": { |
155 | 309 | "kernelspec": { |
156 | | - "display_name": "Python 3", |
| 310 | + "display_name": ".venv", |
157 | 311 | "language": "python", |
158 | 312 | "name": "python3" |
159 | 313 | }, |
|
0 commit comments