Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Multiple Coordinate System #12020

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/src/modules/vector/api/classes.rst
Expand Up @@ -5,10 +5,10 @@ Essential Classes in sympy.vector (doctrings)
CoordSysCartesian
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this title be changed, too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because CoordSysCartesian class is replaced by CartesianCoordinateSystem. I will change it in the next commit.

=================

.. autoclass:: sympy.vector.coordsysrect.CoordSysCartesian
.. autoclass:: sympy.vector.coordsys.CartesianCoordinateSystem
:members:

.. automethod:: sympy.vector.coordsysrect.CoordSysCartesian.__init__
.. automethod:: sympy.vector.coordsys.CartesianCoordinateSystem.__init__


Vector
Expand Down
22 changes: 11 additions & 11 deletions doc/src/modules/vector/basics.rst
Expand Up @@ -9,13 +9,13 @@ As of now, :mod:`sympy.vector` only deals with the Cartesian (also called
rectangular) coordinate systems. A 3D Cartesian coordinate system can
be initialized in :mod:`sympy.vector` as

>>> from sympy.vector import CoordSysCartesian
>>> N = CoordSysCartesian('N')
>>> from sympy.vector import CartesianCoordinateSystem
>>> N = CartesianCoordinateSystem('N')

The string parameter to the constructor denotes the name assigned to the
system, and will primarily be used for printing purposes.

Once a coordinate system (in essence, a ``CoordSysCartesian`` instance)
Once a coordinate system (in essence, a ``CartesianCoordinateSystem`` instance)
has been defined, we can access the orthonormal unit vectors (i.e. the
:math:`\mathbf{\hat{i}}`, :math:`\mathbf{\hat{j}}` and
:math:`\mathbf{\hat{k}}` vectors) and coordinate variables/base
Expand Down Expand Up @@ -76,7 +76,7 @@ All the classes shown above - ``BaseVector``, ``VectorMul``,

You should never have to instantiate objects of any of the
subclasses of ``Vector``. Using the ``BaseVector`` instances assigned to a
``CoordSysCartesian`` instance and (if needed) ``Vector.zero``
``CartesianCoordinateSystem`` instance and (if needed) ``Vector.zero``
as building blocks, any sort of vectorial expression can be constructed
with the basic mathematical operators ``+``, ``-``, ``*``.
and ``/``.
Expand Down Expand Up @@ -164,10 +164,10 @@ point. Points, in general, have been implemented in :mod:`sympy.vector` in the
form of the ``Point`` class.

To access the origin of system, use the ``origin`` property of the
``CoordSysCartesian`` class.
``CartesianCoordinateSystem`` class.

>>> from sympy.vector import CoordSysCartesian
>>> N = CoordSysCartesian('N')
>>> from sympy.vector import CartesianCoordinateSystem
>>> N = CartesianCoordinateSystem('N')
>>> N.origin
N.origin
>>> type(N.origin)
Expand All @@ -184,7 +184,7 @@ new ``Point``, and its position vector with respect to the

Like ``Vector``, a user never has to expressly instantiate an object of
``Point``. This is because any location in space (albeit relative) can be
pointed at by using the ``origin`` of a ``CoordSysCartesian`` as the
pointed at by using the ``origin`` of a ``CartesianCoordinateSystem`` as the
reference, and then using ``locate_new`` on it and subsequent
``Point`` instances.

Expand All @@ -197,7 +197,7 @@ be computed using the ``position_wrt`` method.
a*N.i + c*N.k

Additionally, it is possible to obtain the :math:`X`, :math:`Y` and :math:`Z`
coordinates of a ``Point`` with respect to a ``CoordSysCartesian``
coordinates of a ``Point`` with respect to a ``CartesianCoordinateSystem``
in the form of a tuple. This is done using the ``express_coordinates``
method.

Expand All @@ -218,8 +218,8 @@ The outer products of vectors can be computed using the ``outer``
method of ``Vector``. The ``|`` operator has been overloaded for
``outer``.

>>> from sympy.vector import CoordSysCartesian
>>> N = CoordSysCartesian('N')
>>> from sympy.vector import CartesianCoordinateSystem
>>> N = CartesianCoordinateSystem('N')
>>> N.i.outer(N.j)
(N.i|N.j)
>>> N.i|N.j
Expand Down
26 changes: 13 additions & 13 deletions doc/src/modules/vector/coordsys.rst
Expand Up @@ -10,7 +10,7 @@ Locating new systems
====================

We already know that the ``origin`` property of a
``CoordSysCartesian`` corresponds to the ``Point`` instance
``CartesianCoordinateSystem`` corresponds to the ``Point`` instance
denoting its origin reference point.

Consider a coordinate system :math:`N`. Suppose we want to define
Expand All @@ -23,8 +23,8 @@ would be :math:`(-3, -4, -5)`.

This can be achieved programatically as follows -

>>> from sympy.vector import CoordSysCartesian
>>> N = CoordSysCartesian('N')
>>> from sympy.vector import CartesianCoordinateSystem
>>> N = CartesianCoordinateSystem('N')
>>> M = N.locate_new('M', 3*N.i + 4*N.j + 5*N.k)
>>> M.position_wrt(N)
3*N.i + 4*N.j + 5*N.k
Expand All @@ -35,21 +35,21 @@ It is worth noting that :math:`M`'s orientation is the same as that of
:math:`N`. This means that the rotation matrix of :math: `N` with respect
to :math:`M`, and also vice versa, is equal to the identity matrix of
dimensions 3x3.
The ``locate_new`` method initializes a ``CoordSysCartesian`` that
The ``locate_new`` method initializes a ``CartesianCoordinateSystem`` that
is only translated in space, not re-oriented, relative to the 'parent'
system.

Orienting new systems
=====================

Similar to 'locating' new systems, :mod:`sympy.vector` also allows for
initialization of new ``CoordSysCartesian`` instances that are oriented
initialization of new ``CartesianCoordinateSystem`` instances that are oriented
in user-defined ways with respect to existing systems.

Suppose you have a coordinate system :math:`A`.

>>> from sympy.vector import CoordSysCartesian
>>> A = CoordSysCartesian('A')
>>> from sympy.vector import CartesianCoordinateSystem
>>> A = CartesianCoordinateSystem('A')

You want to initialize a new coordinate system :math:`B`, that is rotated with
respect to :math:`A`'s Z-axis by an angle :math:`\theta`.
Expand All @@ -66,8 +66,8 @@ The orientation is shown in the diagram below:

There are two ways to achieve this.

Using a method of CoordSysCartesian directly
--------------------------------------------
Using a method of CartesianCoordinateSystem directly
----------------------------------------------------

This is the easiest, cleanest, and hence the recommended way of doing
it.
Expand All @@ -77,7 +77,7 @@ it.
This initialzes :math:`B` with the required orientation information with
respect to :math:`A`.

``CoordSysCartesian`` provides the following direct orientation methods
``CartesianCoordinateSystem`` provides the following direct orientation methods
in its API-

1. ``orient_new_axis``
Expand All @@ -88,7 +88,7 @@ in its API-

4. ``orient_new_quaternion``

Please look at the ``CoordSysCartesian`` class API given in the docs
Please look at the ``CartesianCoordinateSystem`` class API given in the docs
of this module, to know their functionality and required arguments
in detail.

Expand Down Expand Up @@ -193,9 +193,9 @@ in different coordinate systems using the ``express`` function.

For purposes of this section, assume the following initializations-

>>> from sympy.vector import CoordSysCartesian, express
>>> from sympy.vector import CartesianCoordinateSystem, express
>>> from sympy.abc import a, b, c
>>> N = CoordSysCartesian('N')
>>> N = CartesianCoordinateSystem('N')
>>> M = N.orient_new_axis('M', a, N.k)

``Vector`` instances can be expressed in user defined systems using
Expand Down
8 changes: 4 additions & 4 deletions doc/src/modules/vector/examples.rst
Expand Up @@ -23,8 +23,8 @@ and basic operations on ``Vector``.

Define a coordinate system

>>> from sympy.vector import CoordSysCartesian
>>> Sys = CoordSysCartesian('Sys')
>>> from sympy.vector import CartesianCoordinateSystem
>>> Sys = CartesianCoordinateSystem('Sys')

Define point O to be Sys' origin. We can do this without
loss of generality
Expand Down Expand Up @@ -88,8 +88,8 @@ Solution

Start with a coordinate system

>>> from sympy.vector import CoordSysCartesian
>>> C = CoordSysCartesian('C')
>>> from sympy.vector import CartesianCoordinateSystem
>>> C = CartesianCoordinateSystem('C')

The scalar field :math:`f` and the measure numbers of the vector field
:math:`\vec v` are all functions of the coordinate variables of the
Expand Down
58 changes: 29 additions & 29 deletions doc/src/modules/vector/fields.rst
Expand Up @@ -8,16 +8,16 @@ Implementation in sympy.vector
Scalar and vector fields
------------------------

In :mod:`sympy.vector`, every ``CoordSysCartesian`` instance is assigned basis
In :mod:`sympy.vector`, every ``CartesianCoordinateSystem`` instance is assigned basis
vectors corresponding to the :math:`X`, :math:`Y` and
:math:`Z` axes. These can be accessed using the properties
named ``i``, ``j`` and ``k`` respectively. Hence, to define a vector
:math:`\mathbf{v}` of the form
:math:`3\mathbf{\hat{i}} + 4\mathbf{\hat{j}} + 5\mathbf{\hat{k}}` with
respect to a given frame :math:`\mathbf{R}`, you would do

>>> from sympy.vector import CoordSysCartesian
>>> R = CoordSysCartesian('R')
>>> from sympy.vector import CartesianCoordinateSystem
>>> R = CartesianCoordinateSystem('R')
>>> v = 3*R.i + 4*R.j + 5*R.k

Vector math and basic calculus operations with respect to vectors have
Expand All @@ -36,8 +36,8 @@ and ``R.z`` expressions respectively.
Therefore, to generate the expression for the aforementioned electric
potential field :math:`2{x}^{2}y`, you would have to do

>>> from sympy.vector import CoordSysCartesian
>>> R = CoordSysCartesian('R')
>>> from sympy.vector import CartesianCoordinateSystem
>>> R = CartesianCoordinateSystem('R')
>>> electric_potential = 2*R.x**2*R.y
>>> electric_potential
2*R.x**2*R.y
Expand All @@ -51,8 +51,8 @@ for any math/calculus functionality. Hence, to differentiate the above
electric potential with respect to :math:`x` (i.e. ``R.x``), you would
use the ``diff`` method.

>>> from sympy.vector import CoordSysCartesian
>>> R = CoordSysCartesian('R')
>>> from sympy.vector import CartesianCoordinateSystem
>>> R = CartesianCoordinateSystem('R')
>>> electric_potential = 2*R.x**2*R.y
>>> from sympy import diff
>>> diff(electric_potential, R.x)
Expand All @@ -66,8 +66,8 @@ constant.
Like scalar fields, vector fields that vary with position can also be
constructed using ``BaseScalar`` s in the measure-number expressions.

>>> from sympy.vector import CoordSysCartesian
>>> R = CoordSysCartesian('R')
>>> from sympy.vector import CartesianCoordinateSystem
>>> R = CartesianCoordinateSystem('R')
>>> v = R.x**2*R.i + 2*R.x*R.z*R.k

The Del operator
Expand All @@ -84,16 +84,16 @@ but a convenient mathematical notation to denote any one of the
aforementioned field operations.

In :mod:`sympy.vector`, :math:`\mathbf{\nabla}` has been implemented
as the ``delop`` property of the ``CoordSysCartesian`` class.
as the ``delop`` property of the ``CartesianCoordinateSystem`` class.
Hence, assuming ``C`` is a coordinate system, the
:math:`\mathbf{\nabla}` operator corresponding to the vector
differentials wrt ``C``'s coordinate variables and basis vectors
would be accessible as ``C.delop``.

Given below is an example of usage of the ``delop`` object.

>>> from sympy.vector import CoordSysCartesian
>>> C = CoordSysCartesian('C')
>>> from sympy.vector import CartesianCoordinateSystem
>>> C = CartesianCoordinateSystem('C')
>>> gradient_field = C.delop(C.x*C.y*C.z)
>>> gradient_field
(Derivative(C.x*C.y*C.z, C.x))*C.i + (Derivative(C.x*C.y*C.z, C.y))*C.j + (Derivative(C.x*C.y*C.z, C.z))*C.k
Expand Down Expand Up @@ -137,8 +137,8 @@ accomplished in two ways.

One, by using the ``delop`` property

>>> from sympy.vector import CoordSysCartesian
>>> C = CoordSysCartesian('C')
>>> from sympy.vector import CartesianCoordinateSystem
>>> C = CartesianCoordinateSystem('C')
>>> C.delop.cross(C.x*C.y*C.z*C.i).doit()
C.x*C.y*C.j + (-C.x*C.z)*C.k
>>> (C.delop ^ C.x*C.y*C.z*C.i).doit()
Expand Down Expand Up @@ -174,8 +174,8 @@ accomplished in two ways.

One, by using the ``delop`` property

>>> from sympy.vector import CoordSysCartesian
>>> C = CoordSysCartesian('C')
>>> from sympy.vector import CartesianCoordinateSystem
>>> C = CartesianCoordinateSystem('C')
>>> C.delop.dot(C.x*C.y*C.z*(C.i + C.j + C.k)).doit()
C.x*C.y + C.x*C.z + C.y*C.z
>>> (C.delop & C.x*C.y*C.z*(C.i + C.j + C.k)).doit()
Expand Down Expand Up @@ -207,8 +207,8 @@ accomplished in two ways.

One, by using the ``delop`` property

>>> from sympy.vector import CoordSysCartesian
>>> C = CoordSysCartesian('C')
>>> from sympy.vector import CartesianCoordinateSystem
>>> C = CartesianCoordinateSystem('C')
>>> C.delop.gradient(C.x*C.y*C.z).doit()
C.y*C.z*C.i + C.x*C.z*C.j + C.x*C.y*C.k
>>> C.delop(C.x*C.y*C.z).doit()
Expand All @@ -235,10 +235,10 @@ velocity :math:`v`. It is represented mathematically as:

Directional derivatives of vector and scalar fields can be computed in
:mod:`sympy.vector` using the ``delop`` property of
``CoordSysCartesian``.
``CartesianCoordinateSystem``.

>>> from sympy.vector import CoordSysCartesian
>>> C = CoordSysCartesian('C')
>>> from sympy.vector import CartesianCoordinateSystem
>>> C = CartesianCoordinateSystem('C')
>>> vel = C.i + C.j + C.k
>>> scalar_field = C.x*C.y*C.z
>>> vector_field = C.x*C.y*C.z*C.i
Expand All @@ -263,8 +263,8 @@ energy is conserved.
To check if a vector field is conservative in :mod:`sympy.vector`, the
``is_conservative`` function can be used.

>>> from sympy.vector import CoordSysCartesian, is_conservative
>>> R = CoordSysCartesian('R')
>>> from sympy.vector import CartesianCoordinateSystem, is_conservative
>>> R = CartesianCoordinateSystem('R')
>>> field = R.y*R.z*R.i + R.x*R.z*R.j + R.x*R.y*R.k
>>> is_conservative(field)
True
Expand All @@ -277,8 +277,8 @@ is zero at all points in space.
To check if a vector field is solenoidal in :mod:`sympy.vector`, the
``is_solenoidal`` function can be used.

>>> from sympy.vector import CoordSysCartesian, is_solenoidal
>>> R = CoordSysCartesian('R')
>>> from sympy.vector import CartesianCoordinateSystem, is_solenoidal
>>> R = CartesianCoordinateSystem('R')
>>> field = R.y*R.z*R.i + R.x*R.z*R.j + R.x*R.y*R.k
>>> is_solenoidal(field)
True
Expand All @@ -298,8 +298,8 @@ scalar potential field corresponding to a given conservative vector field in

Example of usage -

>>> from sympy.vector import CoordSysCartesian, scalar_potential
>>> R = CoordSysCartesian('R')
>>> from sympy.vector import CartesianCoordinateSystem, scalar_potential
>>> R = CartesianCoordinateSystem('R')
>>> conservative_field = 4*R.x*R.y*R.z*R.i + 2*R.x**2*R.z*R.j + 2*R.x**2*R.y*R.k
>>> scalar_potential(conservative_field, R)
2*R.x**2*R.y*R.z
Expand All @@ -315,9 +315,9 @@ function, since it depends only on the endpoints of the path.

This computation is performed as follows in :mod:`sympy.vector`.

>>> from sympy.vector import CoordSysCartesian, Point
>>> from sympy.vector import CartesianCoordinateSystem, Point
>>> from sympy.vector import scalar_potential_difference
>>> R = CoordSysCartesian('R')
>>> R = CartesianCoordinateSystem('R')
>>> P = R.origin.locate_new('P', 1*R.i + 2*R.j + 3*R.k)
>>> vectfield = 4*R.x*R.y*R.i + 2*R.x**2*R.j
>>> scalar_potential_difference(vectfield, R, R.origin, P)
Expand Down