Testing whether a line segment intersects a sphere

后端 未结 4 391
感动是毒
感动是毒 2020-12-17 03:42

I am trying to determine whether a line segment (i.e. between two points) intersects a sphere. I am not interested in the position of the intersection, just whether or not t

4条回答
  •  情书的邮戳
    2020-12-17 04:17

    If you are only interested if knowing if it intersects or not then your basic algorithm will look like this...

    Consider you have the vector of your ray line, A -> B.

    You know that the shortest distance between this vector and the centre of the sphere occurs at the intersection of your ray vector and a vector which is at 90 degrees to this which passes through the centre of the sphere.

    You hence have two vectors, the equations of which fully completely defined. You can work out the intersection point of the vectors using linear algebra, and hence the length of the line (or more efficiently the square of the length of the line) and test if this is less than the radius (or the square of the radius) of your sphere.

提交回复
热议问题