Given two spheres, I need to determine if a collision has occurred between them. I need to input the radii and the centers from the screen and use a double-valued function (outside of the main program) for the distance formula.

What I have so far is

#include <iostream>

using namespace std;

//Function prototype
double DistanceBetween( double x1, double y1, double z1, double x2, double y2, double z2 );

void main()
{
   //center point and radius of first sphere
   double x1, y1, z1, r1;

   cout << "Please enter the data for the first sphere:" << endl;

   cout << "x: ";
   cin >> x1;

   cout << "y: ";
   cin >> y1;
   
   cout << "z: ";
   cin >> z1;
   
   cout << "r: ";
   cin >> r1;

The worse thing I can do for you is to write you the whole thing, but I can help:

1) Check the distance between two given centers.
2) Sum up the radiuses of the first and second sphere if the sum is bigger or equal to distance (see point 1) then they collide with each other.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.