Need some help on figuring out how to get the minDist variable to be used to give feedback on the distance from the first sphere at every check through the loop as well as at the final output.
Any ideas?
#include ..
#include ..
using namespace std;
int main(){
double s1x;
double s1y;
double s1z;
double s1rad;
double s2x;
double s2y;
double s2z;
double s2rad;
double dir;
double dx;
double dy;
double dz;
float count;
double distance;
double minDist;
cout << "sphere 1 starts at (100,50,75) and the radius is 10 ..n";
cout << "input location for sphere 2 below a range of 100 and enter the radius ..n" << "x? ";
Question
saiya
Need some help on figuring out how to get the minDist variable to be used to give feedback on the distance from the first sphere at every check through the loop as well as at the final output.
Any ideas?
#include ..
#include ..
using namespace std;
int main(){
double s1x;
double s1y;
double s1z;
double s1rad;
double s2x;
double s2y;
double s2z;
double s2rad;
double dir;
double dx;
double dy;
double dz;
float count;
double distance;
double minDist;
cout << "sphere 1 starts at (100,50,75) and the radius is 10 ..n";
cout << "input location for sphere 2 below a range of 100 and enter the radius ..n" << "x? ";
cin >> s2x;
cout << "y? ..n";
cin >> s2y;
cout << "z? ..n";
cin >> s2z;
cout << "radius? ..n";
cin >> s2rad;
cout << " ..n";
s1x = 100;
s1y = 50;
s1z = 75;
count = 0;
dx = 1.
09287;
dy = 0.
34751;
dz = 0.
6;
distance = sqrt(pow((s1x-s2x),2) + pow((s1y-s2y),2) + pow((s1z-s2z),2));
while ((count < 101) & (distance > s1rad + s2rad)){
count = count + 1;
s2x = s2x + dx;
s2y = s2y + dy;
s2z = s2z + dz;
cout << count << " : x " << s2x << " : y " << s2y << " : z " << s2z << endl;
if (count == 101){
cout << "They will never collide.
";
break;
}
if (distance == s1rad + s2rad){
cout << count << "it made contact at " << " : x " << s2x << " : y " << s2y << " : z " << s2z << endl;
break;
}
}
return 0;
Link to comment
Share on other sites
1 answer to this question
Recommended Posts