Message Boards Message Boards

Find coordinates of an intersecting Line and Surface in 3D?


I am trying to find the coordinates of an arbitrary line (denoted by two points) when it intersects a few arbitrary shapes, and return the coordinates associated with the first surface encountered. The problem I am having is that the parametric based method appears to be inconsistent. Sometimes it finds the right answer, but other times it does not, even when I know the points of the line are on opposite sides of the surface.

In the code, "shapeEq" is the equation for the surface of an arbitrary geometry in 3D, and "inOutDeterminer" is a binary switch that returns a 1 when the coordinates are outside the geometry and a 0 when they are inside the geometry. The inconsistency issues persist when inOutDeterminer gives different binary values for the two line points.

The fact that I am having issues occasionally makes me suspect that Mathematica is having trouble finding the appropriate values for "t". Is this correct?

I have a vested interest in minimizing the changes to the program. Suggestions that salvage most of the pre-existing code are especially preferred.


POSTED BY: Matthew Boraas
10 months ago

How about this simple example:

shapeEq = x^2 + y^2 + z^2 - 1;
p = {0, 0, 0};
q = {1, 1, 1};
NSolve[{{x, y, z} == t*p + (1 - t) q, shapeEq == 0, 0 < t < 1},
 {t, x, y, z}]
POSTED BY: Gianluca Gorni
10 months ago

Group Abstract Group Abstract