math module
This module provide basic linear algebra classes.
Classes:
|
A class to represent a 3D vector. |
|
A class to represent a 3D axial vector. |
|
A class to represent a 2D vector. |
|
A class to represent a 2D axial vector. |
|
A class to represent a 3x3 matrix. |
|
A class to represent a 2x2 matrix. |
- class apsg.math.Vector3(*args)
Bases:
Vector
A class to represent a 3D vector.
There are different way to create
Vector3
object:without arguments create default
Vector3
(1, 0, 0)with single argument v, where
v could be Vector3-like object
v could be string ‘x’, ‘y’ or ‘z’ - principal axes of coordinate system
v could be tuple of (x, y, z) - vector components
with 2 arguments plunge direction and plunge
with 3 numerical arguments defining vector components
- Parameters
azi (float) – plunge direction of linear feature in degrees
inc (float) – plunge of linear feature in degrees
Example
>>> vec() >>> vec(1,2,-1) >>> vec('y') >>> vec(120, 30) >>> v = vec(1, -2, 1)
- property z
Return z-component of the vector
- normalized()
Returns normalized (unit length) vector
- uv()
Returns normalized (unit length) vector
- lower()
Change vector direction to point towards positive Z direction
- is_upper()
Return True if vector points towards negative Z direction
- property geo
Return tuple of plunge direction and signed plunge
- classmethod unit_x()
Create unit length vector in x-direction
- classmethod unit_y()
Create unit length vector in y-direction
- classmethod unit_z()
Create unit length vector in z-direction
- classmethod random()
Create random 3D vector
- transform(F, **kwargs)
Return affine transformation of vector u by matrix F.
- Parameters
F – transformation matrix
- Keyword Arguments
norm – normalize transformed vectors. [True or False] Default False
- Returns
vector representation of affine transformation (dot product) of self by F
Example
# Reflexion of y axis. >>> F = [[1, 0, 0], [0, -1, 0], [0, 0, 1]] >>> u = Vector3([1, 1, 1]) >>> u.transform(F) Vector3(1, -1, 1)
- class apsg.math.Axial3(*args)
Bases:
Vector3
A class to represent a 3D axial vector.
Note: the angle between axial data cannot be more than 90°
- class apsg.math.Vector2(*args)
Bases:
Vector
A class to represent a 2D vector.
There are different way to create
Vector2
object:without arguments create default
Vector2
(0, 0, 1)with single argument v, where
v could be Vector2-like object
v could be string ‘x’ or ‘y’ - principal axes of coordinate system
v could be tuple of (x, y) - vector components
v could be float - unit vector with given angle to ‘x’ axis
with 2 numerical arguments defining vector components
- Parameters
ang (float) – angle between ‘x’ axis and vector in degrees
Example
>>> vec2() >>> vec2(1, -1) >>> vec2('y') >>> vec2(50) >>> v = vec2(1, -2)
- normalized()
Returns normalized (unit length) vector
- uv()
Returns normalized (unit length) vector
- property direction
Returns direction of the vector in degrees
- classmethod random()
Random 2D vector
- classmethod unit_x()
Create unit length vector in x-direction
- classmethod unit_y()
Create unit length vector in y-direction
- transform(*args, **kwargs)
Return affine transformation of vector u by matrix F.
- Parameters
F – transformation matrix
- Keyword Arguments
norm – normalize transformed vectors. [True or False] Default False
- Returns
vector representation of affine transformation (dot product) of self by F
Example
# Reflexion of y axis. >>> F = [[1, 0], [0, -1]] >>> u = vec2([1, 1]) >>> u.transform(F) Vector2(1, -1)
- class apsg.math.Axial2(*args)
Bases:
Vector2
A class to represent a 2D axial vector.
Note: the angle between axial data cannot be more than 90°
- class apsg.math.Matrix3(*args)
Bases:
Matrix
A class to represent a 3x3 matrix.
There are different way to create
Matrix3
object:without arguments create default identity
Matrix3
with single argument of Matrix3-like object
- Parameters
v – 2-dimensional array-like object
Example
>>> Matrix3() Matrix3 [[1 0 0] [0 1 0] [0 0 1]] >>> A = Matrix3([[2, 1, 0], [0, 0.5, 0], [0, -0.5, 1]])
- classmethod from_comp(xx=1, xy=0, xz=0, yx=0, yy=1, yz=0, zx=0, zy=0, zz=1)
Return
Matrix3
defined by individual components. Default is identity tensor.- Keyword Arguments
xx (float) – tensor component M_xx
xy (float) – tensor component M_xy
xz (float) – tensor component M_xz
yx (float) – tensor component M_yx
yy (float) – tensor component M_yy
yz (float) – tensor component M_yz
zx (float) – tensor component M_zx
zy (float) – tensor component M_zy
zz (float) – tensor component M_zz
Example
>>> F = Matrix3.from_comp(xy=1, zy=-0.5) >>> F [[ 1. 1. 0. ] [ 0. 1. 0. ] [ 0. -0.5 1. ]]
- property xz
Return xz-element of the matrix
- property yz
Return yz-element of the matrix
- property zx
Return zx-element of the matrix
- property zy
Return zy-element of the matrix
- property zz
Return zz-element of the matrix
- property E3
Third eigenvalue
- property V3
Third eigenvector
- eigenvectors()
Return tuple of principal eigenvectors as
Vector3
objects.
- scaled_eigenvectors()
Return tuple of principal eigenvectors as
Vector3
objects with magnitudes of eigenvalues
- class apsg.math.Matrix2(*args)
Bases:
Matrix
A class to represent a 2x2 matrix.
There are different way to create
Matrix2
object:without arguments create default identity
Matrix2
with single argument of Matrix2-like object
- Parameters
v – 2-dimensional array-like object
Example
>>> Matrix2() Matrix2 [[1 0] [0 1]] >>> A = Matrix2([[2, 1],[0, 0.5]])
- classmethod from_comp(xx=1, xy=0, yx=0, yy=1)
Return
Matrix2
defined by individual components. Default is identity tensor.- Keyword Arguments
xx (float) – tensor component M_xx
xy (float) – tensor component M_xy
yx (float) – tensor component M_yx
yy (float) – tensor component M_yy
Example
>>> F = Matrix2.from_comp(xy=2) >>> F [[1. 2.] [0. 1.]]
- eigenvectors()
Return tuple of principal eigenvectors as
Vector3
objects.
- scaled_eigenvectors()
Return tuple of principal eigenvectors as
Vector3
objects with magnitudes of eigenvalues