基本类#
- class sympy.physics.vector.frame.CoordinateSym(name, frame, index)[源代码]#
与参考坐标系相关联的一种坐标符号/基标量。
理想情况下,用户不应该实例化这个类。此类的实例只能通过相应的frame as'frame访问 [指数] '.
具有相同帧和索引参数的坐标符号是相等的(即使它们可以单独实例化)。
- 参数:
name :字符串
坐标符号的显示名称
框架 :参考帧
此基标量所属的参考帧
指数 :0、1或2
由该变量的坐标表示的索引
实例
>>> from sympy.physics.vector import ReferenceFrame, CoordinateSym >>> A = ReferenceFrame('A') >>> A[1] A_y >>> type(A[0]) <class 'sympy.physics.vector.frame.CoordinateSym'> >>> a_y = CoordinateSym('a_y', A, 1) >>> a_y == A[1] True
- class sympy.physics.vector.frame.ReferenceFrame(name, indices=None, latexs=None, variables=None)[源代码]#
经典力学中的参考系。
ReferenceFrame是一个在经典力学中用来表示参考框架的类。它在帧的x、y和z方向有三个单位向量的标准基。
它也可以具有相对于父帧的旋转;该旋转由将该帧的基向量与父帧的基向量相关的方向余弦矩阵定义。它也可以有一个角速度向量,在另一帧中定义。
- ang_acc_in(otherframe)[源代码]#
返回ReferenceFrame的角加速度矢量。
Effectively returns the Vector:
N_alpha_B
which represent the angular acceleration of B in N, where B is self, and N is otherframe.
- 参数:
其他帧 :参考帧
返回角加速度的参考帧。
实例
>>> from sympy.physics.vector import ReferenceFrame >>> N = ReferenceFrame('N') >>> A = ReferenceFrame('A') >>> V = 10 * N.x >>> A.set_ang_acc(N, V) >>> A.ang_acc_in(N) 10*N.x
- ang_vel_in(otherframe)[源代码]#
返回ReferenceFrame的角速度矢量。
Effectively returns the Vector:
^N omega ^B
which represent the angular velocity of B in N, where B is self, and N is otherframe.
- 参数:
其他帧 :参考帧
返回角速度的参考帧。
实例
>>> from sympy.physics.vector import ReferenceFrame >>> N = ReferenceFrame('N') >>> A = ReferenceFrame('A') >>> V = 10 * N.x >>> A.set_ang_vel(N, V) >>> A.ang_vel_in(N) 10*N.x
- dcm(otherframe)[源代码]#
Returns the direction cosine matrix of this reference frame relative to the provided reference frame.
返回的矩阵可用于表示该帧的正交单位向量,表示为
otherframe
.- 参数:
其他帧 :参考帧
该坐标系的方向余弦矩阵所对应的参考坐标系。
实例
以下示例通过简单的旋转将参考坐标系A相对于N旋转,然后计算N相对于A的方向余弦矩阵。
>>> from sympy import symbols, sin, cos >>> from sympy.physics.vector import ReferenceFrame >>> q1 = symbols('q1') >>> N = ReferenceFrame('N') >>> A = ReferenceFrame('A') >>> A.orient_axis(N, q1, N.x) >>> N.dcm(A) Matrix([ [1, 0, 0], [0, cos(q1), -sin(q1)], [0, sin(q1), cos(q1)]])
上述方向余弦矩阵的第二行表示
N.y
单位向量,单位为N,用A表示,如下所示:>>> Ny = 0*A.x + cos(q1)*A.y - sin(q1)*A.z
因此,表达
N.y
应返回相同的结果:>>> N.y.express(A) cos(q1)*A.y - sin(q1)*A.z
笔记
It is important to know what form of the direction cosine matrix is returned. If
B.dcm(A)
is called, it means the "direction cosine matrix of B rotated relative to A". This is the matrix \({}^B\mathbf{C}^A\) shown in the following relationship:\[\begin{split}\begin{bmatrix} \hat{\mathbf{b}}_1 \\ \hat{\mathbf{b}}_2 \\ \hat{\mathbf{b}}_3 \end{bmatrix} = {}^B\mathbf{C}^A \begin{bmatrix} \hat{\mathbf{a}}_1 \\ \hat{\mathbf{a}}_2 \\ \hat{\mathbf{a}}_3 \end{bmatrix}.\end{split}\]\({}^B\mathbf{C}^A\) is the matrix that expresses the B unit vectors in terms of the A unit vectors.
- orient(parent, rot_type, amounts, rot_order='')[源代码]#
设置此参考帧相对于另一个(父)参考帧的方向。
备注
It is now recommended to use the
.orient_axis, .orient_body_fixed, .orient_space_fixed, .orient_quaternion
methods for the different rotation types.- 参数:
起源 :参考帧
此参考帧将相对于其旋转的参考帧。
rot_type :结构
生成方向余弦矩阵的方法。支持的方法有:
'Axis'
:围绕单个公共轴的简单旋转'DCM'
:用于直接设置方向余弦矩阵'Body'
:围绕新的中间轴连续旋转三次,也称为“Euler和Tait-Bryan角”'Space'
:围绕父帧的单位向量连续旋转三次'Quaternion'
:由四个参数定义的旋转,从而产生无奇异方向余弦矩阵
数量:
定义旋转角度或方向余弦矩阵的表达式。这些必须与
rot_type
. 详细信息请参见下面的示例。输入类型包括:'Axis'
:2元组(expr/sym/func,Vector)'DCM'
:矩阵,形状(3,3)'Body'
:3-表达式、符号或函数的元组'Space'
:3-表达式、符号或函数的元组'Quaternion'
:4-表达式、符号或函数的元组
rot_order :str或int,可选
如果适用,依次旋转的顺序。绳子
'123'
和整数123
例如,是等价的。所需的'Body'
和'Space'
.- Warns:
UserWarning
If the orientation creates a kinematic loop.
- orient_axis(parent, axis, angle)[源代码]#
Sets the orientation of this reference frame with respect to a parent reference frame by rotating through an angle about an axis fixed in the parent reference frame.
- 参数:
起源 :参考帧
此参考帧将相对于其旋转的参考帧。
axis :矢量
Vector fixed in the parent frame about about which this frame is rotated. It need not be a unit vector and the rotation follows the right hand rule.
angle : sympifiable
Angle in radians by which it the frame is to be rotated.
- Warns:
UserWarning
If the orientation creates a kinematic loop.
实例
示例的设置变量:
>>> from sympy import symbols >>> from sympy.physics.vector import ReferenceFrame >>> q1 = symbols('q1') >>> N = ReferenceFrame('N') >>> B = ReferenceFrame('B') >>> B.orient_axis(N, N.x, q1)
The
orient_axis()
method generates a direction cosine matrix and its transpose which defines the orientation of B relative to N and vice versa. Once orient is called,dcm()
outputs the appropriate direction cosine matrix:>>> B.dcm(N) Matrix([ [1, 0, 0], [0, cos(q1), sin(q1)], [0, -sin(q1), cos(q1)]]) >>> N.dcm(B) Matrix([ [1, 0, 0], [0, cos(q1), -sin(q1)], [0, sin(q1), cos(q1)]])
The following two lines show that the sense of the rotation can be defined by negating the vector direction or the angle. Both lines produce the same result.
>>> B.orient_axis(N, -N.x, q1) >>> B.orient_axis(N, N.x, -q1)
- orient_body_fixed(parent, angles, rotation_order)[源代码]#
Rotates this reference frame relative to the parent reference frame by right hand rotating through three successive body fixed simple axis rotations. Each subsequent axis of rotation is about the "body fixed" unit vectors of a new intermediate reference frame. This type of rotation is also referred to rotating through the Euler and Tait-Bryan Angles.
The computed angular velocity in this method is by default expressed in the child's frame, so it is most preferable to use
u1 * child.x + u2 * child.y + u3 * child.z
as generalized speeds.- 参数:
起源 :参考帧
此参考帧将相对于其旋转的参考帧。
angles : 3-tuple of sympifiable
Three angles in radians used for the successive rotations.
rotation_order : 3 character string or 3 digit integer
Order of the rotations about each intermediate reference frames' unit vectors. The Euler rotation about the X, Z', X'' axes can be specified by the strings
'XZX'
,'131'
, or the integer131
. There are 12 unique valid rotation orders (6 Euler and 6 Tait-Bryan): zxz, xyx, yzy, zyz, xzx, yxy, xyz, yzx, zxy, xzy, zyx, and yxz.- Warns:
UserWarning
If the orientation creates a kinematic loop.
实例
示例的设置变量:
>>> from sympy import symbols >>> from sympy.physics.vector import ReferenceFrame >>> q1, q2, q3 = symbols('q1, q2, q3') >>> N = ReferenceFrame('N') >>> B = ReferenceFrame('B') >>> B1 = ReferenceFrame('B1') >>> B2 = ReferenceFrame('B2') >>> B3 = ReferenceFrame('B3')
For example, a classic Euler Angle rotation can be done by:
>>> B.orient_body_fixed(N, (q1, q2, q3), 'XYX') >>> B.dcm(N) Matrix([ [ cos(q2), sin(q1)*sin(q2), -sin(q2)*cos(q1)], [sin(q2)*sin(q3), -sin(q1)*sin(q3)*cos(q2) + cos(q1)*cos(q3), sin(q1)*cos(q3) + sin(q3)*cos(q1)*cos(q2)], [sin(q2)*cos(q3), -sin(q1)*cos(q2)*cos(q3) - sin(q3)*cos(q1), -sin(q1)*sin(q3) + cos(q1)*cos(q2)*cos(q3)]])
This rotates reference frame B relative to reference frame N through
q1
aboutN.x
, then rotates B again throughq2
aboutB.y
, and finally throughq3
aboutB.x
. It is equivalent to three successiveorient_axis()
calls:>>> B1.orient_axis(N, N.x, q1) >>> B2.orient_axis(B1, B1.y, q2) >>> B3.orient_axis(B2, B2.x, q3) >>> B3.dcm(N) Matrix([ [ cos(q2), sin(q1)*sin(q2), -sin(q2)*cos(q1)], [sin(q2)*sin(q3), -sin(q1)*sin(q3)*cos(q2) + cos(q1)*cos(q3), sin(q1)*cos(q3) + sin(q3)*cos(q1)*cos(q2)], [sin(q2)*cos(q3), -sin(q1)*cos(q2)*cos(q3) - sin(q3)*cos(q1), -sin(q1)*sin(q3) + cos(q1)*cos(q2)*cos(q3)]])
可接受的旋转顺序长度为3,用字符串表示
'XYZ'
或'123'
或整数123
. 禁止连续两次绕轴旋转。>>> B.orient_body_fixed(N, (q1, q2, 0), 'ZXZ') >>> B.orient_body_fixed(N, (q1, q2, 0), '121') >>> B.orient_body_fixed(N, (q1, q2, q3), 123)
- orient_dcm(parent, dcm)[源代码]#
Sets the orientation of this reference frame relative to another (parent) reference frame using a direction cosine matrix that describes the rotation from the child to the parent.
- 参数:
起源 :参考帧
此参考帧将相对于其旋转的参考帧。
dcm : Matrix, shape(3, 3)
Direction cosine matrix that specifies the relative rotation between the two reference frames.
- Warns:
UserWarning
If the orientation creates a kinematic loop.
实例
示例的设置变量:
>>> from sympy import symbols, Matrix, sin, cos >>> from sympy.physics.vector import ReferenceFrame >>> q1 = symbols('q1') >>> A = ReferenceFrame('A') >>> B = ReferenceFrame('B') >>> N = ReferenceFrame('N')
A simple rotation of
A
relative toN
aboutN.x
is defined by the following direction cosine matrix:>>> dcm = Matrix([[1, 0, 0], ... [0, cos(q1), sin(q1)], ... [0, -sin(q1), cos(q1)]]) >>> A.orient_dcm(N, dcm) >>> A.dcm(N) Matrix([ [1, 0, 0], [0, cos(q1), sin(q1)], [0, -sin(q1), cos(q1)]])
This is equivalent to using
orient_axis()
:>>> B.orient_axis(N, N.x, q1) >>> B.dcm(N) Matrix([ [1, 0, 0], [0, cos(q1), sin(q1)], [0, -sin(q1), cos(q1)]])
- orient_quaternion(parent, numbers)[源代码]#
Sets the orientation of this reference frame relative to a parent reference frame via an orientation quaternion. An orientation quaternion is defined as a finite rotation a unit vector,
(lambda_x, lambda_y, lambda_z)
, by an angletheta
. The orientation quaternion is described by four parameters:q0 = cos(theta/2)
q1 = lambda_x*sin(theta/2)
q2 = lambda_y*sin(theta/2)
q3 = lambda_z*sin(theta/2)
See Quaternions and Spatial Rotation on Wikipedia for more information.
- 参数:
起源 :参考帧
此参考帧将相对于其旋转的参考帧。
numbers : 4-tuple of sympifiable
The four quaternion scalar numbers as defined above:
q0
,q1
,q2
,q3
.- Warns:
UserWarning
If the orientation creates a kinematic loop.
实例
示例的设置变量:
>>> from sympy import symbols >>> from sympy.physics.vector import ReferenceFrame >>> q0, q1, q2, q3 = symbols('q0 q1 q2 q3') >>> N = ReferenceFrame('N') >>> B = ReferenceFrame('B')
Set the orientation:
>>> B.orient_quaternion(N, (q0, q1, q2, q3)) >>> B.dcm(N) Matrix([ [q0**2 + q1**2 - q2**2 - q3**2, 2*q0*q3 + 2*q1*q2, -2*q0*q2 + 2*q1*q3], [ -2*q0*q3 + 2*q1*q2, q0**2 - q1**2 + q2**2 - q3**2, 2*q0*q1 + 2*q2*q3], [ 2*q0*q2 + 2*q1*q3, -2*q0*q1 + 2*q2*q3, q0**2 - q1**2 - q2**2 + q3**2]])
- orient_space_fixed(parent, angles, rotation_order)[源代码]#
Rotates this reference frame relative to the parent reference frame by right hand rotating through three successive space fixed simple axis rotations. Each subsequent axis of rotation is about the "space fixed" unit vectors of the parent reference frame.
The computed angular velocity in this method is by default expressed in the child's frame, so it is most preferable to use
u1 * child.x + u2 * child.y + u3 * child.z
as generalized speeds.- 参数:
起源 :参考帧
此参考帧将相对于其旋转的参考帧。
angles : 3-tuple of sympifiable
Three angles in radians used for the successive rotations.
rotation_order : 3 character string or 3 digit integer
Order of the rotations about the parent reference frame's unit vectors. The order can be specified by the strings
'XZX'
,'131'
, or the integer131
. There are 12 unique valid rotation orders.- Warns:
UserWarning
If the orientation creates a kinematic loop.
实例
示例的设置变量:
>>> from sympy import symbols >>> from sympy.physics.vector import ReferenceFrame >>> q1, q2, q3 = symbols('q1, q2, q3') >>> N = ReferenceFrame('N') >>> B = ReferenceFrame('B') >>> B1 = ReferenceFrame('B1') >>> B2 = ReferenceFrame('B2') >>> B3 = ReferenceFrame('B3')
>>> B.orient_space_fixed(N, (q1, q2, q3), '312') >>> B.dcm(N) Matrix([ [ sin(q1)*sin(q2)*sin(q3) + cos(q1)*cos(q3), sin(q1)*cos(q2), sin(q1)*sin(q2)*cos(q3) - sin(q3)*cos(q1)], [-sin(q1)*cos(q3) + sin(q2)*sin(q3)*cos(q1), cos(q1)*cos(q2), sin(q1)*sin(q3) + sin(q2)*cos(q1)*cos(q3)], [ sin(q3)*cos(q2), -sin(q2), cos(q2)*cos(q3)]])
相当于:
>>> B1.orient_axis(N, N.z, q1) >>> B2.orient_axis(B1, N.x, q2) >>> B3.orient_axis(B2, N.y, q3) >>> B3.dcm(N).simplify() Matrix([ [ sin(q1)*sin(q2)*sin(q3) + cos(q1)*cos(q3), sin(q1)*cos(q2), sin(q1)*sin(q2)*cos(q3) - sin(q3)*cos(q1)], [-sin(q1)*cos(q3) + sin(q2)*sin(q3)*cos(q1), cos(q1)*cos(q2), sin(q1)*sin(q3) + sin(q2)*cos(q1)*cos(q3)], [ sin(q3)*cos(q2), -sin(q2), cos(q2)*cos(q3)]])
值得注意的是,空间固定和物体固定的旋转是由旋转的顺序联系在一起的,也就是说,物体固定的相反顺序将产生空间固定,反之亦然。
>>> B.orient_space_fixed(N, (q1, q2, q3), '231') >>> B.dcm(N) Matrix([ [cos(q1)*cos(q2), sin(q1)*sin(q3) + sin(q2)*cos(q1)*cos(q3), -sin(q1)*cos(q3) + sin(q2)*sin(q3)*cos(q1)], [ -sin(q2), cos(q2)*cos(q3), sin(q3)*cos(q2)], [sin(q1)*cos(q2), sin(q1)*sin(q2)*cos(q3) - sin(q3)*cos(q1), sin(q1)*sin(q2)*sin(q3) + cos(q1)*cos(q3)]])
>>> B.orient_body_fixed(N, (q3, q2, q1), '132') >>> B.dcm(N) Matrix([ [cos(q1)*cos(q2), sin(q1)*sin(q3) + sin(q2)*cos(q1)*cos(q3), -sin(q1)*cos(q3) + sin(q2)*sin(q3)*cos(q1)], [ -sin(q2), cos(q2)*cos(q3), sin(q3)*cos(q2)], [sin(q1)*cos(q2), sin(q1)*sin(q2)*cos(q3) - sin(q3)*cos(q1), sin(q1)*sin(q2)*sin(q3) + cos(q1)*cos(q3)]])
- orientnew(newname, rot_type, amounts, rot_order='', variables=None, indices=None, latexs=None)[源代码]#
返回相对于此参考帧定向的新参考帧。
见
ReferenceFrame.orient()
参考框架的详细定位示例。- 参数:
纽名 :结构
新参照系的名称。
rot_type :结构
生成方向余弦矩阵的方法。支持的方法有:
'Axis'
:围绕单个公共轴的简单旋转'DCM'
:用于直接设置方向余弦矩阵'Body'
:围绕新的中间轴连续旋转三次,也称为“Euler和Tait-Bryan角”'Space'
:围绕父帧的单位向量连续旋转三次'Quaternion'
:由四个参数定义的旋转,从而产生无奇异方向余弦矩阵
数量:
定义旋转角度或方向余弦矩阵的表达式。这些必须与
rot_type
. 详细信息请参见下面的示例。输入类型包括:'Axis'
:2元组(expr/sym/func,Vector)'DCM'
:矩阵,形状(3,3)'Body'
:3-表达式、符号或函数的元组'Space'
:3-表达式、符号或函数的元组'Quaternion'
:4-表达式、符号或函数的元组
rot_order :str或int,可选
如果适用,依次旋转的顺序。绳子
'123'
和整数123
例如,是等价的。所需的'Body'
和'Space'
.指数 :str的元组
使用提供的三个指示符字符串,允许Python的方括号索引符号访问参考帧的基本单位向量,并更改单位向量的打印以反映此选择。
迟到的 :str的元组
将参考框架的基本单位向量的 Latex 打印更改为提供的三个有效 Latex 字符串。
实例
>>> from sympy import symbols >>> from sympy.physics.vector import ReferenceFrame, vlatex >>> q0, q1, q2, q3 = symbols('q0 q1 q2 q3') >>> N = ReferenceFrame('N')
创建一个新的参考坐标系a通过简单的旋转相对于N旋转。
>>> A = N.orientnew('A', 'Axis', (q0, N.x))
创建一个新的参考系B,通过主体固定旋转相对于N旋转。
>>> B = N.orientnew('B', 'Body', (q1, q2, q3), '123')
创建一个新的参照系C,通过一个简单的旋转和独特的索引和 Latex 打印相对于N旋转。
>>> C = N.orientnew('C', 'Axis', (q0, N.x), indices=('1', '2', '3'), ... latexs=(r'\hat{\mathbf{c}}_1',r'\hat{\mathbf{c}}_2', ... r'\hat{\mathbf{c}}_3')) >>> C['1'] C['1'] >>> print(vlatex(C['1'])) \hat{\mathbf{c}}_1
- partial_velocity(frame, *gen_speeds)[源代码]#
返回给定帧中此帧相对于一个或多个提供的广义速度的部分角速度。
- 参数:
框架 :参考帧
在中定义角速度的帧。
gen_speeds :时间函数
广义速度。
- 返回:
partial_velocities :向量元组
与所提供的广义速度相对应的偏角速度矢量。
实例
>>> from sympy.physics.vector import ReferenceFrame, dynamicsymbols >>> N = ReferenceFrame('N') >>> A = ReferenceFrame('A') >>> u1, u2 = dynamicsymbols('u1, u2') >>> A.set_ang_vel(N, u1 * A.x + u2 * N.y) >>> A.partial_velocity(N, u1) A.x >>> A.partial_velocity(N, u1, u2) (A.x, N.y)
- set_ang_acc(otherframe, value)[源代码]#
定义参考帧中的角加速度矢量。
定义此参考帧的角加速度。角加速度可以根据多个不同的参考框架来定义。必须注意不要创建不一致的循环。
- 参数:
其他帧 :参考帧
定义角加速度的参考框架
价值 :矢量
代表角加速度的向量
实例
>>> from sympy.physics.vector import ReferenceFrame >>> N = ReferenceFrame('N') >>> A = ReferenceFrame('A') >>> V = 10 * N.x >>> A.set_ang_acc(N, V) >>> A.ang_acc_in(N) 10*N.x
- set_ang_vel(otherframe, value)[源代码]#
定义参考帧中的角速度矢量。
定义此参考帧的角速度。角速度可以根据多个不同的参考帧来定义。必须注意不要创建不一致的循环。
- 参数:
其他帧 :参考帧
定义角速度的参考框架
价值 :矢量
表示角速度的向量
实例
>>> from sympy.physics.vector import ReferenceFrame >>> N = ReferenceFrame('N') >>> A = ReferenceFrame('A') >>> V = 10 * N.x >>> A.set_ang_vel(N, V) >>> A.ang_vel_in(N) 10*N.x
- property u#
Unit dyadic for the ReferenceFrame.
- variable_map(otherframe)[源代码]#
返回一个字典,该字典用otherframe的变量表示此帧的坐标变量。
如果向量.simp为True,则返回映射值的简化版本。否则,返回它们而不进行简化。
简化表达式可能需要时间。
- 参数:
其他帧 :参考帧
将变量映射到的另一个框架
实例
>>> from sympy.physics.vector import ReferenceFrame, dynamicsymbols >>> A = ReferenceFrame('A') >>> q = dynamicsymbols('q') >>> B = A.orientnew('B', 'Axis', [q, A.z]) >>> A.variable_map(B) {A_x: B_x*cos(q(t)) - B_y*sin(q(t)), A_y: B_x*sin(q(t)) + B_y*cos(q(t)), A_z: B_z}
- property x#
参考帧的基向量,在x方向。
- property xx#
Unit dyad of basis Vectors x and x for the ReferenceFrame.
- property xy#
Unit dyad of basis Vectors x and y for the ReferenceFrame.
- property xz#
Unit dyad of basis Vectors x and z for the ReferenceFrame.
- property y#
参考帧的基向量,在y方向。
- property yx#
Unit dyad of basis Vectors y and x for the ReferenceFrame.
- property yy#
Unit dyad of basis Vectors y and y for the ReferenceFrame.
- property yz#
Unit dyad of basis Vectors y and z for the ReferenceFrame.
- property z#
参考帧的基向量,在z方向。
- property zx#
Unit dyad of basis Vectors z and x for the ReferenceFrame.
- property zy#
Unit dyad of basis Vectors z and y for the ReferenceFrame.
- property zz#
Unit dyad of basis Vectors z and z for the ReferenceFrame.
- class sympy.physics.vector.vector.Vector(inlist)[源代码]#
用于定义向量的类。
它和ReferenceFrame一起是在PyDy和sympy.物理.矢量.
属性
辛普
(Boolean)让某些方法在其输出上使用trigsimp
- angle_between(vec)[源代码]#
Returns the smallest angle between Vector 'vec' and self.
警告
Python ignores the leading negative sign so that might give wrong results.
-A.x.angle_between()
would be treated as-(A.x.angle_between())
, instead of(-A.x).angle_between()
.参数
- vec矢量
The Vector between which angle is needed.
实例
>>> from sympy.physics.vector import ReferenceFrame >>> A = ReferenceFrame("A") >>> v1 = A.x >>> v2 = A.y >>> v1.angle_between(v2) pi/2
>>> v3 = A.x + A.y + A.z >>> v1.angle_between(v3) acos(sqrt(3)/3)
- cross(other)[源代码]#
两个向量的叉积算子。
返回一个向量,表示为与self相同的引用参数。
- 参数:
其他 :矢量
我们要穿越的向量
实例
>>> from sympy import symbols >>> from sympy.physics.vector import ReferenceFrame, cross >>> q1 = symbols('q1') >>> N = ReferenceFrame('N') >>> cross(N.x, N.y) N.z >>> A = ReferenceFrame('A') >>> A.orient_axis(N, q1, N.x) >>> cross(A.x, N.y) N.z >>> cross(N.y, A.x) - sin(q1)*A.y - cos(q1)*A.z
- diff(var, frame, var_in_dcm=True)[源代码]#
返回矢量相对于所提供参考帧中变量的偏导数。
- 参数:
var :符号
偏导数是关于什么的。
框架 :参考帧
采用偏导数的参考系。
var_in_dcm :布尔值
如果为真,则微分算法假设变量可能存在于任何方向余弦矩阵中,该矩阵将帧与向量的任何分量的帧相关联。如果在全余弦坐标系中不存在的话,在全余弦坐标系中不存在。
实例
>>> from sympy import Symbol >>> from sympy.physics.vector import dynamicsymbols, ReferenceFrame >>> from sympy.physics.vector import init_vprinting >>> init_vprinting(pretty_print=False) >>> t = Symbol('t') >>> q1 = dynamicsymbols('q1') >>> N = ReferenceFrame('N') >>> A = N.orientnew('A', 'Axis', [q1, N.y]) >>> A.x.diff(t, N) - sin(q1)*q1'*N.x - cos(q1)*q1'*N.z >>> A.x.diff(t, N).express(A).simplify() - q1'*A.z >>> B = ReferenceFrame('B') >>> u1, u2 = dynamicsymbols('u1, u2') >>> v = u1 * A.x + u2 * B.y >>> v.diff(u2, N, var_in_dcm=False) B.y
- dot(other)[源代码]#
两个向量的点积。
返回一个标量,即两个向量的点积
- 参数:
其他 :矢量
我们用的矢量
实例
>>> from sympy.physics.vector import ReferenceFrame, dot >>> from sympy import symbols >>> q1 = symbols('q1') >>> N = ReferenceFrame('N') >>> dot(N.x, N.x) 1 >>> dot(N.x, N.y) 0 >>> A = N.orientnew('A', 'Axis', [q1, N.x]) >>> dot(N.y, A.y) cos(q1)
- express(otherframe, variables=False)[源代码]#
返回一个与此向量等价的向量,用otherframe表示。使用全局表达式方法。
- 参数:
其他帧 :参考帧
用于描述此向量的帧
变量 :布尔值
如果为真,则此矢量中的坐标符号(如果存在)将用otherframe重新表示
实例
>>> from sympy.physics.vector import ReferenceFrame, dynamicsymbols >>> from sympy.physics.vector import init_vprinting >>> init_vprinting(pretty_print=False) >>> q1 = dynamicsymbols('q1') >>> N = ReferenceFrame('N') >>> A = N.orientnew('A', 'Axis', [q1, N.y]) >>> A.x.express(N) cos(q1)*N.x - sin(q1)*N.z
- free_dynamicsymbols(reference_frame)[源代码]#
Returns the free dynamic symbols (functions of time
t
) in the measure numbers of the vector expressed in the given reference frame.- 参数:
reference_frame :参考帧
The frame with respect to which the free dynamic symbols of the given vector is to be determined.
- 返回:
set
Set of functions of time
t
, e.g.Function('f')(me.dynamicsymbols._t)
.
- free_symbols(reference_frame)[源代码]#
返回给定参考坐标系中表示的矢量的度量值中的自由符号。
- 参数:
reference_frame :参考帧
确定给定向量的自由符号的帧。
- 返回:
set of Symbol
set of symbols present in the measure numbers of
reference_frame
.
- property func#
Returns the class Vector.
- magnitude()[源代码]#
返回self的大小(欧几里德范数)。
警告
Python ignores the leading negative sign so that might give wrong results.
-A.x.magnitude()
would be treated as-(A.x.magnitude())
, instead of(-A.x).magnitude()
.
- outer(other)[源代码]#
两个向量之间的外积。
一种秩递增运算,从两个向量返回并矢
- 参数:
其他 :矢量
取外积的向量
实例
>>> from sympy.physics.vector import ReferenceFrame, outer >>> N = ReferenceFrame('N') >>> outer(N.x, N.x) (N.x|N.x)
- separate()[源代码]#
根据其定义,在不同参考系中该向量的组成部分。
返回将每个ReferenceFrame映射到相应的组成向量的dict。
实例
>>> from sympy.physics.vector import ReferenceFrame >>> R1 = ReferenceFrame('R1') >>> R2 = ReferenceFrame('R2') >>> v = R1.x + R2.x >>> v.separate() == {R1: R1.x, R2: R2.x} True
- subs(*args, **kwargs)[源代码]#
向量上的替换。
实例
>>> from sympy.physics.vector import ReferenceFrame >>> from sympy import Symbol >>> N = ReferenceFrame('N') >>> s = Symbol('s') >>> a = N.x * s >>> a.subs({s: 2}) 2*N.x
- to_matrix(reference_frame)[源代码]#
返回向量相对于给定帧的矩阵形式。
- 参数:
reference_frame :参考帧
矩阵行对应的参考坐标系。
- 返回:
矩阵 :不可变矩阵,形状(3,1)
给出一维向量的矩阵。
实例
>>> from sympy import symbols >>> from sympy.physics.vector import ReferenceFrame >>> a, b, c = symbols('a, b, c') >>> N = ReferenceFrame('N') >>> vector = a * N.x + b * N.y + c * N.z >>> vector.to_matrix(N) Matrix([ [a], [b], [c]]) >>> beta = symbols('beta') >>> A = N.orientnew('A', 'Axis', (beta, N.x)) >>> vector.to_matrix(A) Matrix([ [ a], [ b*cos(beta) + c*sin(beta)], [-b*sin(beta) + c*cos(beta)]])
- xreplace(rule)[源代码]#
Replace occurrences of objects within the measure numbers of the vector.
- 参数:
rule :dict样
Expresses a replacement rule.
- 返回:
矢量
Result of the replacement.
实例
>>> from sympy import symbols, pi >>> from sympy.physics.vector import ReferenceFrame >>> A = ReferenceFrame('A') >>> x, y, z = symbols('x y z') >>> ((1 + x*y) * A.x).xreplace({x: pi}) (pi*y + 1)*A.x >>> ((1 + x*y) * A.x).xreplace({x: pi, y: 2}) (1 + 2*pi)*A.x
仅当表达式树中的整个节点匹配时才会进行替换:
>>> ((x*y + z) * A.x).xreplace({x*y: pi}) (z + pi)*A.x >>> ((x*y*z) * A.x).xreplace({x*y: pi}) x*y*z*A.x
- class sympy.physics.vector.dyadic.Dyadic(inlist)[源代码]#
并矢物体。
参见:https://en.wikipedia.org/wiki/Dyadic_tensorKane,T.,Levinson,D.动力学理论与应用。1985年麦格劳希尔
表示刚体惯性的更有力的方法。当它比较复杂时,通过选择并矢分量为体内固定基向量,得到的矩阵等价于惯性张量。
- cross(other)[源代码]#
Returns the dyadic resulting from the dyadic vector cross product: Dyadic x Vector.
- 参数:
其他 :矢量
Vector to cross with.
实例
>>> from sympy.physics.vector import ReferenceFrame, outer, cross >>> N = ReferenceFrame('N') >>> d = outer(N.x, N.x) >>> cross(d, N.y) (N.x|N.z)
- dot(other)[源代码]#
并矢与并矢或向量的内积算子。
- 参数:
其他 :二进或向量
取内积的另一个并矢或向量
实例
>>> from sympy.physics.vector import ReferenceFrame, outer >>> N = ReferenceFrame('N') >>> D1 = outer(N.x, N.y) >>> D2 = outer(N.y, N.y) >>> D1.dot(D2) (N.x|N.y) >>> D1.dot(N.y) N.x
- dt(frame)[源代码]#
在一个帧中取这个并矢的时间导数。
此函数调用全局时间导数方法
- 参数:
框架 :参考帧
获取时间导数的框架
实例
>>> from sympy.physics.vector import ReferenceFrame, outer, dynamicsymbols >>> from sympy.physics.vector import init_vprinting >>> init_vprinting(pretty_print=False) >>> N = ReferenceFrame('N') >>> q = dynamicsymbols('q') >>> B = N.orientnew('B', 'Axis', [q, N.z]) >>> d = outer(N.x, N.x) >>> d.dt(B) - q'*(N.y|N.x) - q'*(N.x|N.y)
- express(frame1, frame2=None)[源代码]#
在交替帧中表示此并元
第一帧是列表端表达式,第二帧是右侧;如果并矢是A.x | B.y格式,则可以用两个不同的帧来表示它。如果没有给出第二帧,则并矢只在一个帧中表示。
调用global express函数
- 参数:
框架1 :参考帧
在中表示并矢的左侧的框架
框架2 :参考帧
如果提供的话,表示二元体右边的框
实例
>>> from sympy.physics.vector import ReferenceFrame, outer, dynamicsymbols >>> from sympy.physics.vector import init_vprinting >>> init_vprinting(pretty_print=False) >>> N = ReferenceFrame('N') >>> q = dynamicsymbols('q') >>> B = N.orientnew('B', 'Axis', [q, N.z]) >>> d = outer(N.x, N.x) >>> d.express(B, N) cos(q)*(B.x|N.x) - sin(q)*(B.y|N.x)
- property func#
Returns the class Dyadic.
- subs(*args, **kwargs)[源代码]#
并矢上的代换。
实例
>>> from sympy.physics.vector import ReferenceFrame >>> from sympy import Symbol >>> N = ReferenceFrame('N') >>> s = Symbol('s') >>> a = s*(N.x|N.x) >>> a.subs({s: 2}) 2*(N.x|N.x)
- to_matrix(reference_frame, second_reference_frame=None)[源代码]#
返回关于一个或两个参考帧的并矢矩阵形式。
- 参数:
reference_frame :参考帧
矩阵的行和列所对应的参考框架。如果提供了第二个参考帧,则仅对应于矩阵的行。
second_reference_frame :ReferenceFrame,可选,默认值=无
矩阵列对应的参考框架。
- 返回:
矩阵 :不可变矩阵,形状(3,3)
给出二维张量形式的矩阵。
实例
>>> from sympy import symbols, trigsimp >>> from sympy.physics.vector import ReferenceFrame >>> from sympy.physics.mechanics import inertia >>> Ixx, Iyy, Izz, Ixy, Iyz, Ixz = symbols('Ixx, Iyy, Izz, Ixy, Iyz, Ixz') >>> N = ReferenceFrame('N') >>> inertia_dyadic = inertia(N, Ixx, Iyy, Izz, Ixy, Iyz, Ixz) >>> inertia_dyadic.to_matrix(N) Matrix([ [Ixx, Ixy, Ixz], [Ixy, Iyy, Iyz], [Ixz, Iyz, Izz]]) >>> beta = symbols('beta') >>> A = N.orientnew('A', 'Axis', (beta, N.x)) >>> trigsimp(inertia_dyadic.to_matrix(A)) Matrix([ [ Ixx, Ixy*cos(beta) + Ixz*sin(beta), -Ixy*sin(beta) + Ixz*cos(beta)], [ Ixy*cos(beta) + Ixz*sin(beta), Iyy*cos(2*beta)/2 + Iyy/2 + Iyz*sin(2*beta) - Izz*cos(2*beta)/2 + Izz/2, -Iyy*sin(2*beta)/2 + Iyz*cos(2*beta) + Izz*sin(2*beta)/2], [-Ixy*sin(beta) + Ixz*cos(beta), -Iyy*sin(2*beta)/2 + Iyz*cos(2*beta) + Izz*sin(2*beta)/2, -Iyy*cos(2*beta)/2 + Iyy/2 - Iyz*sin(2*beta) + Izz*cos(2*beta)/2 + Izz/2]])
- xreplace(rule)[源代码]#
Replace occurrences of objects within the measure numbers of the Dyadic.
- 参数:
rule :dict样
Expresses a replacement rule.
- 返回:
并矢
Result of the replacement.
实例
>>> from sympy import symbols, pi >>> from sympy.physics.vector import ReferenceFrame, outer >>> N = ReferenceFrame('N') >>> D = outer(N.x, N.x) >>> x, y, z = symbols('x y z') >>> ((1 + x*y) * D).xreplace({x: pi}) (pi*y + 1)*(N.x|N.x) >>> ((1 + x*y) * D).xreplace({x: pi, y: 2}) (1 + 2*pi)*(N.x|N.x)
仅当表达式树中的整个节点匹配时才会进行替换:
>>> ((x*y + z) * D).xreplace({x*y: pi}) (z + pi)*(N.x|N.x) >>> ((x*y*z) * D).xreplace({x*y: pi}) x*y*z*(N.x|N.x)