-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_playground.qmd
More file actions
81 lines (62 loc) · 1.37 KB
/
python_playground.qmd
File metadata and controls
81 lines (62 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
79
80
81
---
format:
html:
code-fold: true
jupyter: python3
---
# Python Playground
```{python}
#| label: fig-polar
#| fig-cap: "A line plot on a polar axis"
import numpy as np
import matplotlib.pyplot as plt
r = np.arange(0, 2, 0.01)
theta = 2 * np.pi * r
fig, ax = plt.subplots(
subplot_kw = {'projection': 'polar'}
)
ax.plot(theta, r)
ax.set_rticks([0.5, 1, 1.5, 2])
ax.grid(True)
plt.show()
```
## MeshCat
```{python}
#| output: false
#| echo: false
import meshcat
from meshcat.geometry import Box
from meshcat.animation import Animation
import meshcat.transformations as tf
vis = meshcat.Visualizer()
```
```{python}
vis["box1"].set_object(Box([0.1, 0.2, 0.3]))
anim = Animation()
with anim.at_frame(vis, 0) as frame:
frame["box1"].set_transform(tf.translation_matrix([0, 0, 0]))
with anim.at_frame(vis, 30) as frame:
frame["box1"].set_transform(tf.translation_matrix([0, 1, 0]))
vis.set_animation(anim)
vis.render_static()
```
```{python}
#| echo: false
#| output: asis
import sympy as sp
import numpy as np
# load our custom module
import sys
from pathlib import Path
module_path = str(Path.cwd() / "code")
if module_path not in sys.path:
sys.path.append(module_path)
from sympy_helper import *
t = sp.Symbol("t")
printer = MyLatexPrinter(t)
x = sp.Function("x")(t)
printer.show(x)
printer.show(x**2)
printer.show(sp.diff(x,t,1))
printer.show(sp.diff(x,t,2))
```