Point where a line segment intersects a sphere?
Posted: Fri Nov 27, 2020 10:07 am
Can anyone please help me out with this please?
This sort of math is beyond my understanding unfortunately so any help would be appreciated thanks.
Code: Select all
(Global) Var Vector Intersect1, Intersect2;
Function Int FindSphereIntersection(Vector LineStart, Vector LineEnd, Vector SphereOrigin, Float SphereRadius)
{
//Math, math, math.
//Math, math, math.
//Math, math, math.
if (Line from LineStart to LineEnd doesnt intersect with Sphere)
Return 0;
if (Line from LineStart to LineEnd intersects with Sphere once)
{
Intersect1 = Intersect point;
Return 1;
}
if (Line from LineStart to LineEnd intersects with Sphere twice)
{
Intersect1 = Intersect point;
Intersect1 = Other intersect point;
Return 2;
}
}