Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cmath>
- using namespace std;
- void inter(float r1, float x1, float y1, float r2, float x2, float y2) {
- fstream wyjscie;
- wyjscie.open("wynik1.txt", ios::out);
- if (!((r1 - r2)*(r1 - r2) <= (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2) &&
- (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2) <= (r1 + r2)*(r1 + r2))) {
- wyjscie << "brak wspolnych punktow";
- wyjscie.close();
- }
- else {
- float x3, x4, y3, y4, d, h, a, x, y;
- d = sqrt(pow((x2 - x1), 2) + pow((y2 - y1), 2));
- a = (r1*r1 - r2*r2 + d*d) / (2 * d);
- h = sqrt(r1*r1 - a*a);
- x = x1 + a*(x2 - x1) / d;
- y = y1 + a*(y2 - y1) / d;
- x3 = x + h*(y2 - y1) / d;
- y3 = y - h*(x2 - x1) / d;
- x4 = x - h*(y2 - y1) / d;
- y4 = y + h*(x2 - x1) / d;
- if (x3 == x4 && y3 == y4) {
- wyjscie << x3 << y3;
- }
- else {
- wyjscie << x3 << " " << y3 << endl;
- wyjscie << x4 << " " << y4;
- }
- wyjscie.close();
- }
- }
- int main() {
- float r1, x1, y1, r2, x2, y2;
- fstream wejscie;
- wejscie.open("dane1.txt", ios::in);
- while (wejscie.good()) {
- wejscie >> r1 >> x1 >> y1;
- wejscie >> r2 >> x2 >> y2;
- }
- wejscie.close();
- inter(r1, x1, y1, r2, x2, y2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement