Closed darkeclipz closed 5 years ago
Imports:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import proj3d, Axes3D
from sympy import symbols, Matrix
import math
from sympy.parsing.sympy_parser import parse_expr
Plot for two variables:
t = symbols('t')
u = parse_expr('Matrix([t*cos(3*t), t*sin(2*t)])')
a = 16
lim = [0, a]
ts = np.linspace(lim[0], lim[1], a**2)
Y = np.array([u.subs('t', t).evalf() for t in ts]).astype('float')
xs = [x[0] for x in Y]
ys = [x[1] for x in Y]
plot(xs, ys)
Plot for three variables:
t = symbols('t')
u = parse_expr('Matrix([t*cos(3*t), t*sin(2*t), t])')
a = 16
lim = [0, a]
ts = np.linspace(lim[0], lim[1], a**2)
Y = np.array([u.subs('t', t).evalf() for t in ts]).astype('float')
xs = [x[0] for x in Y]
ys = [x[1] for x in Y]
zs = [x[2] for x in Y]
fig = plt.figure(figsize=(10,10))
ax = fig.add_subplot(111, projection='3d')
plot(xs, ys, zs, c="purple")
plt.show()
A 3x1 or 2x1 matrix can be detected in the following way:
def is_matrix_3x1(u): return 'Matrix' in str(type(u)) and u.shape == (3, 1)
def is_matrix_2x1(u): return 'Matrix' in str(type(u)) and u.shape == (2, 1)
Support for two and three dimensional parametric curves.
A paramatric curve can be recognized if the expression is a 2x1 or 3x1 matrix with a single variable.