Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct Point
- {
- float x;
- float y;
- };
- struct Circle
- {
- Point I; //center
- float r; //radius
- };
- void InputPoint(Point &d)
- {
- cout << "\nCoordinates";
- cout << "\nx=";
- cin >> d.x;
- cout << "\ny=";
- cin >> d.y;
- }
- void InputCircle(Circle &C)
- {
- cout << "\nInput center ";
- InputPoint(C.I);
- cout << "\nInput radius ";
- cin >> C.r;
- }
- float Distance(Point I1, Point I2)
- {
- return sqrt(float(pow(I1.x - I2.x, 2) + pow(I1.y - I2.y, 2)));
- }
- bool Checkcollision(Circle C1, Circle C2)
- {
- float dis;
- dis = Distance(C1.I, C2.I);
- float R = C1.r + C2.r;
- if (dis <= R)
- return true;
- return false;
- }
- void main()
- {
- Circle C1, C2;
- InputCircle(C1);
- InputCircle(C2);
- if (Checkcollision(C1, C2)) cout << "collision" << endl;
- else
- cout << "dont collision" << endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement