Jump to content

  • Log In with Google      Sign In   
  • Create Account

Closest point on a line to a sphere...


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 Lohrno   Members   -  Reputation: 222

Like
Likes
Like

Posted 10 February 2004 - 06:02 AM

... [Edited by - Lohrno on December 3, 2004 10:42:14 AM]

Sponsor:

#2 0BZEN   Crossbones+   -  Reputation: 2016

Like
Likes
Like

Posted 10 February 2004 - 06:10 AM

line or segment?

closest point to a sphere is closest point to centre of sphere, BTW.

for a segment [E0, E1], and a spehre [C, r]

Vector D = C - E0;
Vector E = E1 - E0;

float e2 = E.Dot(E);
float ed = E.Dot(D);

float t = ed / e2;

if (t < 0.0f) t = 0.0f; else if (t > 1.0f) t = 1.0f;

Vector ClosestPoint = E0 + E * t;



#3 Nathaniel Hammen   Members   -  Reputation: 136

Like
Likes
Like

Posted 10 February 2004 - 06:11 AM

It''s exactly the same as finding the closest point on a line to a point. Just use the center as that point. The only difference is that you have to figure out if the line intersects the sphere. Then what you do depends on why you want to know the closest point.

If you don''t know how to find the closest point on a line to another point (I''ll call this point "P" from now on), I''ll explain it to you. First take a point on the line. It doesn''t matter what point, so long as it is on the line. Let''s call this point the orgin of the line. Now take a vector representing the line. This vector should be normalized. Let''s call this vector the slope of the line. Get a vector by subtracting P-Orgin. Take the dot product of this vector and the slope. Multiply this answer by the slope. Add this to the orgin. This point is the closest point.

If the closest point lies inside the sphere, the line intersects the sphere.

--------------------------------------
I am the master of stories.....
If only I could just write them down...

#4 Nathaniel Hammen   Members   -  Reputation: 136

Like
Likes
Like

Posted 10 February 2004 - 06:13 AM

Grrr. oliii beat me to it.

--------------------------------------
I am the master of stories.....
If only I could just write them down...

[edited by - Nathaniel Hammen on February 10, 2004 1:13:59 PM]

#5 tj963   Members   -  Reputation: 234

Like
Likes
Like

Posted 10 February 2004 - 06:17 AM

Easy. Assuming you line is in the form r = s + dt, where r,s,d are vectors and t is a real number, and a sphere with center c, the point is d*(d.(c-s)), where . is the dot prodect and * is a scalar multiply.

tj963

#6 Lohrno   Members   -  Reputation: 222

Like
Likes
Like

Posted 10 February 2004 - 07:03 AM

Cool! Thank guys!

-=Lohrno

#7 0BZEN   Crossbones+   -  Reputation: 2016

Like
Likes
Like

Posted 10 February 2004 - 09:03 AM

you use that, and check if the closest point is in the sphere, if so, intersection

#8 Lohrno   Members   -  Reputation: 222

Like
Likes
Like

Posted 10 February 2004 - 10:18 AM

Well thats cool too, but actually I'm looking at using it to do obstacle avoidance. (Is the sphere in my path?) Almost the same thing really...

-=Lohrno

[edited by - Lohrno on February 10, 2004 5:19:10 PM]




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS