ddg.math.euclidean2d module

Planar Euclidean geometry utils.

ddg.math.euclidean2d.intersect_diags(x1, x2, x3, x4)[source]

For a 2D-quadrilateral (x1,x2,x3,x4) get the intersection point of the diagonals.

Please refer to ddg.math.complex.intersect_diags().

Parameters:
x1, x2, x3, x4numpy.ndarray of shape(2,)

Coordinates of the given quadrilateral.

Returns:
numpy.ndarray of shape(2,)

Coordinate of diagonal intersection

ddg.math.euclidean2d.intersect_edges(x1, x2, x3, x4)[source]

For a 2D-quadrilateral (x1, x2, x3, x4) get the intersection points of opposing edges.

Will return a array(NaN) if intersection does not exist.

    z2
   / \
  /   \
x4-----x3--
 |     |    \
 |     |     z1
 |     |    /
x1-----x2--
Parameters:
x1, x2, x3, x4numpy.ndarray of shape(2,)

Coordinates of the given quadrilateral.

Returns:
z1, z2numpy.ndarray of shape(2,)

Coordinates of diagonal intersections

ddg.math.euclidean2d.christoffel_dual_quad(x1, x2, x3, x4)[source]

A Christoffel dual quadrilateral of the given quadrilateral.

Corresponding edges and non-corresponding diagonals are parallel. This determines the dual quadrilateral up to scaling.

Parameters:
x1, x2, x3, x4numpy.ndarray of shape (2,)

Coordinates of the given quadrilateral.

Returns:
X1, X2, X3, X4numpy.ndarray of shape (2,)

Coordinates of the dual quadrilateral.

ddg.math.euclidean2d.corner_angle(x1, x2, x3)[source]

Angle of the corner (x1, x2, x3) at the vertex x2.

Computes the angle between vectors x1-x2 and x3-x2 in (0,2*pi].

Parameters:
x1, x2, x3numpy.ndarray of shape (2,)

Coordinate of points forming the vertex.

Returns:
float

Vertex angle.

Notes

Only reliable for convex quads.

ddg.math.euclidean2d.corner_angle_signed(x1, x2, x3)[source]

Signed angle of the corner (x1, x2, x3) at the vertex x2.

Computes the angle between vectors x1-x2 and x3-x2 in (-pi,pi].

Parameters:
x1, x2, x3numpy.ndarray of shape (2,)

Coordinate of points forming the vertex.

Returns:
float

Signed vertex angle.

ddg.math.euclidean2d.cyclic_order(points, center)[source]

Determines the cyclic order of the points beginning with the first with respect to the center.

Parameters:
pointslist of numpy.ndarray of shape (2,)

List of points.

centernumpy.ndarray of shape (2,)

Coordinate of the center.

Returns:
list of numpy.ndarray of shape (2,)

Cyclic order of the points with respect to the center.

Notes

Useful for angle calculation in non-embedded case.

ddg.math.euclidean2d.circumcenter(x1, x2, x3)[source]

Get center of circle through three points. This is a real variant of ddg.math.complex.circumcenter().

Parameters:
x1, x2, x3numpy.ndarray of shape (2,)

Coordinates of three points in a circle.

Returns:
numpy.ndarray of shape (2,)

Coordinate of center.

ddg.math.euclidean2d.circumradius(x1, x2, x3)[source]

Get radius of circle through three points. This is a real variant of ddg.math.complex.circumradius().

Parameters:
x1, x2, x3numpy.ndarray of shape (2,)

Coordinates of three points in a circle.

Returns:
float

Radius of circle.

ddg.math.euclidean2d.fourth_point_from_cross_ratio(x, x1, x2, q)[source]

Get fourth point on a quadrilateral from real cross-ratio. Applies the real variant of the complex cross ratio (See ddg.math.complex.fourth_point_from_cross_ratio()).

Parameters:
x, x1, x2numpy.ndarray of shape (2,)

Coordinates of points with order (x, x_1, …, x_2).

qcomplex

Cross ration of points.

Returns:
array_like

Corrdinate of fourth point.

Notes

Not exact with fractions right now.

ddg.math.euclidean2d.triangle_area(a, b, c)[source]

Compute area of triangle from side lengths.

Numerically stable version of Heron’s formula for the area of a triangle with side lengths a,b,c.

Parameters:
a, b, cfloat

Side lengths

Returns:
float

Area of triangle

ddg.math.euclidean2d.line2D(x1, x2)[source]

Gives the coefficients of the line equation describing the line through given points x1 and x2.

Parameters:
x1numpy.ndarray of shape (2,)

Point x1 given by its Euclidean 2D coordinates in 2-dim array.

x2numpy.ndarray of shape (2,)

Point x1 given by its Euclidean 2D coordinates in 2-dim array.

Returns:
[A, B, C]list of three floats

The coefficients of the line equation Ax + By = C describing the line through x1 and x2.

ddg.math.euclidean2d.intersection(l1, l2)[source]

Calculates the intersection of two lines that are given by coefficients of their line equations.

To do so the linear system Ax = b of the line equations is solved via numpy.linalg.solver.

Parameters:
l1, l2[float, float, float]

The two lines whose intersection shall be calculated. Both given by the coefficients of their line equations Ai*x + Bi*y = Ci where i=1,2.

Returns:
[x,y]np.array of two floats

The Euclidean 2D coordinates of the intersection point.

ddg.math.euclidean2d.intersectionCramer(l1, l2)[source]

Calculates the intersection of two lines that are given by coefficients of their line equations via Cramer’s rule.

Parameters:
l1, l2[float, float, float]

The two lines whose intersection shall be calculated. Both given by the coefficients of their line equations Ai*x + Bi*y = Ci where i=1,2.

Returns:
[x,y]array of two floats

The Euclidean 2D coordinates of the intersection point.

Raises:
ValueError

If the given lines do not intersect.

ddg.math.euclidean2d.intersection_in_barycentric_coords(x1, x2, y1, y2)[source]

Gives the intersection of two lines in barycentric coordinates relative to the given points which the lines run through.

Parameters:
x1, x2numpy.ndarray of shape (2,)

The two points the first line for intersecting runs through, given by their Euclidean 2D coordinates.

y1, y2numpy.ndarray of shape (2,)

The two points the second line for intersecting runs through, given by their Euclidean 2D coordinates.

Returns:
xnp.array[t1, s1, t2, s2] where ti, si float, i=1,2

The intersection of the lines given as the barycentric coordinates corresponding to solving the equation t1*x1 + s1*x2 = t2*y1 + s2*y2.

Notes

We establish a homogeneous system and solve it via numpy.