addsub1234
addsub1234

Reputation: 53

Length of a parametric curve (integral of differential of the curve)

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.

enter image description here

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()

Upvotes: 0

Views: 718

Answers (1)

smichr
smichr

Reputation: 19057

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

SymPy does not yet allow 3-D curves but you can do this in general by defining the point parametrically, then integrating over the range of interest.

from sympy import Tuple
from sympy.abc import t
x=Tuple(cos(t),sin(t),3*t)
ss = sum([i.diff(t)**2 for i in x])
>>> integrate(sqrt(ss), (t,0,2))
2*sqrt(10)*pi

Upvotes: 3

Related Questions