RE: [Algorithms] Bounding sphere of spheres
Brought to you by:
vexxed72
From: Peter P. <pr...@ph...> - 2001-08-29 19:28:33
|
>>> Direction = Delta*1/Distance; // normed Directionvector from P2 to P1 >>> Because of this divide this algorithm will actually fail if the two spheres happen >>> to have the same center. This is a case that needs to be tested seperatelly. >> actually, this case is already handled (if the two spheres have the same >> center, the larger one will contain the other, and the divide won't get >> executed) >That's not true. Here is an excerpt of the code fragment to which I was >replying: Ooops, you're right, i was showing intermediate results for clearness and thus broke the code :) here's the corrected code: Delta = P1-P2; Distance = Delta.Length(); // where Length calculates the Length of a vector if(r1>=r2+Distance) // sphere 2 contained in sphere 1 { P = P1; r = r1; } else if(r2>=r1+Distance) // sphere 1 contained in sphere 2 { P = P2; r = r2; } else { Direction = Delta*1/Distance; // normed Directionvector from P2 to P1 P = (P1+Direction*r1 + P2-Direction*r2)/2; // Position of Bounding Sphere r = (r1+r2+Distance)/2; } |