0

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!

Lightsong
  • 312
  • 2
  • 8
  • see [ray-and-ellipsoid-intersection-accuracy-improvement](https://stackoverflow.com/questions/25470493/ray-and-ellipsoid-intersection-accuracy-improvement) – Spektre Oct 07 '22 at 06:12

1 Answers1

3

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
  • Oh, I see, thank you! I still wonder, how would a change of basis take part in this? Is there an alternative way of checking it? – Lightsong Oct 07 '22 at 13:19
  • @Lightsong Doing a change of basis is possible but it adds a lot of useless operations. If you pack `i1, j1, k1` and ``i2, j2, k2`` into two matrices `B1` and `B2`, this check would be `(B1.inverse() * v).z < 0 || (B2.inverse() * v).z > 0`. As you can see, you need to calculate an inverse (or a transpose if the basis is orthonormal), and extract only 1 component. The solution I provided is a simplification of this calculation where only the useful part are kept. – Gilles-Philippe Paillé Oct 07 '22 at 17:15