Deprecated Classes (Docstrings)#

自 1.13 版本弃用: Body and JointsMethod have been deprecated. The functionality of Body is fully captured by RigidBody and Particle and the functionality of JointsMethod is fully captured by System.

class sympy.physics.mechanics.body.Body(name, masscenter=None, mass=None, frame=None, central_inertia=None)[源代码]#

Body是刚体或粒子SymPy对象的常见表示,具体取决于初始化过程中传入的内容。如果传入一个质量,而“中心惯性”保留为“无”,则创建粒子对象。否则将创建刚体对象。

自 1.13 版本弃用: The Body class is deprecated. Its functionality is captured by RigidBody and Particle.

参数:

name :字符串

定义实体的名称。它用作定义实体特定属性的基础。

质量中心 :点,可选

质心代表物体或粒子质心的点。如果没有给定点,则生成一个点。

mass :可解释,可选

代表身体质量的可解释物体。如果没有质量通过,就会产生一个。

框架 :ReferenceFrame,可选

表示主体的参考框架的ReferenceFrame。如果没有给定帧,则生成一个帧。

central_inertia :并矢,可选

物体的中心惯性并矢。如果在创建刚体时没有传递,则生成默认惯性。

解释

主体所拥有的属性将与粒子实例或刚体实例相同,具体取决于创建的对象。下面列出了其他属性。

实例

As Body has been deprecated, the following examples are for illustrative purposes only. The functionality of Body is fully captured by RigidBody and Particle. To ignore the deprecation warning we can use the ignore_warnings context manager.

>>> from sympy.utilities.exceptions import ignore_warnings

违约行为。这将导致创建一个刚体对象,其“质量”、“质心”、“帧”和“惯性”属性均已给定默认值。:

>>> from sympy.physics.mechanics import Body
>>> with ignore_warnings(DeprecationWarning):
...     body = Body('name_of_body')

下一个示例演示指定Body对象的所有值所需的代码。注意这也将创建Body对象的刚体版本。:

>>> from sympy import Symbol
>>> from sympy.physics.mechanics import ReferenceFrame, Point, inertia
>>> from sympy.physics.mechanics import Body
>>> mass = Symbol('mass')
>>> masscenter = Point('masscenter')
>>> frame = ReferenceFrame('frame')
>>> ixx = Symbol('ixx')
>>> body_inertia = inertia(frame, ixx, 0, 0)
>>> with ignore_warnings(DeprecationWarning):
...     body = Body('name_of_body', masscenter, mass, frame, body_inertia)

创建实体对象的粒子版本所需的最小代码只需传入名称和质量。:

>>> from sympy import Symbol
>>> from sympy.physics.mechanics import Body
>>> mass = Symbol('mass')
>>> with ignore_warnings(DeprecationWarning):
...     body = Body('name_of_body', mass=mass)

实体对象的粒子版本也可以接收质量中心点和参考帧,而不是惯性。

属性

名称

(字符串)主体的名称

质量中心

(点)表示刚体质心的点

框架

(ReferenceFrame)主体固定在其中的参考坐标系

群众

(值得同情的)身体的质量

惯性

(并矢点)物体围绕其质心的惯性。该属性特定于刚体形式,对于粒子形式未定义

荷载

(iterable)此列表包含作用在主体上的不同荷载的信息。力列为(点,矢量)元组,转矩列为(参考帧,矢量)元组。

ang_vel_in(body)[源代码]#

Returns this body's angular velocity with respect to the provided rigid body or reference frame.

参数:

body: Body or ReferenceFrame

The rigid body or reference frame to calculate the angular velocity in.

例子

As Body has been deprecated, the following examples are for illustrative purposes only. The functionality of Body is fully captured by RigidBody and Particle. To ignore the deprecation warning we can use the ignore_warnings context manager.

>>> from sympy.utilities.exceptions import ignore_warnings
>>> from sympy.physics.mechanics import Body, ReferenceFrame
>>> with ignore_warnings(DeprecationWarning):
...     A = Body('A')
>>> N = ReferenceFrame('N')
>>> with ignore_warnings(DeprecationWarning):
...     B = Body('B', frame=N)
>>> A.frame.set_ang_vel(N, 5*N.x)
>>> A.ang_vel_in(B)
5*N.x
>>> A.ang_vel_in(N)
5*N.x
angular_momentum(point, frame)[源代码]#

返回刚体关于给定帧中某一点的角动量。

参数:

:点

角动量需要角动量的点。

框架 :参考帧

需要角动量的帧。

解释

刚体B关于框架N中某点O的角动量H由下式给出:

H = dot(I, w) + cross(r, m * v)

where I and m are the central inertia dyadic and mass of rigid body B, w is the angular velocity of body B in the frame N, r is the position vector from point O to the mass center of B, and v is the velocity of the mass center in the frame N.

实例

>>> from sympy.physics.mechanics import Point, ReferenceFrame, outer
>>> from sympy.physics.mechanics import RigidBody, dynamicsymbols
>>> from sympy.physics.vector import init_vprinting
>>> init_vprinting(pretty_print=False)
>>> m, v, r, omega = dynamicsymbols('m v r omega')
>>> N = ReferenceFrame('N')
>>> b = ReferenceFrame('b')
>>> b.set_ang_vel(N, omega * b.x)
>>> P = Point('P')
>>> P.set_vel(N, 1 * N.x)
>>> I = outer(b.x, b.x)
>>> B = RigidBody('B', P, b, m, (I, P))
>>> B.angular_momentum(P, N)
omega*b.x
apply_force(force, point=None, reaction_body=None, reaction_point=None)[源代码]#

Add force to the body(s).

参数:

force: Vector

The force to be applied.

点:点,可选

The point on self on which force is applied. By default self's masscenter.

reaction_body: Body, optional

Second body on which equal and opposite force is to be applied.

reaction_point : Point, optional

The point on other body on which equal and opposite force is applied. By default masscenter of other body.

解释

Applies the force on self or equal and opposite forces on self and other body if both are given on the desired point on the bodies. The force applied on other body is taken opposite of self, i.e, -force.

例子

As Body has been deprecated, the following examples are for illustrative purposes only. The functionality of Body is fully captured by RigidBody and Particle. To ignore the deprecation warning we can use the ignore_warnings context manager.

>>> from sympy.utilities.exceptions import ignore_warnings
>>> from sympy import symbols
>>> from sympy.physics.mechanics import Body, Point, dynamicsymbols
>>> m, g = symbols('m g')
>>> with ignore_warnings(DeprecationWarning):
...     B = Body('B')
>>> force1 = m*g*B.z
>>> B.apply_force(force1) #Applying force on B's masscenter
>>> B.loads
[(B_masscenter, g*m*B_frame.z)]

We can also remove some part of force from any point on the body by adding the opposite force to the body on that point.

>>> f1, f2 = dynamicsymbols('f1 f2')
>>> P = Point('P') #Considering point P on body B
>>> B.apply_force(f1*B.x + f2*B.y, P)
>>> B.loads
[(B_masscenter, g*m*B_frame.z), (P, f1(t)*B_frame.x + f2(t)*B_frame.y)]

Let's remove f1 from point P on body B.

>>> B.apply_force(-f1*B.x, P)
>>> B.loads
[(B_masscenter, g*m*B_frame.z), (P, f2(t)*B_frame.y)]

To further demonstrate the use of apply_force attribute, consider two bodies connected through a spring.

>>> from sympy.physics.mechanics import Body, dynamicsymbols
>>> with ignore_warnings(DeprecationWarning):
...     N = Body('N') #Newtonion Frame
>>> x = dynamicsymbols('x')
>>> with ignore_warnings(DeprecationWarning):
...     B1 = Body('B1')
...     B2 = Body('B2')
>>> spring_force = x*N.x

Now let's apply equal and opposite spring force to the bodies.

>>> P1 = Point('P1')
>>> P2 = Point('P2')
>>> B1.apply_force(spring_force, point=P1, reaction_body=B2, reaction_point=P2)

We can check the loads(forces) applied to bodies now.

>>> B1.loads
[(P1, x(t)*N_frame.x)]
>>> B2.loads
[(P2, - x(t)*N_frame.x)]

笔记

If a new force is applied to a body on a point which already has some force applied on it, then the new force is added to the already applied force on that point.

apply_torque(torque, reaction_body=None)[源代码]#

Add torque to the body(s).

参数:

torque: Vector

The torque to be applied.

reaction_body: Body, optional

Second body on which equal and opposite torque is to be applied.

解释

Applies the torque on self or equal and opposite torques on self and other body if both are given. The torque applied on other body is taken opposite of self, i.e, -torque.

例子

As Body has been deprecated, the following examples are for illustrative purposes only. The functionality of Body is fully captured by RigidBody and Particle. To ignore the deprecation warning we can use the ignore_warnings context manager.

>>> from sympy.utilities.exceptions import ignore_warnings
>>> from sympy import symbols
>>> from sympy.physics.mechanics import Body, dynamicsymbols
>>> t = symbols('t')
>>> with ignore_warnings(DeprecationWarning):
...     B = Body('B')
>>> torque1 = t*B.z
>>> B.apply_torque(torque1)
>>> B.loads
[(B_frame, t*B_frame.z)]

We can also remove some part of torque from the body by adding the opposite torque to the body.

>>> t1, t2 = dynamicsymbols('t1 t2')
>>> B.apply_torque(t1*B.x + t2*B.y)
>>> B.loads
[(B_frame, t1(t)*B_frame.x + t2(t)*B_frame.y + t*B_frame.z)]

Let's remove t1 from Body B.

>>> B.apply_torque(-t1*B.x)
>>> B.loads
[(B_frame, t2(t)*B_frame.y + t*B_frame.z)]

To further demonstrate the use, let us consider two bodies such that a torque \(T\) is acting on one body, and \(-T\) on the other.

>>> from sympy.physics.mechanics import Body, dynamicsymbols
>>> with ignore_warnings(DeprecationWarning):
...     N = Body('N') #Newtonion frame
...     B1 = Body('B1')
...     B2 = Body('B2')
>>> v = dynamicsymbols('v')
>>> T = v*N.y #Torque

Now let's apply equal and opposite torque to the bodies.

>>> B1.apply_torque(T, B2)

We can check the loads (torques) applied to bodies now.

>>> B1.loads
[(B1_frame, v(t)*N_frame.y)]
>>> B2.loads
[(B2_frame, - v(t)*N_frame.y)]

笔记

If a new torque is applied on body which already has some torque applied on it, then the new torque is added to the previous torque about the body's frame.

property central_inertia#

物体的中心惯性并矢。

clear_loads()[源代码]#

Clears the Body's loads list.

例子

As Body has been deprecated, the following examples are for illustrative purposes only. The functionality of Body is fully captured by RigidBody and Particle. To ignore the deprecation warning we can use the ignore_warnings context manager.

>>> from sympy.utilities.exceptions import ignore_warnings
>>> from sympy.physics.mechanics import Body
>>> with ignore_warnings(DeprecationWarning):
...     B = Body('B')
>>> force = B.x + B.y
>>> B.apply_force(force)
>>> B.loads
[(B_masscenter, B_frame.x + B_frame.y)]
>>> B.clear_loads()
>>> B.loads
[]
dcm(body)[源代码]#

Returns the direction cosine matrix of this body relative to the provided rigid body or reference frame.

参数:

body: Body or ReferenceFrame

The rigid body or reference frame to calculate the dcm.

例子

As Body has been deprecated, the following examples are for illustrative purposes only. The functionality of Body is fully captured by RigidBody and Particle. To ignore the deprecation warning we can use the ignore_warnings context manager.

>>> from sympy.utilities.exceptions import ignore_warnings
>>> from sympy.physics.mechanics import Body
>>> with ignore_warnings(DeprecationWarning):
...     A = Body('A')
...     B = Body('B')
>>> A.frame.orient_axis(B.frame, B.frame.x, 5)
>>> A.dcm(B)
Matrix([
[1,       0,      0],
[0,  cos(5), sin(5)],
[0, -sin(5), cos(5)]])
>>> A.dcm(B.frame)
Matrix([
[1,       0,      0],
[0,  cos(5), sin(5)],
[0, -sin(5), cos(5)]])
property frame#

The ReferenceFrame fixed to the body.

property inertia#

The body's inertia about a point; stored as (Dyadic, Point).

kinetic_energy(frame)[源代码]#

Kinetic energy of the body.

参数:

frame : ReferenceFrame or Body

The Body's angular velocity and the velocity of it's mass center are typically defined with respect to an inertial frame but any relevant frame in which the velocities are known can be supplied.

实例

As Body has been deprecated, the following examples are for illustrative purposes only. The functionality of Body is fully captured by RigidBody and Particle. To ignore the deprecation warning we can use the ignore_warnings context manager.

>>> from sympy.utilities.exceptions import ignore_warnings
>>> from sympy.physics.mechanics import Body, ReferenceFrame, Point
>>> from sympy import symbols
>>> m, v, r, omega = symbols('m v r omega')
>>> N = ReferenceFrame('N')
>>> O = Point('O')
>>> with ignore_warnings(DeprecationWarning):
...     P = Body('P', masscenter=O, mass=m)
>>> P.masscenter.set_vel(N, v * N.y)
>>> P.kinetic_energy(N)
m*v**2/2
>>> N = ReferenceFrame('N')
>>> b = ReferenceFrame('b')
>>> b.set_ang_vel(N, omega * b.x)
>>> P = Point('P')
>>> P.set_vel(N, v * N.x)
>>> with ignore_warnings(DeprecationWarning):
...     B = Body('B', masscenter=P, frame=b)
>>> B.kinetic_energy(N)
B_ixx*omega**2/2 + B_mass*v**2/2

参见

sympy.physics.mechanics

Particle, RigidBody

linear_momentum(frame)[源代码]#

刚体的线动量。

参数:

框架 :参考帧

需要线性动量的帧。

解释

The linear momentum L, of a rigid body B, with respect to frame N is given by:

L = m * v

where m is the mass of the rigid body, and v is the velocity of the mass center of B in the frame N.

实例

>>> from sympy.physics.mechanics import Point, ReferenceFrame, outer
>>> from sympy.physics.mechanics import RigidBody, dynamicsymbols
>>> from sympy.physics.vector import init_vprinting
>>> init_vprinting(pretty_print=False)
>>> m, v = dynamicsymbols('m v')
>>> N = ReferenceFrame('N')
>>> P = Point('P')
>>> P.set_vel(N, v * N.x)
>>> I = outer (N.x, N.x)
>>> Inertia_tuple = (I, P)
>>> B = RigidBody('B', P, N, m, Inertia_tuple)
>>> B.linear_momentum(N)
m*v*N.x
property mass#

The body's mass.

property masscenter#

The body's center of mass.

masscenter_vel(body)[源代码]#

Returns the velocity of the mass center with respect to the provided rigid body or reference frame.

参数:

body: Body or ReferenceFrame

The rigid body or reference frame to calculate the velocity in.

例子

As Body has been deprecated, the following examples are for illustrative purposes only. The functionality of Body is fully captured by RigidBody and Particle. To ignore the deprecation warning we can use the ignore_warnings context manager.

>>> from sympy.utilities.exceptions import ignore_warnings
>>> from sympy.physics.mechanics import Body
>>> with ignore_warnings(DeprecationWarning):
...     A = Body('A')
...     B = Body('B')
>>> A.masscenter.set_vel(B.frame, 5*B.frame.x)
>>> A.masscenter_vel(B)
5*B_frame.x
>>> A.masscenter_vel(B.frame)
5*B_frame.x
property name#

The name of the body.

parallel_axis(point, frame=None)[源代码]#

返回物体相对于另一点的惯性并矢。

参数:

: sympy.物理.矢量.点

表示惯性并矢的点。

框架 : sympy.物理.矢量.参考框架

用来构造并矢的参考坐标系。

返回:

惯性 : sympy.物理.矢量.并矢

刚体的惯量并矢表示在给定点附近。

例子

As Body has been deprecated, the following examples are for illustrative purposes only. The functionality of Body is fully captured by RigidBody and Particle. To ignore the deprecation warning we can use the ignore_warnings context manager.

>>> from sympy.utilities.exceptions import ignore_warnings
>>> from sympy.physics.mechanics import Body
>>> with ignore_warnings(DeprecationWarning):
...     A = Body('A')
>>> P = A.masscenter.locatenew('point', 3 * A.x + 5 * A.y)
>>> A.parallel_axis(P).to_matrix(A.frame)
Matrix([
[A_ixx + 25*A_mass, A_ixy - 15*A_mass,             A_izx],
[A_ixy - 15*A_mass,  A_iyy + 9*A_mass,             A_iyz],
[            A_izx,             A_iyz, A_izz + 34*A_mass]])
property point#

The body's center of mass.

property potential_energy#

The potential energy of the body.

实例

>>> from sympy.physics.mechanics import Particle, Point
>>> from sympy import symbols
>>> m, g, h = symbols('m g h')
>>> O = Point('O')
>>> P = Particle('P', O, m)
>>> P.potential_energy = m * g * h
>>> P.potential_energy
g*h*m
remove_load(about=None)[源代码]#

Remove load about a point or frame.

参数:

about : Point or ReferenceFrame, optional

The point about which force is applied, and is to be removed. If about is None, then the torque about self's frame is removed.

例子

As Body has been deprecated, the following examples are for illustrative purposes only. The functionality of Body is fully captured by RigidBody and Particle. To ignore the deprecation warning we can use the ignore_warnings context manager.

>>> from sympy.utilities.exceptions import ignore_warnings
>>> from sympy.physics.mechanics import Body, Point
>>> with ignore_warnings(DeprecationWarning):
...     B = Body('B')
>>> P = Point('P')
>>> f1 = B.x
>>> f2 = B.y
>>> B.apply_force(f1)
>>> B.apply_force(f2, P)
>>> B.loads
[(B_masscenter, B_frame.x), (P, B_frame.y)]
>>> B.remove_load(P)
>>> B.loads
[(B_masscenter, B_frame.x)]
property x#

The basis Vector for the Body, in the x direction.

property y#

The basis Vector for the Body, in the y direction.

property z#

The basis Vector for the Body, in the z direction.

class sympy.physics.mechanics.jointsmethod.JointsMethod(newtonion, *joints)[源代码]#

Method for formulating the equations of motion using a set of interconnected bodies with joints.

自 1.13 版本弃用: The JointsMethod class is deprecated. Its functionality has been replaced by the new System class.

参数:

newtonion : Body or ReferenceFrame

The newtonion(inertial) frame.

*joints : Joint

The joints in the system

实例

As Body and JointsMethod have been deprecated, the following examples are for illustrative purposes only. The functionality of Body is fully captured by RigidBody and Particle and the functionality of JointsMethod is fully captured by System. To ignore the deprecation warning we can use the ignore_warnings context manager.

>>> from sympy.utilities.exceptions import ignore_warnings

这是一个单自由度平动弹簧质量阻尼器的简单例子。

>>> from sympy import symbols
>>> from sympy.physics.mechanics import Body, JointsMethod, PrismaticJoint
>>> from sympy.physics.vector import dynamicsymbols
>>> c, k = symbols('c k')
>>> x, v = dynamicsymbols('x v')
>>> with ignore_warnings(DeprecationWarning):
...     wall = Body('W')
...     body = Body('B')
>>> J = PrismaticJoint('J', wall, body, coordinates=x, speeds=v)
>>> wall.apply_force(c*v*wall.x, reaction_body=body)
>>> wall.apply_force(k*x*wall.x, reaction_body=body)
>>> with ignore_warnings(DeprecationWarning):
...     method = JointsMethod(wall, J)
>>> method.form_eoms()
Matrix([[-B_mass*Derivative(v(t), t) - c*v(t) - k*x(t)]])
>>> M = method.mass_matrix_full
>>> F = method.forcing_full
>>> rhs = M.LUsolve(F)
>>> rhs
Matrix([
[                     v(t)],
[(-c*v(t) - k*x(t))/B_mass]])

笔记

JointsMethod currently only works with systems that do not have any configuration or motion constraints.

属性

q、 美国

(iterable) Iterable of the generalized coordinates and speeds

身体

(iterable) Iterable of Body objects in the system.

荷载

(iterable)描述系统上力的(Point,vector)或(ReferenceFrame,vector)元组的iterable。

mass_matrix

(Matrix, shape(n, n)) The system's mass matrix

强迫

(Matrix, shape(n, 1)) The system's forcing vector

mass_matrix_full

(Matrix, shape(2*n, 2*n)) The "mass matrix" for the u's and q's

forcing_full

(Matrix, shape(2*n, 1)) The "forcing vector" for the u's and q's

方法

(KanesMethod or Lagrange's method) Method's object.

kdes

(iterable) Iterable of kde in they system.

property bodies#

List of bodies in they system.

property forcing#

The system's forcing vector.

property forcing_full#

The "forcing vector" for the u's and q's.

form_eoms(method=<class 'sympy.physics.mechanics.kane.KanesMethod'>)[源代码]#

Method to form system's equation of motions.

参数:

method : Class

Class name of method.

返回:

矩阵

Vector of equations of motions.

实例

As Body and JointsMethod have been deprecated, the following examples are for illustrative purposes only. The functionality of Body is fully captured by RigidBody and Particle and the functionality of JointsMethod is fully captured by System. To ignore the deprecation warning we can use the ignore_warnings context manager.

>>> from sympy.utilities.exceptions import ignore_warnings

这是一个单自由度平动弹簧质量阻尼器的简单例子。

>>> from sympy import S, symbols
>>> from sympy.physics.mechanics import LagrangesMethod, dynamicsymbols, Body
>>> from sympy.physics.mechanics import PrismaticJoint, JointsMethod
>>> q = dynamicsymbols('q')
>>> qd = dynamicsymbols('q', 1)
>>> m, k, b = symbols('m k b')
>>> with ignore_warnings(DeprecationWarning):
...     wall = Body('W')
...     part = Body('P', mass=m)
>>> part.potential_energy = k * q**2 / S(2)
>>> J = PrismaticJoint('J', wall, part, coordinates=q, speeds=qd)
>>> wall.apply_force(b * qd * wall.x, reaction_body=part)
>>> with ignore_warnings(DeprecationWarning):
...     method = JointsMethod(wall, J)
>>> method.form_eoms(LagrangesMethod)
Matrix([[b*Derivative(q(t), t) + k*q(t) + m*Derivative(q(t), (t, 2))]])

我们也可以用“rhs”方法求解状态。

>>> method.rhs()
Matrix([
[                Derivative(q(t), t)],
[(-b*Derivative(q(t), t) - k*q(t))/m]])
property kdes#

List of the generalized coordinates.

property loads#

List of loads on the system.

property mass_matrix#

The system's mass matrix.

property mass_matrix_full#

The "mass matrix" for the u's and q's.

property method#

Object of method used to form equations of systems.

property q#

List of the generalized coordinates.

rhs(inv_method=None)[源代码]#

Returns equations that can be solved numerically.

参数:

inv_method :结构

The specific sympy inverse matrix calculation method to use. For a list of valid methods, see inv()

返回:

矩阵

Numerically solvable equations.

参见

sympy.physics.mechanics.kane.KanesMethod.rhs

KanesMethod's rhs function.

sympy.physics.mechanics.lagrange.LagrangesMethod.rhs

LagrangesMethod's rhs function.

property u#

List of the generalized speeds.