Space#

The module includes classes and routines for operations involving points, pointclouds and reference frames in Euclidean space.

class sigmaepsilon.mesh.space.CartesianFrame(axes: ndarray | None = None, *args, dim: int = 3, origo: ndarray | None = None, **kwargs)[source]#

A field-specific reference frame to be used in problems related to Euclidean geometry.

It builds on top of FrameLike from sigmaepsilon.math, but adds the contept of ‘origo’, and some other applications related to the field.

See also

FrameLike

Parameters:
  • axes (numpy.ndarray, Optional.) – 2d numpy array of floats specifying cartesian reference frames. Dafault is None.

  • dim (int, Optional) – Dimension of the mesh. Deafult is 3.

  • origo (numpy.ndarray, Optional.) – The origo of the mesh. Default is the zero vector.

Note

See the documentation of FrameLike for more control over object creation. However, if your problem not very extreme in some sense, you are probably good to goo only by following the examples.

Example

Define a standard Cartesian frame and rotate it around axis ‘Z’ with an amount of 180 degrees:

>>> from sigmaepsilon.mesh.space import CartesianFrame
>>> import numpy as np
>>> A = CartesianFrame(dim=3)
>>> B = A.orient_new('Space', [0, 0, np.pi], 'XYZ')

To create a third frame that rotates from B the way B rotates from A, we can do

>>> A = CartesianFrame(dim=3)
>>> C = A.orient_new('Space', [0, 0, 2*np.pi], 'XYZ')

or we can define it relative to B (this literally makes C to looke in B like B looks in A)

>>> C = CartesianFrame(B.axes, parent=B)

Then, the DCM from A to B , that is \(^{A}\mathbf{R}^{B}\) would be

>>> A_R_B = B.dcm(source=A)

or equivalently

>>> A_R_B = A.dcm(target=A)
copy(deep: bool = False, name: str | None = None) CartesianFrame[source]#

Returns a shallow or deep copy of this object, depending of the argument deepcopy (default is False).

Parameters:
  • deep (bool, Optional) – If True, a deep copy is returned. Default is False.

  • name (str, Optional) – The name of the copy. Default is None.

deepcopy(name: str | None = None) CartesianFrame[source]#

Returns a deep copy of the instance.

Parameters:

name (str, Optional) – The name of the copy. Default is None.

fork(*args, **kwargs) CartesianFrame[source]#

Alias for orient_new.

move(d: Vector | ndarray, frame: FrameLike | None = None) CartesianFrame[source]#

Moves the frame by shifting its origo.

Parameters:
  • d (VectorLike) – Vector or Array, the amount of the motion.

  • frame (FrameLike, Optional) – A frame in which the input is defined if it is not a Vector. Default is None, which assumes the root frame.

Returns:

The object the function is called on.

Return type:

CartesianFrame

Examples

>>> from sigmaepsilon.mesh.space import CartesianFrame
>>> import numpy as np
>>> A = CartesianFrame()
>>> v = Vector([1., 0., 0.], frame=A)
>>> B = A.fork('Space', [0, 0, 45*np.pi/180], 'XYZ').move(v)

Move the frame locally with the same amount

>>> B.move(v.array, frame=B)
relative_origo(target: FrameLike | None = None) ndarray[source]#

Returns the origo of the current frame in ambient space or with respect to another frame.

Parameters:

target (FrameLike, Optional) – A frame in which we want to get the origo of the current frame. A None value returns the origo of the current frame with respect to the root. Default is None.

Returns:

A vector defined in ambient space, or the specified frame.

Return type:

numpy.ndarray

Examples

Define a standard Cartesian frame and rotate it around axis ‘Z’ with an amount of 180 degrees:

>>> from sigmaepsilon.mesh.space import CartesianFrame
>>> import numpy as np
>>> A = CartesianFrame()
>>> B = A.orient_new('Space', [0, 0, 45*np.pi/180],  'XYZ')

To get the origin of frame B:

>>> B.relative_origo()
[0., 0., 0.]

Move frame B (the motion is defined locally) and print the new point of origin with respect to A:

>>> B.move(Vector([1, 0, 0], frame=B))
>>> B.relative_origo(A)
[0.7071, 0.7071, 0.]

Of course, the point of origin of a frame with respect to itself must be a zero vector:

>>> B.relative_origo(B)
[0., 0., 0.]

Providing with no arguments returns the distance of origin with respect to the root frame:

>>> B.relative_origo()  # same as B.relative_origo(B.root)
[0.7071, 0.7071, 0.]
rotate(*args, **kwargs) CartesianFrame[source]#

Alias for orient and orient_new, all extra arguments are forwarded.

New in version 0.0.4.

Parameters:

inplace (bool, Optional) – If True, transformation is carried out on the instance the function call is made upon, otherwise a new frame is returned. Default is True.

Returns:

An exisitng (if inplace is True) or a new ReferenceFrame object.

Return type:

ReferenceFrame

Example

Define a standard Cartesian frame and rotate it around axis ‘Z’ with 180 degrees:

>>> A = ReferenceFrame(dim=3)
>>> A.rotate('Space', [0, 0, np.pi], 'XYZ')
array([[-1.0000000e+00,  1.2246468e-16,  0.0000000e+00],
       [-1.2246468e-16, -1.0000000e+00,  0.0000000e+00],
       [ 0.0000000e+00,  0.0000000e+00,  1.0000000e+00]])

See also

orient(), orient_new()

class sigmaepsilon.mesh.space.Point(*args, frame: ReferenceFrame | ndarray | Iterable | None = None, id: int | None = None, gid: int | None = None, **kwargs)[source]#

Deprecated since version 2.3.0: Use PointCloud instead.

A class a to handle a single point in Euclidean space.

It inherits Vector, and extends its behaviour with default frame management for domain specific applications.

If data is provided on object creation, the class can infer an appropriate default frame, hence the specification of such can be omitted.

Parameters:

frame (Union[ReferenceFrame, numpy.ndarray, Iterable], Optional) – A suitable reference frame, or an iterable representing coordinate axes of one. Default is None.

Note

  1. This is class is superseded by PointCloud.

2) This class does not take the origo of the supporting reference frame into consideration when transforming coordinates between frames.

Examples

>>> from sigmaepsilon.mesh.space import Point
>>> p = Point([1., 1., 1.])
>>> type(p.frame)
sigmaepsilon.math.linalg.frame.CartesianFrame

If we want to handle more than one point:

>>> import math
>>> p = Point([[1., 0., 0.], [0., 1., 0.]])
>>> A = p.frame
>>> B = A.orient_new('Body', [0, 0, math.pi/2], 'XYZ')
>>> p.show(B)
array([[ 0.0, -1.0,  0.0],
       [ 1.0,  0.0,  0.0]])
class sigmaepsilon.mesh.space.PointCloud(*args, frame: CartesianFrame | FrameLike | None = None, inds: ndarray | None = None, **kwargs)[source]#

A numba-jittable class to support calculations related to points in Euclidean space.

Parameters:
  • frame (FrameLike or numpy.ndarray, Optional) – A numpy array representing coordinate axes of a reference frame. Default is None.

  • inds (numpy.ndarray, Optional) – An 1d integer array specifying point indices. Default is None.

Examples

Collect the points of a simple triangulation and get the center:

>>> from sigmaepsilon.mesh.space import PointCloud
>>> from sigmaepsilon.mesh.triang import triangulate
>>> coords, *_ = triangulate(size=(800, 600), shape=(10, 10))
>>> coords = PointCloud(coords)
>>> coords.center()
    array([400., 300.,   0.])

Centralize and get center again:

>>> coords.centralize()
>>> coords.center()
    array([0., 0., 0.])

Move the points in the global frame:

>>> coords.move(np.array([1., 0., 0.]))
>>> coords.center()
    array([1., 0., 0.])

Rotate the points with 90 degrees around global Z. Before we do so, let check the boundaries:

>>> coords.x().min(), coords.x().max()
(-400., 400.)
>>> coords.y().min(), coords.y().max()
(-300., 300.)

Now centralize wrt. the global frame, rotate and check the boundaries again:

>>> coords.rotate('Body', [0, 0, np.pi], 'XYZ')
>>> coords.center()
    [1., 0., 0.]
>>> coords.x().min(), coords.x().max()
(-300., 300.)
>>> coords.y().min(), coords.y().max()
(-400., 400.)

The object keeps track of indices after slicing, always referring to the top level array:

>>> coords[10:50][[1, 2, 10]].inds
array([11, 12, 20])

The instances are available in Numba-jitted functions, with the coordinates and indices available as ‘data’ and ‘inds’:

>>> from numba import jit
>>> @jit(nopython=True)
>>> def foo(arr): return arr.data, arr.inds
>>> c = np.array([[0, 0, 0], [0, 0, 1.], [0, 0, 0]])
>>> COORD = PointCloud(c, inds=np.array([0, 1, 2, 3]))
>>> foo(COORD)
bounds(target: FrameLike | None = None) ndarray[source]#

Returns the bounds of the pointcloud as a numpy array with a shape of (N, 2), where N is 2 for 2d problems and 3 for 3d ones.

center(target: FrameLike | None = None) ndarray[source]#

Returns the center of the points in a specified frame, or the root frame if there is no target provided.

Parameters:

target (ReferenceFrame, Optional) – A frame of reference. Default is None.

Returns:

A numpy array.

Return type:

numpy.ndarray

centralize(target: FrameLike | None = None, axes: Iterable | None = None) PointCloud[source]#

Centralizes the coordinates wrt. to a specified frame, or the root frame if there is no target provided.

Returns the object for continuation.

Parameters:
  • target (ReferenceFrame, Optional) – A frame of reference. Default is None.

  • axes (Iterable, Optional) – The axes on which centralization is to be performed. A None value means all axes. Default is None.

Returns:

The object the function is called on.

Return type:

PointCloud

closest(p: Point | Vector | ndarray, frame: FrameLike | None = None) Point[source]#

Returns the point being closest to p.

Parameters:
  • p (Vector or Array, Optional) – Vectors or coordinates of one or more points. If provided as an array, the frame argument can be used to specify the parent frame in which the coordinates are to be understood.

  • frame (ReferenceFrame, Optional) – A frame in which the input is defined if it is not a Vector. Default is None.

Return type:

~sigmaepsilon.mesh.space.point.Point

property frame: CartesianFrame | FrameLike#

Returns the frame the points are embedded in.

furthest(p: Point | Vector | ndarray, frame: FrameLike | None = None) Point[source]#

Returns the point being closest to p.

Parameters:
  • p (Vector or Array, Optional) – Vectors or coordinates of one or more points. If provided as an array, the frame argument can be used to specify the parent frame in which the coordinates are to be understood.

  • frame (ReferenceFrame, Optional) – A frame in which the input is defined if it is not a Vector. Default is None.

Return type:

~sigmaepsilon.mesh.space.point.Point

property id: ndarray#

Returns the indices of the points.

idsort() ndarray[source]#

Returns the indices that would sort the array according to their indices.

index_of_closest(p: Point | Vector | ndarray, frame: FrameLike | None = None) int[source]#

Returns the index of the point being closest to p.

Parameters:
  • p (Vector or Array, Optional) – Vectors or coordinates of one or more points. If provided as an array, the frame argument can be used to specify the parent frame in which the coordinates are to be understood.

  • frame (ReferenceFrame, Optional) – A frame in which the input is defined if it is not a Vector. Default is None.

Return type:

int

index_of_furthest(p: Point | Vector | ndarray, frame: FrameLike | None = None) int[source]#

Returns the index of the point being furthest from p.

Parameters:
  • p (Vector or Array, Optional) – Vectors or coordinates of one or more points. If provided as an array, the frame argument can be used to specify the parent frame in which the coordinates are to be understood.

  • frame (ReferenceFrame, Optional) – A frame in which the input is defined if it is not a Vector. Default is None.

Return type:

int

move(v: Point | Vector | ndarray, frame: FrameLike | None = None) PointCloud[source]#

Moves the points wrt. to a specified frame, or the root frame if there is no target provided. Returns the object for continuation.

Parameters:
  • v (Vector or Array, Optional) – An array of a vector. If provided as an array, the frame argument can be used to specify the parent frame in which the motion is tp be understood.

  • frame (ReferenceFrame, Optional) – A frame in which the input is defined if it is not a Vector. Default is None.

Returns:

The object the function is called on.

Return type:

PointCloud

Examples

Collect the points of a simple triangulation and get the center:

>>> from sigmaepsilon.mesh.tri import triangulate
>>> coords, *_ = triangulate(size=(800, 600), shape=(10, 10))
>>> coords = PointCloud(coords)
>>> coords.center()
    array([400., 300.,   0.])

Move the points and get the center again:

d = np.array([0., 1., 0.]) >>> coords.move(d).move(d) >>> coords.center() array([400., 302., 0.])

rotate(*args, **kwargs) PointCloud[source]#

Applies a transformation to the coordinates in-place. All arguments are passed to ReferenceFrame.orient_new, see its docs to know more.

Returns the object for continuation.

Parameters:

*args (tuple,) – The first positional argument can be a ReferenceFrame object. If it is not, all positional and keyword arguments are forwarded to ReferenceFrame.orient_new.

Returns:

The object the function is called on.

Return type:

PointCloud

Examples

To apply a 90 degree rotation about the Z axis:

>>> from sigmaepsilon.mesh.space import PointCloud
>>> from sigmaepsilon.mesh import triangulate
>>> coords, *_ = triangulate(size=(800, 600), shape=(10, 10))
>>> points = PointCloud(coords)
>>> points.rotate('Space', [0, 0, np.pi/2], 'XYZ')
show(target: FrameLike | None = None, *args, **kwargs) ndarray[source]#

Returns the coordinates of the points in a specified frame, or the root frame if there is no target provided.

Parameters:

target (ReferenceFrame, Optional) – A frame of reference. Default is None.

Notes

This function returns the coordinates of the points in a target frame, but does not make any changes to the points themselves. If you want to change the frame of the pointcloud, reset the frame of the object by setting the frame property.

See also

frame()

Returns:

The coordinates in the desired frame.

Return type:

numpy.ndarray

sort_indices() PointCloud[source]#

Sorts the points according to their indices and returns the object.

x(target: FrameLike | None = None) ndarray[source]#

Returns the x coordinates.

y(target: FrameLike | None = None) ndarray[source]#

Returns the y coordinates.

z(target: FrameLike | None = None) ndarray[source]#

Returns the z coordinates.

sigmaepsilon.mesh.space.StandardFrame#

alias of CartesianFrame