Skip to content

Geometry Utilities

angle_2vec2D(V1, V2)

Angle between two 2D vectors

Parameters:

Name Type Description Default
V1 Vec

first vector

required
V2 Vec

second vector

required

Returns:

Name Type Description
float float

the angle

angle_2vec3D(V1, V2)

Angle between two 3D vectors

Parameters:

Name Type Description Default
V1 Vec

first vector

required
V2 Vec

second vector

required

Returns:

Name Type Description
float float

the angle

angle_3pts(A, B, C)

Angle ABC between three points

Parameters:

Name Type Description Default
A Vec

first point

required
B Vec

central point

required
C Vec

second point

required

Returns:

Name Type Description
float float

the angle

aspect_ratio(A, B, C)

Computes the aspect ratio of triangle ABC, defined as the ratio between the circumradius to twice the inradius. This ratio equals 1 for equilateral triangle and goes to zero as the triangle gets close to degenerate.

Parameters:

Name Type Description Default
A Vec

first point of the triangle

required
B Vec

second point of the triangle

required
C Vec

third point of the triangle

required

Returns:

Name Type Description
float float

the aspect ratio of triangle ABC

Note

https://stackoverflow.com/a/10290011

circumcenter(v1, v2, v3)

Circumcenter of the triangle formed by three points in the plane

Parameters:

Name Type Description Default
v1 Vec

first point

required
v2 Vec

second point

required
v3 Vec

third point

required
Warning

Circumcenter of triangle (v1,v2,v3) may not lay inside the triangle

Returns:

Name Type Description
Vec Vec

coordinates of the circumcenter

cotan(A, B, C)

cotangent of the angle \(\hat{ABC}\) Parameters: A (Vec): point A B (Vec): point B C (Vec): point C

Returns:

Name Type Description
float float

the cotangent

cross(A, B)

Cross product of vectors A and B

Parameters:

Name Type Description Default
A Vec

Size 3 vector

required
B Vec

Size 3 vector

required

Returns:

Name Type Description
Vec Vec

cross product AxB

det_2x2(A, B)

Computes a 2x2 determinant

Parameters:

Name Type Description Default
A Union[complex, ndarray]

first column vector. Can also be a complex number

required
B Union[complex, ndarray]

second column vector. Can also be a complex number

required

Returns:

Name Type Description
float float

the determinant

det_3x3(*args)

Computes a 3x3 using the rule of Sarrus

Parameters:

Name Type Description Default
args

Either a 3x3 numpy array representing a matrix, or 3 3x1 numpy array representing three column vectors

()

Returns:

Name Type Description
float float

the determinant

distance(A, B, which='l2')

Distance between A and B. Three distances are implemented, the Euclidean distance l2, the Manhattan l1 distance of the l-infinity distance:

l2: \(\sqrt{(B-A)^T(B-A)} = \sqrt{\sum_i (A_i - B_i)^2}\)

l1: \(\sum_i |A_i - B_i|\)

linf: \(\max_i |A_i - B_i|\)

Parameters:

Name Type Description Default
A Vec

first point

required
B Vec

second point

required
which str

which norm to compute. Choices are "l2", "l1" and "linf". Defaults to "l2".

'l2'

Returns:

Name Type Description
float float

distance

distance_to_segment2D(P, A, B)

Computes, in the plane, the distance of point P to the segment [A;B]

Parameters:

Name Type Description Default
P Vec

Query point in 2D

required
A Vec

First segment extremity

required
B Vec

Second segment extremity

required

Returns:

Name Type Description
float float

the euclidean distance from P to [A;B]

dot(A, B)

dot product \(A^TB\) between two vectors

Parameters:

Name Type Description Default
A ndarray

first vector

required
B ndarray

second vector

required

Returns:

Name Type Description
float float

dot product

face_basis(*f)

Orthonormal basis of face Given three points A,B,C, returns a basis such that the first vector is along direction AB and third vector is normal to the plane ABC

Parameters:

Name Type Description Default
A,B,C

three points (in a list or not)

required

Returns:

Type Description

Vec,Vec,Vec: an orthonormal 3D basis of the face

intersect_2lines2D(p1, d1, p2, d2)

Computes the intersection of two lines in the plane

Parameters:

Name Type Description Default
p1 Vec

point on the first line

required
d1 Vec

direction vector of the first line

required
p2 Vec

point on the second line

required
d2 Vec

direction vector of the second line

required

Returns:

Name Type Description
Vec Vec

the intersection point. None if lines are parallel

norm(x, which='l2')

Vector norm. Three norms are implemented, the Euclidean l2 norm, the l1 norm or the l-infinite norm:

l2: $ \sqrt{ \sum_i v[i]^2 } $

l1: $ \sum_i |v[i]| $

linf: $ \max_i |v[i]| $

Parameters:

Name Type Description Default
x ndarray

vector from which we compute the norm. Will be flattened if it has more than one dimension.

required
which str

which norm to compute. Choices are "l2", "l1" and "linf". Defaults to "l2".

'l2'

Returns:

Name Type Description
float float

the vector's norm

project_to_plane(P, N, orig)

Projects vector P onto the plane of normal N and passing through point 'orig'

Parameters:

Name Type Description Default
P Vec

query position to project

required
N Vec

normal vector of the plane

required

Returns:

Name Type Description
Vec Vec

P projected onto the plane

quad_area(A, B, C, D)

Area of the quad ABCD

Parameters:

Name Type Description Default
A Vec

first point

required
B Vec

second point

required
C Vec

third point

required
D Vec

fourth point

required

Returns:

Name Type Description
float float

area

sign(x)

\[\text{sign}(x)=\begin{cases} 0 \text{ if } x=0 \\ 1 \text{ if } x>0 \\ -1 \text{ if } x<0 \end{cases}\]

Parameters:

Name Type Description Default
x float

input number

required

Returns:

Name Type Description
float

x/|x| and 0 for x=0

sign0(x)

\[\text{sign0}(x)=\begin{cases} 1 \text{ if } x\geqslant0 \\ -1 \text{ if } x<0 \end{cases}\]

Parameters:

Name Type Description Default
x float

input number

required

Returns:

Name Type Description
float

the sign of x

signed_angle_2vec3D(V1, V2, N)

Signed angle between two vectors with orientation given by normal N

Parameters:

Name Type Description Default
V1 Vec

First vector

required
V2 Vec

Second vector

required
N Vec

reference normal direction

required

Returns:

Name Type Description
float float

the angle

signed_angle_3pts(A, B, C, N)

Signed angle between three points ABC with orientation givne by normal N

Parameters:

Name Type Description Default
A Vec

first point

required
B Vec

central point

required
C Vec

second point

required
N Vec

reference normal direction

required

Returns:

Name Type Description
float float

the angle

triangle_area(A, B, C)

Area of 3D triangle ABC

Parameters:

Name Type Description Default
A Vec

first point

required
B Vec

second point

required
C Vec

third point

required

Returns:

Name Type Description
float float

area

triangle_area_2D(A, B, C)

Area of 2D triangle ABC

Parameters:

Name Type Description Default
A Vec

first point

required
B Vec

second point

required
C Vec

third point

required

Returns:

Name Type Description
float float

area