Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add specialized point in triangle test #9

Open
Huite opened this issue Jul 28, 2023 · 0 comments
Open

Add specialized point in triangle test #9

Huite opened this issue Jul 28, 2023 · 0 comments

Comments

@Huite
Copy link
Collaborator

Huite commented Jul 28, 2023

This might be worthwhile when dealing with a fully triangular grid.

Coming from xugrid:

@nb.njit(inline="always")
def point_in_triangle(p: Point, triangle: Triangle) -> bool:
    """Unrolled half-plane check."""
    a = cross_product(to_vector(triangle.a, triangle.b), to_vector(triangle.a, p)) > 0
    b = cross_product(to_vector(triangle.b, triangle.c), to_vector(triangle.b, p)) > 0
    c = cross_product(to_vector(triangle.c, triangle.a), to_vector(triangle.c, p)) > 0
    return (a == b) and (b == c)


@nb.njit(inline="always", parallel=True, cache=True)
def points_in_triangles(
    points: FloatArray,
    face_indices: IntArray,
    faces: IntArray,
    vertices: FloatArray,
):
    n_points = len(points)
    inside = np.empty(n_points, dtype=np.bool_)
    for i in nb.prange(n_points):
        face_index = face_indices[i]
        face = faces[face_index]
        triangle = as_triangle(vertices, face)
        point = as_point(points[i])
        inside[i] = point_in_triangle(point, triangle)
    return inside
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant