Search code examples
vectorgraphics3dgeometry

How to check if the connection of two points in the surface of two spheres doesn't collide with any of the spheres


I want to make a connection between the points at the surface of two separate spheres, with the condition that it cannot go through neither of the two spheres. (this connection is simply a line, it could be considered as a vector "starting and ending" at those two points).

For this, I have two spheres with their respective local coordinate systems (k being a surface normal to that sphere, and i and j perpendicular vectors to it) an axis and center points in a global coordinate system, from which I have calculated the connection points in the global coordinate system (let's call said connection points p1 and p2)

While getting said points and the vector between them was trivial, I am not sure how to check whether the resulting vector collides with any of those spheres.

I know that I should form and use a change of basis matrix, but I don't know how to exactly apply it for this.

Any help is appreciated.

connections!


Solution

  • Checking if the line goes below the tangent surface of each sphere is sufficient. This is done by checking if the dot product of the vector with the normal is negative. Given the notation provided, this would be:

    v = p2 - p1
    k1.dot(v) < 0 || k2.dot(v) > 0