Essential Classes

CoordinateSym

class sympy.physics.vector.frame.CoordinateSym(name, frame, index)[source]

A coordinate symbol/base scalar associated wrt a Reference Frame.

Ideally, users should not instantiate this class. Instances of this class must only be accessed through the corresponding frame as ‘frame[index]’.

CoordinateSyms having the same frame and index parameters are equal (even though they may be instantiated separately).

Parameters

name : string

The display name of the CoordinateSym

frame : ReferenceFrame

The reference frame this base scalar belongs to

index : 0, 1 or 2

The index of the dimension denoted by this coordinate variable

Examples

>>> 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

ReferenceFrame

class sympy.physics.vector.frame.ReferenceFrame(name, indices=None, latexs=None, variables=None)[source]

A reference frame in classical mechanics.

ReferenceFrame is a class used to represent a reference frame in classical mechanics. It has a standard basis of three unit vectors in the frame’s x, y, and z directions.

It also can have a rotation relative to a parent frame; this rotation is defined by a direction cosine matrix relating this frame’s basis vectors to the parent frame’s basis vectors. It can also have an angular velocity vector, defined in another frame.

ang_acc_in(otherframe)[source]

Returns the angular acceleration Vector of the 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.

Parameters

otherframe : ReferenceFrame

The ReferenceFrame which the angular acceleration is returned in.

Examples

>>> 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)[source]

Returns the angular velocity Vector of the 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.

Parameters

otherframe : ReferenceFrame

The ReferenceFrame which the angular velocity is returned in.

Examples

>>> 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)[source]

Returns the direction cosine matrix relative to the provided reference frame.

The returned matrix can be used to express the orthogonal unit vectors of this frame in terms of the orthogonal unit vectors of otherframe.

Parameters

otherframe : ReferenceFrame

The reference frame which the direction cosine matrix of this frame is formed relative to.

Examples

The following example rotates the reference frame A relative to N by a simple rotation and then calculates the direction cosine matrix of N relative to A.

>>> from sympy import symbols, sin, cos
>>> from sympy.physics.vector import ReferenceFrame
>>> q1 = symbols('q1')
>>> N = ReferenceFrame('N')
>>> A = N.orientnew('A', 'Axis', (q1, N.x))
>>> N.dcm(A)
Matrix([
[1,       0,        0],
[0, cos(q1), -sin(q1)],
[0, sin(q1),  cos(q1)]])

The second row of the above direction cosine matrix represents the N.y unit vector in N expressed in A. Like so:

>>> Ny = 0*A.x + cos(q1)*A.y - sin(q1)*A.z

Thus, expressing N.y in A should return the same result:

>>> N.y.express(A)
cos(q1)*A.y - sin(q1)*A.z

Notes

It is import 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 relative to A”. This is the matrix \(^{\mathbf{A}} \mathbf{R} ^{\mathbf{B}}\) shown in the following relationship:

\[\begin{split}\begin{bmatrix} \hat{\mathbf{b}}_1 \\ \hat{\mathbf{b}}_2 \\ \hat{\mathbf{b}}_3 \end{bmatrix} = {}^A\mathbf{R}^B \begin{bmatrix} \hat{\mathbf{a}}_1 \\ \hat{\mathbf{a}}_2 \\ \hat{\mathbf{a}}_3 \end{bmatrix}.\end{split}\]

\({}^A\mathbf{R}^B\) is the matrix that expresses the B unit vectors in terms of the A unit vectors.

orient(parent, rot_type, amounts, rot_order='')[source]

Sets the orientation of this reference frame relative to another (parent) reference frame.

Note

It is now recommended to use the .orient_axis, .orient_body_fixed, .orient_space_fixed, .orient_quaternion methods for the different rotation types.

Parameters

parent : ReferenceFrame

Reference frame that this reference frame will be rotated relative to.

rot_type : str

The method used to generate the direction cosine matrix. Supported methods are:

  • 'Axis': simple rotations about a single common axis

  • 'DCM': for setting the direction cosine matrix directly

  • 'Body': three successive rotations about new intermediate axes, also called “Euler and Tait-Bryan angles”

  • 'Space': three successive rotations about the parent frames’ unit vectors

  • 'Quaternion': rotations defined by four parameters which result in a singularity free direction cosine matrix

amounts :

Expressions defining the rotation angles or direction cosine matrix. These must match the rot_type. See examples below for details. The input types are:

  • 'Axis': 2-tuple (expr/sym/func, Vector)

  • 'DCM': Matrix, shape(3,3)

  • 'Body': 3-tuple of expressions, symbols, or functions

  • 'Space': 3-tuple of expressions, symbols, or functions

  • 'Quaternion': 4-tuple of expressions, symbols, or functions

rot_order : str or int, optional

If applicable, the order of the successive of rotations. The string '123' and integer 123 are equivalent, for example. Required for 'Body' and 'Space'.

Warns

UserWarning

If the orientation creates a kinematic loop.

orient_axis(parent, axis, angle)[source]

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.

Parameters

parent : ReferenceFrame

Reference frame that this reference frame will be rotated relative to.

axis : Vector

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.

Examples

Setup variables for the examples:

>>> 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)[source]

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.

Parameters

parent : ReferenceFrame

Reference frame that this reference frame will be rotated relative to.

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 integer 131. 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.

Examples

Setup variables for the examples:

>>> 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 about N.x, then rotates B again through q2 about B.y, and finally through q3 about B.x. It is equivalent to three successive orient_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)]])

Acceptable rotation orders are of length 3, expressed in as a string 'XYZ' or '123' or integer 123. Rotations about an axis twice in a row are prohibited.

>>> 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_explicit(parent, dcm)[source]

Sets the orientation of this reference frame relative to a parent reference frame by explicitly setting the direction cosine matrix.

Parameters

parent : ReferenceFrame

Reference frame that this reference frame will be rotated relative to.

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.

Examples

Setup variables for the examples:

>>> 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 to N about N.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_explicit(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)]])

Note carefully that N.dcm(B) (the transpose) would be passed into orient_explicit() for A.dcm(N) to match B.dcm(N):

>>> A.orient_explicit(N, N.dcm(B))
>>> A.dcm(N)
Matrix([
[1,       0,      0],
[0,  cos(q1), sin(q1)],
[0, -sin(q1), cos(q1)]])
orient_quaternion(parent, numbers)[source]

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 angle theta. 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.

Parameters

parent : ReferenceFrame

Reference frame that this reference frame will be rotated relative to.

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.

Examples

Setup variables for the examples:

>>> 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)[source]

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.

Parameters

parent : ReferenceFrame

Reference frame that this reference frame will be rotated relative to.

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 integer 131. There are 12 unique valid rotation orders.

Warns

UserWarning

If the orientation creates a kinematic loop.

Examples

Setup variables for the examples:

>>> 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)]])

is equivalent to:

>>> 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)]])

It is worth noting that space-fixed and body-fixed rotations are related by the order of the rotations, i.e. the reverse order of body fixed will give space fixed and vice versa.

>>> 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)[source]

Returns a new reference frame oriented with respect to this reference frame.

See ReferenceFrame.orient() for detailed examples of how to orient reference frames.

Parameters

newname : str

Name for the new reference frame.

rot_type : str

The method used to generate the direction cosine matrix. Supported methods are:

  • 'Axis': simple rotations about a single common axis

  • 'DCM': for setting the direction cosine matrix directly

  • 'Body': three successive rotations about new intermediate axes, also called “Euler and Tait-Bryan angles”

  • 'Space': three successive rotations about the parent frames’ unit vectors

  • 'Quaternion': rotations defined by four parameters which result in a singularity free direction cosine matrix

amounts :

Expressions defining the rotation angles or direction cosine matrix. These must match the rot_type. See examples below for details. The input types are:

  • 'Axis': 2-tuple (expr/sym/func, Vector)

  • 'DCM': Matrix, shape(3,3)

  • 'Body': 3-tuple of expressions, symbols, or functions

  • 'Space': 3-tuple of expressions, symbols, or functions

  • 'Quaternion': 4-tuple of expressions, symbols, or functions

rot_order : str or int, optional

If applicable, the order of the successive of rotations. The string '123' and integer 123 are equivalent, for example. Required for 'Body' and 'Space'.

indices : tuple of str

Enables the reference frame’s basis unit vectors to be accessed by Python’s square bracket indexing notation using the provided three indice strings and alters the printing of the unit vectors to reflect this choice.

latexs : tuple of str

Alters the LaTeX printing of the reference frame’s basis unit vectors to the provided three valid LaTeX strings.

Examples

>>> from sympy import symbols
>>> from sympy.physics.vector import ReferenceFrame, vlatex
>>> q0, q1, q2, q3 = symbols('q0 q1 q2 q3')
>>> N = ReferenceFrame('N')

Create a new reference frame A rotated relative to N through a simple rotation.

>>> A = N.orientnew('A', 'Axis', (q0, N.x))

Create a new reference frame B rotated relative to N through body-fixed rotations.

>>> B = N.orientnew('B', 'Body', (q1, q2, q3), '123')

Create a new reference frame C rotated relative to N through a simple rotation with unique indices and LaTeX printing.

>>> 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)[source]

Returns the partial angular velocities of this frame in the given frame with respect to one or more provided generalized speeds.

Parameters

frame : ReferenceFrame

The frame with which the angular velocity is defined in.

gen_speeds : functions of time

The generalized speeds.

Returns

partial_velocities : tuple of Vector

The partial angular velocity vectors corresponding to the provided generalized speeds.

Examples

>>> 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)[source]

Define the angular acceleration Vector in a ReferenceFrame.

Defines the angular acceleration of this ReferenceFrame, in another. Angular acceleration can be defined with respect to multiple different ReferenceFrames. Care must be taken to not create loops which are inconsistent.

Parameters

otherframe : ReferenceFrame

A ReferenceFrame to define the angular acceleration in

value : Vector

The Vector representing angular acceleration

Examples

>>> 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)[source]

Define the angular velocity vector in a ReferenceFrame.

Defines the angular velocity of this ReferenceFrame, in another. Angular velocity can be defined with respect to multiple different ReferenceFrames. Care must be taken to not create loops which are inconsistent.

Parameters

otherframe : ReferenceFrame

A ReferenceFrame to define the angular velocity in

value : Vector

The Vector representing angular velocity

Examples

>>> 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
variable_map(otherframe)[source]

Returns a dictionary which expresses the coordinate variables of this frame in terms of the variables of otherframe.

If Vector.simp is True, returns a simplified version of the mapped values. Else, returns them without simplification.

Simplification of the expressions may take time.

Parameters

otherframe : ReferenceFrame

The other frame to map the variables to

Examples

>>> 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

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

property y

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

property z

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

Vector

class sympy.physics.vector.vector.Vector(inlist)[source]

The class used to define vectors.

It along with ReferenceFrame are the building blocks of describing a classical mechanics system in PyDy and sympy.physics.vector.

Attributes

simp

(Boolean) Let certain methods use trigsimp on their outputs

angle_between(vec)[source]

Returns the smallest angle between Vector ‘vec’ and self.

Warning

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().

Parameter

vecVector

The Vector between which angle is needed.

Examples

>>> 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)
applyfunc(f)[source]

Apply a function to each component of a vector.

cross(other)[source]

The cross product operator for two Vectors.

Returns a Vector, expressed in the same ReferenceFrames as self.

Parameters

other : Vector

The Vector which we are crossing with

Examples

>>> from sympy.physics.vector import ReferenceFrame
>>> from sympy import symbols
>>> q1 = symbols('q1')
>>> N = ReferenceFrame('N')
>>> N.x ^ N.y
N.z
>>> A = N.orientnew('A', 'Axis', [q1, N.x])
>>> A.x ^ N.y
N.z
>>> N.y ^ A.x
- sin(q1)*A.y - cos(q1)*A.z
diff(var, frame, var_in_dcm=True)[source]

Returns the partial derivative of the vector with respect to a variable in the provided reference frame.

Parameters

var : Symbol

What the partial derivative is taken with respect to.

frame : ReferenceFrame

The reference frame that the partial derivative is taken in.

var_in_dcm : boolean

If true, the differentiation algorithm assumes that the variable may be present in any of the direction cosine matrices that relate the frame to the frames of any component of the vector. But if it is known that the variable is not present in the direction cosine matrices, false can be set to skip full reexpression in the desired frame.

Examples

>>> from sympy import Symbol
>>> from sympy.physics.vector import dynamicsymbols, ReferenceFrame
>>> from sympy.physics.vector import Vector
>>> from sympy.physics.vector import init_vprinting
>>> init_vprinting(pretty_print=False)
>>> Vector.simp = True
>>> t = Symbol('t')
>>> q1 = dynamicsymbols('q1')
>>> N = ReferenceFrame('N')
>>> A = N.orientnew('A', 'Axis', [q1, N.y])
>>> A.x.diff(t, N)
- 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
doit(**hints)[source]

Calls .doit() on each term in the Vector

dot(other)[source]

Dot product of two vectors.

Returns a scalar, the dot product of the two Vectors

Parameters

other : Vector

The Vector which we are dotting with

Examples

>>> 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)
dt(otherframe)[source]

Returns a Vector which is the time derivative of the self Vector, taken in frame otherframe.

Calls the global time_derivative method

Parameters

otherframe : ReferenceFrame

The frame to calculate the time derivative in

express(otherframe, variables=False)[source]

Returns a Vector equivalent to this one, expressed in otherframe. Uses the global express method.

Parameters

otherframe : ReferenceFrame

The frame for this Vector to be described in

variables : boolean

If True, the coordinate symbols(if present) in this Vector are re-expressed in terms otherframe

Examples

>>> 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_symbols(reference_frame)[source]

Returns the free symbols in the measure numbers of the vector expressed in the given reference frame.

Parameter

reference_frameReferenceFrame

The frame with respect to which the free symbols of the given vector is to be determined.

property func

Returns the class Vector.

magnitude()[source]

Returns the magnitude (Euclidean norm) of self.

Warning

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().

normalize()[source]

Returns a Vector of magnitude 1, codirectional with self.

outer(other)[source]

Outer product between two Vectors.

A rank increasing operation, which returns a Dyadic from two Vectors

Parameters

other : Vector

The Vector to take the outer product with

Examples

>>> from sympy.physics.vector import ReferenceFrame, outer
>>> N = ReferenceFrame('N')
>>> outer(N.x, N.x)
(N.x|N.x)
separate()[source]

The constituents of this vector in different reference frames, as per its definition.

Returns a dict mapping each ReferenceFrame to the corresponding constituent Vector.

Examples

>>> 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
simplify()[source]

Returns a simplified Vector.

subs(*args, **kwargs)[source]

Substitution on the Vector.

Examples

>>> 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)[source]

Returns the matrix form of the vector with respect to the given frame.

Parameters

reference_frame : ReferenceFrame

The reference frame that the rows of the matrix correspond to.

Returns

matrix : ImmutableMatrix, shape(3,1)

The matrix that gives the 1D vector.

Examples

>>> 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)[source]

Replace occurrences of objects within the measure numbers of the vector.

Parameters

rule : dict-like

Expresses a replacement rule.

Returns

Vector

Result of the replacement.

Examples

>>> 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

Replacements occur only if an entire node in the expression tree is matched:

>>> ((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

Dyadic

class sympy.physics.vector.dyadic.Dyadic(inlist)[source]

A Dyadic object.

See: https://en.wikipedia.org/wiki/Dyadic_tensor Kane, T., Levinson, D. Dynamics Theory and Applications. 1985 McGraw-Hill

A more powerful way to represent a rigid body’s inertia. While it is more complex, by choosing Dyadic components to be in body fixed basis vectors, the resulting matrix is equivalent to the inertia tensor.

applyfunc(f)[source]

Apply a function to each component of a Dyadic.

cross(other)[source]

For a cross product in the form: Dyadic x Vector.

Parameters

other : Vector

The Vector that we are crossing this Dyadic with

Examples

>>> 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)
doit(**hints)[source]

Calls .doit() on each term in the Dyadic

dot(other)[source]

The inner product operator for a Dyadic and a Dyadic or Vector.

Parameters

other : Dyadic or Vector

The other Dyadic or Vector to take the inner product with

Examples

>>> 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)[source]

Take the time derivative of this Dyadic in a frame.

This function calls the global time_derivative method

Parameters

frame : ReferenceFrame

The frame to take the time derivative in

Examples

>>> 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)[source]

Expresses this Dyadic in alternate frame(s)

The first frame is the list side expression, the second frame is the right side; if Dyadic is in form A.x|B.y, you can express it in two different frames. If no second frame is given, the Dyadic is expressed in only one frame.

Calls the global express function

Parameters

frame1 : ReferenceFrame

The frame to express the left side of the Dyadic in

frame2 : ReferenceFrame

If provided, the frame to express the right side of the Dyadic in

Examples

>>> 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.

simplify()[source]

Returns a simplified Dyadic.

subs(*args, **kwargs)[source]

Substitution on the Dyadic.

Examples

>>> 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)[source]

Returns the matrix form of the dyadic with respect to one or two reference frames.

Parameters

reference_frame : ReferenceFrame

The reference frame that the rows and columns of the matrix correspond to. If a second reference frame is provided, this only corresponds to the rows of the matrix.

second_reference_frame : ReferenceFrame, optional, default=None

The reference frame that the columns of the matrix correspond to.

Returns

matrix : ImmutableMatrix, shape(3,3)

The matrix that gives the 2D tensor form.

Examples

>>> from sympy import symbols
>>> from sympy.physics.vector import ReferenceFrame, Vector
>>> Vector.simp = True
>>> 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))
>>> 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)[source]

Replace occurrences of objects within the measure numbers of the Dyadic.

Parameters

rule : dict-like

Expresses a replacement rule.

Returns

Dyadic

Result of the replacement.

Examples

>>> 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)

Replacements occur only if an entire node in the expression tree is matched:

>>> ((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)