In [1]:
from xv.util import listAttr
import numpy as np
In [2]:
from sympy import Matrix
# from sympy.abc import a, b, x, y
from sympy.vector import CoordSys3D, matrix_to_vector
In [3]:
a, b = 1, 4
x, y = -2, 5
In [4]:
v1 = Matrix([a, b, 0])
v2 = Matrix([x, y, 0])
In [5]:
C = CoordSys3D('')
In [6]:
v3 = matrix_to_vector(v1, C)
display(v3)
In [7]:
v4 = matrix_to_vector(v2, C)
display(v4)
In [8]:
m_v3 = v3.to_matrix(C)
m_v3
Out[8]:
In [9]:
m_v4 = v4.to_matrix(C)
m_v4
Out[9]:
In [10]:
from xv.plotter.core.plot2d import Plotter
In [11]:
plotter = Plotter3D()
In [12]:
C_origin = C.origin.position_wrt(C.origin)
m_C_origin = C_origin.to_matrix(C)
In [13]:
arr_C_origin = np.array(m_C_origin).astype(np.float64)[:-1].flatten()
arr_v3 = np.array(m_v3).astype(np.float64)[:-1].flatten()
arr_v4 = np.array(m_v4).astype(np.float64)[:-1].flatten()
In [14]:
fig, ax = plotter.plot_vector(arr_C_origin, arr_v3, color = 'red')
plotter.plot_vector(arr_C_origin, arr_v4, color = 'blue', fig = fig, ax = ax)
Out[14]:
In [15]:
theta = np.pi/6
In [16]:
D = C.orient_new_axis('D', theta, C.k)
D
Out[16]:
In [17]:
D_origin = D.origin.position_wrt(D.origin)
m_D_origin = D_origin.to_matrix(D)
In [18]:
from sympy.vector import express
In [19]:
v3_D = express(v3, D)
v4_D = express(v4, D)
# display(v3_D, v4_D)
In [20]:
m_v3_D = v3_D.to_matrix(D)
m_v4_D = v4_D.to_matrix(D)
# display(m_v3_D, m_v4_D)
In [21]:
arr_D_origin = np.array(m_D_origin).astype(np.float64)[:-1].flatten()
arr_v3_D = np.array(m_v3_D).astype(np.float64)[:-1].flatten()
arr_v4_D = np.array(m_v4_D).astype(np.float64)[:-1].flatten()
In [22]:
fig, ax = plotter.plot_vector(arr_C_origin, arr_v3, color = 'red')
plotter.plot_vector(arr_D_origin, arr_v3_D, color = 'pink', fig = fig, ax = ax)
plotter.plot_vector(arr_C_origin, arr_v4, color = 'blue', fig = fig, ax = ax)
plotter.plot_vector(arr_D_origin, arr_v4_D, color = 'skyblue', fig = fig, ax = ax)
Out[22]:
In [23]:
dx = 3
In [24]:
E = C.locate_new('E', dx * C.i)
E
Out[24]:
In [25]:
E_origin = express(E.origin.position_wrt(C.origin), E)
m_E_origin = E_origin.to_matrix(E)
In [30]:
v3_E = express(v3, E) + E_origin
v4_E = express(v4, E) + E_origin
# display(v3_E, v4_E)
In [31]:
m_v3_E = v3_E.to_matrix(E)
m_v4_E = v4_E.to_matrix(E)
# display(m_v3_E, m_v4_E)
In [28]:
arr_E_origin = np.array(m_E_origin).astype(np.float64)[:-1].flatten()
arr_v3_E = np.array(m_v3_E).astype(np.float64)[:-1].flatten()
arr_v4_E = np.array(m_v4_E).astype(np.float64)[:-1].flatten()
In [29]:
fig, ax = plotter.plot_vector(arr_C_origin, arr_v3, color = 'red')
plotter.plot_vector(arr_D_origin, arr_v3_D, color = 'pink', fig = fig, ax = ax)
plotter.plot_vector(arr_E_origin, arr_v3_E, color = 'orange', fig = fig, ax = ax)
plotter.plot_vector(arr_C_origin, arr_v4, color = 'blue', fig = fig, ax = ax)
plotter.plot_vector(arr_D_origin, arr_v4_D, color = 'skyblue', fig = fig, ax = ax)
plotter.plot_vector(arr_E_origin, arr_v4_E, color = 'm', fig = fig, ax = ax)
Out[29]:
In [ ]: