I am trying to learn differential geometry and sympy for the first time. Using sympy , I am able to define expressions for parametric curve and find velocities. I am trying to compute the length of the curve as per the below definition, but unable to figure out, how to do this with sympy. Can someone please provide pointers on how to compute the curve length.
Below is the current code I have (using sympy & matplotlib).
# Expression of Parametric Curve
t = sympy.symbols('t')
x_expr = sympy.cos(t)
y_expr = sympy.sin(t)
f_x = sympy.lambdify(t, x_expr, 'numpy')
f_y = sympy.lambdify(t, y_expr, 'numpy')
# Differential of Parametric Curve
diff_x = sympy.lambdify(t, sympy.diff(x_expr, t), 'numpy')
diff_y = sympy.lambdify(t, sympy.diff(y_expr, t), 'numpy')
t_values = np.linspace(0, 2 * np.pi, 80, endpoint=True)
X = f_x(t_values)
Y = f_y(t_values)
# Plot the curve
clear_figure()
ax = create_subplot()
ax.set_xlim(-1.5, 1.5)
ax.set_ylim(-1.5, 1.5)
ax.scatter(X, Y, s=4)
plt_canvas.draw()
# Plot the velocities
t1_values = np.linspace(0, 2 * np.pi, 9, endpoint=True)
for t1 in t1_values:
ax.arrow(f_x(t1), f_y(t1), diff_x(t1), diff_y(t1), head_width=0.02, head_length=0.02, ec='red', linewidth=0.1)
plt_canvas.draw()
From geometry
you can define a parametric curve and it can tell you the length of the same. Is this what you were expecting:
>>> Curve((cos(t), sin(t)), (t, 0, 2*pi)).length
2*pi
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.