# Find intersection of a line with the boundary of 3D object (point set)

sjr51

Wed, 06/22/2022 - 04:41 am

Hello,

I have two 2D waves, each with 3 columns (x, y, z coords). The first wave is a point set that defines the boundary to an object (irregular but approximately spherical). The second is two points that lie inside the object. What I would like to do is find the distance from each of these two points to the boundary, along the line defined by those two points. I can't figure out how to find the intersect between this line and the boundary defined by the point set. I know how to do this in 2D, but I am confused about the best approach in 3D. Any help appreciated!

Is the problem spherical enough that you could refer to the line-intersecting-sphere problem (e.g., https://en.wikipedia.org/wiki/Line%E2%80%93sphere_intersection)? There are also code solutions out there for this kind of problem. If you care for the irregular shape of the object, then one way of approaching this could be to rotate the whole thing until the line equals one of the principal axes (e.g., the x axis). Then the problem becomes 1D. Find the angle between your 'line' vector and the y- and z- axis, then apply the rotation to each of your object points via a common rotation matrix. I guess this is the brute-force method, but Igor can do this for you via MatrixOp. Finally, just find the nearest points on the x-axis (while y,z close to zero).

June 22, 2022 at 07:04 am - Permalink

If you assume a sphere you can solve it mathematically, see Line–sphere intersection - Wikipedia

Otherwise, I think you need to define the boundary as a set of planes, each defined by 3 points, and check for the intersection of the line separately with each plane.

June 22, 2022 at 07:15 am - Permalink

Rotating your coordinate system so the line becomes a principal axis, as chozo suggested, sounds like a pretty good idea.

June 22, 2022 at 07:17 am - Permalink

Thank you both. I will try those approaches, starting with approximating to a sphere.

June 22, 2022 at 07:35 am - Permalink

Just a reminder that Igor's BoundingBall operation can help you convert from a triplet wave to a bounding sphere (center and radius solutions).

June 22, 2022 at 02:33 pm - Permalink