Advertisement
huutho_96

Untitled

Nov 29th, 2015
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. struct Point
  4. {
  5. float x;
  6. float y;
  7. };
  8. struct Circle
  9. {
  10. Point I; //center
  11. float r; //radius
  12. };
  13. void InputPoint(Point &d)
  14. {
  15. cout << "\nCoordinates";
  16. cout << "\nx=";
  17. cin >> d.x;
  18. cout << "\ny=";
  19. cin >> d.y;
  20. }
  21. void InputCircle(Circle &C)
  22. {
  23. cout << "\nInput center ";
  24. InputPoint(C.I);
  25. cout << "\nInput radius ";
  26. cin >> C.r;
  27. }
  28. float Distance(Point I1, Point I2)
  29. {
  30. return sqrt(float(pow(I1.x - I2.x, 2) + pow(I1.y - I2.y, 2)));
  31. }
  32. bool Checkcollision(Circle C1, Circle C2)
  33. {
  34. float dis;
  35. dis = Distance(C1.I, C2.I);
  36. float R = C1.r + C2.r;
  37. if (dis <= R)
  38. return true;
  39. return false;
  40. }
  41. void main()
  42. {
  43. Circle C1, C2;
  44. InputCircle(C1);
  45. InputCircle(C2);
  46. if (Checkcollision(C1, C2)) cout << "collision" << endl;
  47. else
  48. cout << "dont collision" << endl;
  49. system("pause");
  50.  
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement