Geometry#

For the full technical reference see geometry.

Import#

>>> # Exact import
>>> from wulfric.geometry import volume
>>> # Recommended import
>>> from wulfric import volume

Volume#

Volume can be computed from a several types of input data:

  • Cell

\(3\times3\) array, rows are the cell vectors, columns are the \(xyz\) coordinates.

>>> cell = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
>>> volume(cell)
1.0
  • Three vectors

>>> a = [1, 0, 0]
>>> b = [0, 1, 0]
>>> c = [0, 0, 1]
>>> volume(a, b, c)
1.0
  • Six cell parameters

>>> a = 1
>>> b = 1
>>> c = 1
>>> alpha = 90
>>> beta = 90
>>> gamma = 90
>>> volume(a, b, c, alpha, beta, gamma)
1.0

Angle#

Computes the smallest angle between two vectors.

>>> from wulfric import angle
>>> a = [1, 0, 0]
>>> b = [0, 1, 0]
>>> # In degrees by default
>>> angle(a, b)
90.0
>>> # In radians
>>> round(angle(a, b, radians=True), 4)
1.5708
>>> # For the zero vector the angle is not defined
>>> angle(a, [0, 0, 0])
Traceback (most recent call last):
...
ValueError: Angle is ill defined (zero vector).

Coordinates#

Computes relative coordinates of a vector with respect to some basis. Basis is defined by three vectors, which are passed to the function in a form of a \(3\times3\) array. Rows of the cell are the basis vectors, columns are the \(xyz\) coordinates.

>>> from wulfric import absolute_to_relative
>>> basis = [[2, 0, 0], [0, 4, 0], [0, 0, 8]]
>>> vector = [1, 1, 1]
>>> absolute_to_relative(vector, basis)
array([0.5  , 0.25 , 0.125])

Parallelepiped#

Check if the parallelepiped can be formed from six parameters. \(a\), \(b\), \(c\) are the lengths of the three vectors forming the parallelepiped. \(\alpha\), \(\beta\), \(\gamma\) are the angles between the vectors.

>>> from wulfric import parallelepiped_check
>>> a = 1
>>> b = 1
>>> c = 1
>>> alpha = 90
>>> beta = 90
>>> gamma = 90
>>> parallelepiped_check(a, b, c, alpha, beta, gamma)
True
>>> parallelepiped_check(a, b, c, alpha, beta, 181)
False