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 |
References
circumcenter(v1, v2, v3)
Circumcenter of the triangle formed by three points
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 |
closest_point_on_plane(P, orig, N)
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 |
orig
|
Vec
|
a point belonging to the plane |
required |
N
|
Vec
|
normal vector of the plane |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Vec |
Vec
|
P projected onto the plane |
closest_point_on_segment(P, A, B)
Computes the closest point from p on segment [A;B], and the feature of the segment on which it lies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
P
|
Vec
|
Query point |
required |
A
|
Vec
|
First segment extremity |
required |
B
|
Vec
|
Second segment extremity |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Vec |
the point Q on [A;B] that minimizes its distance with P. |
|
int |
the feature of the segment on which Q lies: 0 if Q is in the interior of the segment, 1 if Q is the extremity A, 2 if Q is the extremity B. |
closest_point_on_triangle(P, A, B, C)
Computes the closest point from point p to triangle ABC, and the feature of the triangle on which it lies. Uses the Voronoi region tests from Ericson, Real-Time Collision Detection, section 5.1.5.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
P
|
Vec
|
Query point |
required |
A,B,C
|
Vec
|
vertices of the triangle |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Vec |
the point Q in triangle ABC that minimizes its distance with P. |
|
int |
the feature of the triangle on which Q lies: 0 if Q is in the interior of the face, 1, 2 or 3 if Q is the vertex A, B or C respectively, 4, 5 or 6 if Q is in the interior of the edge AB, BC or CA respectively. |
cotan(A, B, C)
cotangent of the angle \(\hat{ABC}\)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
Vec
|
point A |
required |
B
|
Vec
|
point B |
required |
C
|
Vec
|
point C |
required |
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(A, B, C)
Computes a 3x3 determinant using the rule of Sarrus from three column vectors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
Vec
|
first column |
required |
B
|
Vec
|
second column |
required |
C
|
Vec
|
third column |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
the determinant of [A|B|C] |
distance(A, B)
Distance between A and B.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
Vec
|
first point |
required |
B
|
Vec
|
second point |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
distance |
distance2(A, B)
Squared euclidean distance between points A and B.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
Vec
|
first vector |
required |
B
|
Vec
|
second point |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
distance squared. |
distance_to_plane(P, orig, N)
Computes the distance of point P to the plane of normal N passing through point orig.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
P
|
Vec
|
query position to project |
required |
orig
|
Vec
|
a point belonging to the plane |
required |
N
|
Vec
|
normal vector of the plane. Does not need to be normalized. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the norm of N is smaller than 1e-10. |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
the euclidean distance from P to the plane. |
distance_to_segment(P, A, B)
Computes the distance of point P to the segment [A;B].
Alias for distance(P, closest_point_on_segment(P,A,B)[0])
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
P
|
Vec
|
Query point |
required |
A
|
Vec
|
First segment extremity |
required |
B
|
Vec
|
Second segment extremity |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
the euclidean distance from P to [A;B] |
distance_to_triangle(P, A, B, C)
Computes the distance of point P to the triangle ABC.
Alias for distance(P, closest_point_on_triangle(P,A,B,C)[0])
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
P
|
Vec
|
query point |
required |
A,B,C
|
Vec
|
vertices of the triangle. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
float: the euclidean distance from P to triangle ABC. |
face_basis(A, B, C)
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
|
Vec
|
three points forming a triangle. |
required |
Returns:
| Type | Description |
|---|---|
|
Vec,Vec,Vec: an orthonormal 3D basis of the face ABC |
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 |
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)
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 |
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 |