For direct access use https://forums.oldunreal.com
It's been quite a while since oldunreal had an overhaul, but we are moving to another server which require some updates and changes. The biggest change is the migration of our old reliable YaBB forum to phpBB. This system expects you to login with your username and old password known from YaBB.
If you experience any problems there is also the usual "password forgotten" function. Don't forget to clear your browser cache!
If you have any further concerns feel free to contact me: Smirftsch@oldunreal.com

Point where a line segment intersects a sphere?

The section related to UnrealScript and modding. This board is for coders to discuss and exchange experiences or ask questions.<br />
Post Reply
User avatar
ExpEM
OldUnreal Member
Posts: 58
Joined: Sun Jan 20, 2013 4:10 am

Point where a line segment intersects a sphere?

Post by ExpEM »

Can anyone please help me out with this please?
[code C++]
(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;
}
}
[/code]
This sort of math is beyond my understanding unfortunately so any help would be appreciated thanks.
Finaly signed up, been a fan for years...
User avatar
Bleeder91[NL]
OldUnreal Member
Posts: 1058
Joined: Sun Oct 04, 2009 7:22 pm

Re: Point where a line segment intersects a sphere?

Post by Bleeder91[NL] »

I'm too tired to code it now but this might help:
https://www.scratchapixel.com/lessons/3 ... tersection
Image
User avatar
.:..:
OldUnreal Member
Posts: 1530
Joined: Tue Aug 16, 2005 4:35 am

Re: Point where a line segment intersects a sphere?

Post by .:..: »

I've used this code for 2D sphere ray to sphere collision check, pretty sure it works just like that in 3D coordinates too:

Code: Select all

simulated function TraceActor( TDActor A, TR_TraceInfo T )
{
      local float aa,b,c,radii;
      local vector Dir;

      Dir = T.Start - A.Location2D;
      radii = A.CollisionSize.X + T.Extent.X;

      // Simple circle overlap check.
      c = (Dir Dot Dir) - Square(radii);
      if( c= 0 && c 
To help understand the values:
T.Start = trace start.
A.Location2D = sphere location.
A.CollisionSize.X = sphere radius.
T.Extent.X = ray trace sphere radius.
T.Dir = End-Start direction of raytrace.
T.SetTraceHit(,,);

As said it was originally only used for 2D traces, but it should work in 3D too.
1823223D2A33224B0 wrote:...and now im stuck trying to fix everything you broke for the next 227 release xD :P
(ಠ_ಠ)
User avatar
ExpEM
OldUnreal Member
Posts: 58
Joined: Sun Jan 20, 2013 4:10 am

Re: Point where a line segment intersects a sphere?

Post by ExpEM »

Thank you both for your help!

I have a solution here: https://ut99.org/viewtopic.php?f=15&t=1 ... 22#p124822
Finaly signed up, been a fan for years...
Post Reply
  • Similar Topics
    Replies
    Views
    Last post

Return to “UScript Board”