pyblenderSDIC.meshes.IntersectPoints#
- class IntersectPoints(barycentric_coordinates: ndarray, triangle_indices: ndarray)[source]#
Bases:
object
A class to represent the intersection points of rays with a 3D mesh.
This class stores the barycentric coordinates and triangle indices of the intersection points. The barycentric coordinates are used to locate the position of the intersection within a triangle, and the triangle indices represent the specific triangle in the mesh that was intersected by a ray.
For a triangle with vertices A, B, and C, the barycentric coordinates (u, v) are defined as follows:
\[P = (1 - u - v) A + u B + v C\]Where P is the intersection point, and u and v are the barycentric coordinates between 0 and 1. Their sum is always less than or equal to 1. The barycentric coordinates
Note
If no intersection occurs, the barycentric coordinates are set to NaN and the triangle index is set to -1.
Warning
The input arrays are wrapped with numpy.asarray(), meaning that the data is stored as a dynamic array that can be modified at any time. Therefore, users should be aware that the arrays can be changed after the object is created.
- Parameters:
barycentric_coordinates (numpy.ndarray) – A (N+1)D array of shape (…, 2), where each entry represents the barycentric coordinates (u, v) of an intersection point within the corresponding triangle. If no intersection occurs, the coordinates are NaN.
triangle_indices (numpy.ndarray) – A ND array of shape (…,), where each entry represents the index of the triangle that was intersected. If no intersection occurs, the index is -1.
- property barycentric_coordinates: ndarray#
Gets the barycentric coordinates of the intersections.
The barycentric coordinates are represented as a 2D array of shape (…, 2), where each entry corresponds to the barycentric coordinates (u, v) of an intersection point within the corresponding triangle. The last dimension must be of size 2.
For a triangle with vertices A, B, and C, the barycentric coordinates (u, v) are defined as follows:
\[P = (1 - u - v) A + u B + v C\]Note
An alias for the barycentric coordinates is
uv
.- Returns:
A 2D array of shape (…, 2) representing the barycentric coordinates of the intersections.
- Return type:
numpy.ndarray
- filter_valid() IntersectPoints [source]#
Filters out invalid intersections (where the triangle index is -1 or barycentric coordinates are NaN).
This method modifies the shape of the arrays, changing them from the original (…, 2) and (…,) to (L’, 2), where L’ is the number of valid intersections.
- Returns:
A new IntersectPoints object with only the valid intersections.
- Return type:
- property id: ndarray#
Alias for the triangle indices.
- property internal_bypass: bool#
Get and set the internal bypass mode status. When enabled, internal checks are skipped.
This is useful for testing purposes, but should not be used in production code.
- Parameters:
value (bool) – If True, internal checks are bypassed. If False, internal checks are performed.
- Raises:
TypeError – If the value is not a boolean.
- property triangle_indices: ndarray#
Gets the triangle indices of the intersections.
Note
An alias for the triangle indices is
id
.- Returns:
A 1D array representing the triangle indices of the intersections.
- Return type:
numpy.ndarray
- property uv: ndarray#
Alias for the barycentric coordinates.
- valid_mask() ndarray [source]#
Returns a boolean mask indicating the validity of the barycentric coordinates.
The mask is True if the barycentric coordinates (u, v) are no NaN values. The shape of the mask will be the same as the first dimensions of the barycentric coordinates array.
- Returns:
A boolean array of shape (…,) indicating the validity of the barycentric coordinates.
- Return type:
numpy.ndarray