ddg.math.complex module

Utility functions for complex analysis of plane geometry. Uses and generates (numpy) complex numbers.

ddg.math.complex.complex_sample(size=None, seed=None)[source]

Get a sample of random complex numbers or numpy.ndarray.

Parameters:
sizearray_like of ints (default=None)

Shape of numpy.ndarray. If size=None then a single complex will be returned.

seedint (default=None)

Seed for obtaining a deterministic function.

Returns:
complex or numpy.ndarray of numpy.complex128

If size=None then complex will be returned, else numpy.ndarray of shape size.

Notes

Real and imaginary part are standard normally distributed

Examples

>>> import numpy as np
>>> from ddg.math.complex import complex_sample
>>> complex_sample(seed=15)
(-1.4308730228590871-0.9365477163197146j)
>>> complex_sample(1, 15)
array([-1.43087302-0.93654772j])
>>> complex_sample([2, 1], 15)
array([[-1.43087302+0.39393836j],
       [-0.93654772-0.52408663j]])
>>> type(complex_sample(1)[0])
<class 'numpy.complex128'>
>>> type(complex_sample())
<class 'complex'>
ddg.math.complex.to_array(z)[source]

Convert a complex number to a numpy.ndarray.

Parameters:
zcomplex
Returns:
numpy.ndarray of shape (2, input_shape)

An array with a shape of (2, input_shape), where input_shape is the shape of the input numpy array. If the input is complex, the shape is (2,).

Examples

>>> from ddg.math.complex import to_array, complex_sample
>>> to_array(complex_sample(seed=15))
array([-1.43087302, -0.93654772])
>>> to_array(complex_sample(1, 15))
array([[-1.43087302],
       [-0.93654772]])
ddg.math.complex.to_complex(x)[source]

Convert an array_like to a complex number.

Parameters:
xarray_like of length shape (2,)
Returns:
complex

Examples

>>> from ddg.math.complex import to_complex
>>> to_complex((1, 2))
(1+2j)
>>> to_complex(np.array([1, 0.5]))
(1+0.5j)
>>> to_complex((1, 2, 11, 2, 3, 4, 512, 1412))
(1+2j)
ddg.math.complex.homogeneous(z)[source]

Get complex number in homogeneous coordinates.

z is interpreted as the affine coordinate of an element in CP^1.

Parameters:
zcomplex
Returns:
numpy.ndarray of shape (2,)

Examples

>>> from ddg.math.complex import homogeneous, to_complex
>>> homogeneous(to_complex((1, 2)))
array([1.+2.j, 1.+0.j])
ddg.math.complex.scalar_product(z1, z2)[source]

Calculate scalar product of two complex numbers of corresponding elements in R^2.

Also accepts numpy.ndarray as input.

Parameters:
z1,z2complex or numpy.ndarray of dtype numpy.complex128
Returns:
float or numpy.ndarray

Returns a float if inputs are of type complex. Otherwise a numpy.ndarray is returned.

Examples

>>> from ddg.math.complex import scalar_product, complex_sample
>>> a = complex_sample((2, 2), 15)
>>> a
array([[-1.43087302+0.5256162j , -0.93654772+0.80732362j],
       [ 0.39393836-1.44353139j, -0.52408663+1.01706379j]])
>>> b = a[0]
>>> z = a[0][0]
>>> scalar_product(z, z)
2.323670001997294
>>> scalar_product(b, b)
array([2.32367   , 1.52889306])
>>> scalar_product(b, z)
array([2.32367   , 1.76442324])
>>> scalar_product(a, a)
array([[2.32367   , 1.52889306],
       [2.2389703 , 1.30908554]])
>>> scalar_product(a, b)
array([[ 2.32367   ,  1.52889306],
       [-1.32241926,  1.31193176]])
ddg.math.complex.determinant(z1, z2)[source]

For two complex numbers get determinant of matrix of corresponding elements in R^2.

Also accepts numpy.ndarray as input.

Parameters:
z1,z2complex or numpy.ndarray of dtype numpy.complex128
Returns:
float or numpy.ndarray

Returns a float if inputs are of type complex. Otherwise a numpy.ndarray is returned.

Examples

>>> from ddg.math.complex import determinant, complex_sample
>>> a = complex_sample((2, 2), 15)
>>> a
array([[-1.43087302+0.5256162j , -0.93654772+0.80732362j],
       [ 0.39393836-1.44353139j, -0.52408663+1.01706379j]])
>>> b = a[0]
>>> z = b[0]
>>> determinant(z, z)
0.0
>>> determinant(a, a)
array([[0., 0.],
       [0., 0.]])
>>> determinant(z, a)
array([[ 0.        , -0.66291294],
       [ 1.85844974, -1.17982071]])
ddg.math.complex.rel_angle(z1, z2)[source]

Get angle in [0,2*pi) between complex numbers z1,z2.

Parameters:
z1,z2complex
Returns:
float

Examples

>>> from ddg.math.complex import rel_angle, complex_sample
>>> z1 = complex_sample(seed=15)
>>> z2 = complex_sample(seed=16)
>>> rel_angle(z1, z2)
4.888818869307385
ddg.math.complex.cr(z1, z2, z3, z4)[source]

Compute complex cross ratio.

cr(z1,z2,z3,z4) = (z1 - z2)/(z2 - z3) * (z3 - z4)/(z4 - z1)

Parameters:
z1,z2,z3,z4complex
Returns:
complex

Examples

>>> from ddg.math.complex import cr, complex_sample
>>> Z = complex_sample(4, 15)
>>> Z
array([-1.43087302+0.5256162j , -0.93654772+0.80732362j,
        0.39393836-1.44353139j, -0.52408663+1.01706379j])
>>> cr(Z[0], Z[1], Z[2], Z[3])
(0.5474067528516228-0.08577542856779714j)
ddg.math.complex.fourth_point_from_cross_ratio(z, z1, z2, q)[source]

Get z12 such that cr(z, z1, z12, z2) = q

For a quadrilateral of the form

z2_____z12
 |     |
 |     |
 z_____z1

with given z,z1,z2 and q, compute z12 .

Parameters:
z,z1,z2,qcomplex
Returns:
complex

Examples

>>> from ddg.math.complex import fourth_point_from_cross_ratio, complex_sample
>>> Z = complex_sample(4, 15)
>>> Z
array([-1.43087302+0.5256162j , -0.93654772+0.80732362j,
        0.39393836-1.44353139j, -0.52408663+1.01706379j])
>>> q = complex(0.5474067528516228 - 0.08577542856779719j)
>>> fourth_point_from_cross_ratio(Z[0], Z[1], Z[2], q)
(-1.580286264659597+0.09784352065927185j)
ddg.math.complex.circumcenter(z1, z2, z3)[source]

Get center of circle through three complex numbers.

Parameters:
z1,z2,z3complex
Returns:
numpy.complex128

Examples

>>> from ddg.math.complex import circumcenter, complex_sample
>>> Z = complex_sample(3, 15)
>>> Z
array([-1.43087302-0.52408663j, -0.93654772+0.5256162j ,
        0.39393836+0.80732362j])
>>> circumcenter(Z[0], Z[1], Z[2])
(-0.013691724033015891-0.5502195548404201j)
ddg.math.complex.circumradius(z1, z2, z3)[source]

Get radius of circle through three complex numbers.

Parameters:
z1,z2,z3complex
Returns:
float

Examples

>>> from ddg.math.complex import circumradius, complex_sample
>>> Z = complex_sample(3, 15)
>>> Z
array([-1.43087302-0.52408663j, -0.93654772+0.5256162j ,
        0.39393836+0.80732362j])
>>> circumradius(Z[0], Z[1], Z[2])
1.4174222248902117
ddg.math.complex.intersect_diags(z1, z2, z3, z4)[source]

For a complex quadrilateral (z1,z2,z3,z4) get the intersection point of the diagonals.

The four complex points are given as an argument in positive cyclic order.

z4-----z3
 |\   /|
 |  x  |
 |/   \|
z1-----z2
Parameters:
z1,z2,z3,z4complex
Returns:
complex

Examples

>>> from ddg.math.complex import intersect_diags, complex_sample
>>> Z = complex_sample(4, 15)
>>> Z
array([-1.43087302+0.5256162j , -0.93654772+0.80732362j,
        0.39393836-1.44353139j, -0.52408663+1.01706379j])
>>> intersect_diags(Z[0], Z[1], Z[2], Z[3])
(-1.449982659344593+0.5462373465733343j)
ddg.math.complex.intersect_edges(z1, z2, z3, z4)[source]

For a complex quadrilateral (z1,z2,z3,z4) get the intersection of the two opposite edges (z1,z2) and (z3,z4).

Will return complex infinity if intersection does not exist.

z4-----z3--
 |     |    \
 |     |     x
 |     |    /
z1-----z2--
Parameters:
z1,z2,z3,z4complex
Returns:
complex

Examples

>>> from ddg.math.complex import intersect_edges, complex_sample
>>> Z = complex_sample(4, 15)
>>> Z
array([-1.43087302+0.5256162j , -0.93654772+0.80732362j,
        0.39393836-1.44353139j, -0.52408663+1.01706379j])
>>> intersect_edges(Z[0], Z[1], Z[2], Z[3])
(-0.5318751583626388+1.037939495771862j)
>>> z = Z[0]
>>> intersect_edges(z, z, z, z)
(inf+0j)