Geometry Utilities
angle_2vec2D(V1, V2)
angle_2vec3D(V1, V2)
angle_3pts(A, B, C)
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 |
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)
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)
quad_area(A, B, C, D)
sign(x)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
float
|
input number |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
x/|x| and 0 for x=0 |
sign0(x)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
float
|
input number |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
the sign of x |