Guest User

Untitled

a guest
Sep 23rd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main(){
  6. int x, y, x1, y1, x2, y2 , R1, R2;
  7. cout << "enter the x coordinate of the first
  8. circle: ";
  9. cin >> x1;
  10. cout << "enter the y coordinate of the first
  11. circle: ";
  12. cin >> y1;
  13. cout << "enter the radius of the first circle: ";
  14. cin >> R1;
  15. cout << "enter the x coordinate of the second
  16. circle: ";
  17. cin >> x2;
  18. cout << "enter the y coordinate of the second
  19. circle: ";
  20. cin >> y2;
  21. cout << "enter the radius of the second circle: ";
  22. cin >> R2;
  23.  
  24.  
  25.  
  26. double x2c = x2 - x1;
  27. double y2c = y2 - y1;
  28. double c = ((R2 * R2) - (R1 * R1) - (x2c * x2c) -
  29. (y2c * y2c)) / 2 * x2c;
  30. double A = ((y2c * y2c) / (x2c * x2c)) + 1;
  31. double C = (c * c) - (R1 * R1);
  32. double B = 2 * C * (y2c / x2c);
  33. double d = sqrt(((x1 - x2) * (x1 - x2)) + ((y1 -
  34. y2) * (y1 - y2)));
  35. double D = B * B - 4 * A * C;
  36.  
  37. if (d < R1 + R2){
  38. cout << "Circles Intersect" <<endl;
  39. float yi = ((-B + sqrt(D)) / 2 * A);
  40. float xi = ((C + (B + sqrt(D)) / 2 *A) * y2c) /
  41. x2c;
  42. cout << "x and y coordinates of first point of
  43. intersection intersection" << " " << xi << " " <<
  44. yi << endl;
  45.  
  46. float xj = (-B - sqrt(D) /2 * A);
  47. float yj = ((C +(B - sqrt(D)) / 2 * A) * y2c) /
  48. x2c;
  49. cout << "x and y coordinates of first point of
  50. intersection intersection" << " " << xj << " " <<
  51. yj << endl;
  52. }
  53. else if (d == 0){
  54. cout << "circles are touching";
  55. float xi = ((C + (B + sqrt(D)) / 2 * A) * y2c) /
  56. x2c;
  57. float yi = (-B + sqrt(D)) / 2 * A;
  58. cout << "x and y cordinates of touching point are
  59. :" << " " << "(" << xi << "," << " " << yi << ")"
  60. << endl;
  61. }
  62. else if (R2 > (R1 * d) && (R1 * d) < abs(R1 - R2))
  63. {
  64. cout << "1st circle is inside the second";
  65. }
  66. else if(R1 > (R2 * d) && (R2 * d) < abs(R1 - R2)){
  67. cout << "Second circle is inside the first";
  68. }
  69. else if (d > (R1 + R2)){
  70. cout << "circles do not intersect";
  71. }
  72.  
  73.  
  74. return 0;
  75. }
Add Comment
Please, Sign In to add comment