0

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;
3
Contributors
2
Replies
3
Views
10 Years
Discussion Span
Last Post by iamthwee
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.