Intersection between a line and a sphere

前端 未结 8 2196
无人及你
无人及你 2021-02-09 05:51

I\'m trying to find the point of intersection between a sphere and a line but honestly, I don\'t have any idea of how to do so. Could anyone help me on this one ?

8条回答
  •  灰色年华
    2021-02-09 06:32

    I don't have the reputation to comment on Ashavsky's solution, but the check at the end needed a bit more tweaking.

    if (D < 0)
        return new Point3D[0];
    else if ((t1 > 1 || t1 < 0) && (t2 > 1 || t2 < 0))
        return new Point3D[0];
    else if (!(t1 > 1 || t1 < 0) && (t2 > 1 || t2 < 0))
        return new [] { solution1 };
    else if ((t1 > 1 || t1 < 0) && !(t2 > 1 || t2 < 0))
        return new [] { solution2 };
    else if (D == 0)
        return new [] { solution1 };
    else
        return new [] { solution1, solution2 };
    

提交回复
热议问题