Skip to content

Commit

Permalink
Merge branch 'main' into shipgen-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeBell committed Mar 5, 2025
2 parents f92334b + adb4ab8 commit 22876e9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import sys; sys.path.append('../..')\n",
"from Raytrace.TriangleMesh import Ray\n",
"from Raytrace.BVHMesh import BVHMesh\n",
"from Raytrace.SideScan import SideScan, ScanReading\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import sys; sys.path.append('../..')\n",
"from Raytrace.TriangleMesh import Ray\n",
"from Raytrace.BVHMesh import BVHMesh\n",
"from Raytrace.SideScan import SideScan, ScanReading\n",
Expand Down
9 changes: 5 additions & 4 deletions Raytrace/TriangleMesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def triangle_ray_intersection(triangle, ray:Ray, epsilon = 1e-10) -> float:
return -1
@staticmethod
def batch_triangle_ray_intersection(triangle_array, ray:Ray, epsilon = 1e-10) -> np.ndarray:
vecdot = lambda a, b : np.sum(a*b, axis=-1)
# Translated from https://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm#C++_implementation

triangle_array_comp = triangle_array.swapaxes(0, 1)
Expand All @@ -91,16 +92,16 @@ def batch_triangle_ray_intersection(triangle_array, ray:Ray, epsilon = 1e-10) ->
v2 = v2 - v0

ray_cross_e2 = np.cross(ray.direction, v2)
det = np.vecdot(v1, ray_cross_e2)
det = vecdot(v1, ray_cross_e2)
# if -epsilon < det < epsilon:
# return None # This ray is parallel to this triangle.
old_error_state = np.seterr(divide='ignore', invalid='ignore')
inv_det = 1.0 / det
s = ray.origin - v0
u = inv_det * np.vecdot(s, ray_cross_e2)
u = inv_det * vecdot(s, ray_cross_e2)

s_cross_e1 = np.cross(s, v1)
v = inv_det * np.vecdot(ray.direction, s_cross_e1)
v = inv_det * vecdot(ray.direction, s_cross_e1)

valid = u < -epsilon
np.logical_or(valid, 1 < u, out=valid)
Expand All @@ -111,7 +112,7 @@ def batch_triangle_ray_intersection(triangle_array, ray:Ray, epsilon = 1e-10) ->
t = np.empty(triangle_array.shape[0], dtype=np.float64)
t.fill(-1)

np.multiply(inv_det, np.vecdot(v2, s_cross_e1), out = t, where = valid)
np.multiply(inv_det, vecdot(v2, s_cross_e1), out = t, where = valid)

np.seterr(**old_error_state)
return t
Expand Down

0 comments on commit 22876e9

Please sign in to comment.