Krishnan
Krishnan

Reputation: 385

Sphere - Sphere Intersection : Distance Vector

Is there a way to find out the distance of intersection between 2 spheres ? I understand when two spheres intersect the circle of intersection is formed . But what i'm trying to figure ouut is by how much i will need to push circle 1 outside so that they dont intersect and are at a point where they are just touching each other . The only data i have are the centres of the spheres and their respective radii.

Thanks

Upvotes: 0

Views: 2029

Answers (3)

Phil H
Phil H

Reputation: 20131

Define two spheres with centres at position vectors a and b (i.e. a = axi + ayj + azk).

Define a vector c from centre of sphere A to centre of sphere B:

c = b - a

Its length is |c| = |b - a|
        = sqrt( [bx - ax]2 + [by - ay]2 + [bz - az]2 )

As Mahesh stated, the distance between the two spheres is:

|d| = |c| - rA - rB

So the vector d from the furthest point of sphere A to the furthest point of B will be either pointing along c (when the spheres are not yet intersecting) or in the opposite direction (when the sphere are intersecting).

To move one sphere so they don't intersect, you need to move it by d. Since this is along c, we can just multiply c by a factor to get the components of d:

f = ( |d| / |c| )
d = f * c

For example, in the x direction:

dx = f * cx

So I would say try this:

  • Compute the components of the displacement c from the position vectors of A and B.
  • Compute the length of c from its components
  • Compute the length of d from the length of c and the radii
  • Compute the factor f between c and d
  • Compute the components of d by scaling the components of c by the factor f.

You can test whether the spheres intersect by testing the sign on f: if it is negative then the spheres intersect. You can then either move A or B by d, or both by some portion of d so that they no longer intersect.

Upvotes: 2

Mahesh
Mahesh

Reputation: 34625

( radius1 + radius2 ) - ( Current distance between the two centers ) is the amount of distance to be moved by either of a sphere to exactly touch each other. ( Assuming spheres are currently intersecting )

Upvotes: 1

templatetypedef
templatetypedef

Reputation: 372724

If you know that the two spheres overlap, then you could compute the distance between their centers. You could then add together the two spheres' radii to get the minimum distances that the spheres must be from one another such that they touch only at a point. The difference between the two (sum of the radii minus the distance between the centers) should be the amount the spheres need to move apart from one another so that they touch only at a point.

Upvotes: 0

Related Questions