Lay out a curve in 3D with Sympy

How to build the next three-dimensional curve (as an example) using Sympy? I know that I simply create an array for t and do it in Matplotlib, but I really do not want to draw this curve, but to learn how to draw and draw curves symbolically.

alpha (t) = (cos (t), sin (t), t)

from sympy import *

t = symbols('t')
alpha = [cos(t), sin(t), t]

# now what?

I tried to use the plot method in various ways, but this only led to three separate 1D curves or errors.

+4
source share
2 answers

You must use methods from sympy.plotting, in your case your need plot3d_parametric_line:

from sympy import *
from sympy.plotting import plot3d_parametric_line

t = symbols('t')
alpha = [cos(t), sin(t), t]
plot3d_parametric_line(*alpha)

or plot3d_parametric_line(cos(t), sin(t), t, (t, 0, 2*pi)), if you want to set t limits.

enter image description here 3d sympy: https://github.com/sympy/sympy/blob/master/examples/beginner/plot_examples.py

+6

sympy

, matplotlib

lambdify() -

from sympy import *
from sympy.utilities.lambdify import lambdify
import math

t = symbols('t')
alpha = [cos(t), sin(t), t]

f = lambdify(t, alpha)

T = [2*math.pi/100*n for n in range(100)]
F = [f(x) for x in T]

import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d.axes3d as axes3d

fig1, ax1 = plt.subplots(subplot_kw=dict(projection='3d'))
ax1.plot(*zip(*F))
ax1.set_aspect('equal')
plt.show()

enter image description here

+2

Source: https://habr.com/ru/post/1683494/


All Articles