|
03-05-2014
|
4
|
|
299,792,458 m/s
Join Date: Mar 2012
Location: Lebanon
Posts: 3,581
|
Here's a small C++ code I've forked off, it's just hit detection for circles, though you get the concept hopefully.
PHP Code:
#include <iostream> #include <cmath>
using namespace std;
int main() { // x1 and y1 are the coordinated of the first circle, and r1 is it's ray. (2 * r1 is the diameter) double x1, y1, r1, x2, y2, r2, _unusedvar;
cout << "Insert the coordinates and the ray of the first circle seperated by spaces. (x y ray)" << endl;
cin >> x1 >> y1 >> r1;
cout << "Insert the coordinates and the ray of the second circle seperated by spaces. (x y ray)" << endl;
cin >> x2 >> y2 >> r2;
if (sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2)) < r1 + r2) { // The mathematical process, sqrt() means square root and pow(number, power) is the number to the power of cout << "Yes, the circles do collide." << endl; } else cout << "These circles do not collide" << endl;
cin >> _unusedvar; // Just so the program won't quit.
return 0; }
|
|
|
|