Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. void inter(float r1, float x1, float y1, float r2, float x2, float y2) {
  7. fstream wyjscie;
  8. wyjscie.open("wynik1.txt", ios::out);
  9.  
  10. if (!((r1 - r2)*(r1 - r2) <= (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2) &&
  11. (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2) <= (r1 + r2)*(r1 + r2))) {
  12. wyjscie << "brak wspolnych punktow";
  13. wyjscie.close();
  14. }
  15. else {
  16. float x3, x4, y3, y4, d, h, a, x, y;
  17. d = sqrt(pow((x2 - x1), 2) + pow((y2 - y1), 2));
  18. a = (r1*r1 - r2*r2 + d*d) / (2 * d);
  19. h = sqrt(r1*r1 - a*a);
  20. x = x1 + a*(x2 - x1) / d;
  21. y = y1 + a*(y2 - y1) / d;
  22. x3 = x + h*(y2 - y1) / d;
  23. y3 = y - h*(x2 - x1) / d;
  24. x4 = x - h*(y2 - y1) / d;
  25. y4 = y + h*(x2 - x1) / d;
  26. if (x3 == x4 && y3 == y4) {
  27. wyjscie << x3 << y3;
  28. }
  29. else {
  30. wyjscie << x3 << " " << y3 << endl;
  31. wyjscie << x4 << " " << y4;
  32. }
  33. wyjscie.close();
  34. }
  35. }
  36. int main() {
  37. float r1, x1, y1, r2, x2, y2;
  38. fstream wejscie;
  39. wejscie.open("dane1.txt", ios::in);
  40.  
  41. while (wejscie.good()) {
  42. wejscie >> r1 >> x1 >> y1;
  43. wejscie >> r2 >> x2 >> y2;
  44. }
  45. wejscie.close();
  46.  
  47. inter(r1, x1, y1, r2, x2, y2);
  48.  
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement