-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
76 lines (53 loc) · 1.36 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <stdio.h>
#include <time.h>
#define USE_MATH_DEFINES
#include <math.h>
#include <float.h>
int main()
{
float x1, y1, x2 , y2;
float R1, R2;
float l;
FILE * f = NULL;
f=fopen("twoc.in","r");
fscanf(f,"%f %f %f %f ",&x1, &y1, &x2, &y2);
fscanf(f,"%f %f ",&R1, &R2);
fclose(f);
f=fopen("twoc.out", "w");
l = (pow((x2 - x1),2) + pow((y2 - y1),2)); // distance between centers
//fprintf(f, "%0.3lf ", l);
//fprintf(f, "%0.3lf ", R1 + R2);
if (l > pow((R1 + R2),2))
{
fprintf(f, "Too far") ;
} ;
if ((l < pow((R1 - R2),2)) && (R1 > R2) )
{
fprintf(f, "2 inside 1") ;
} ;
if ((l < pow((R1 - R2),2)) && (R1 < R2) )
{
fprintf(f, "1 inside 2") ;
} ;
//if(fabs(l-pow((R1 + R2),2) <= DBL_EPSILON * fmax(fabs(l),fabs(pow((R1 + R2),2)))))
if (l == pow((R1 + R2),2))
{
fprintf(f, "Tangent: outside") ;
} ;
//if(fabs(l-pow((R1 - R2),2) <= DBL_EPSILON * fmax(fabs(l),fabs(pow((R1 - R2),2)))))
if ((l == pow((R1 - R2),2)) && (R1 > R2))
{
fprintf(f, "Tangent: 2 in 1") ;
} ;
//if(fabs(l-pow((-R1 + R2),2) <= DBL_EPSILON * fmax(fabs(l),fabs(pow((-R1 + R2),2)))))
if (l == pow((R2 - R1),2) && (R1 < R2))
{
fprintf(f, "Tangent: 1 in 2") ;
}
if ((l > pow((R1 - R2),2)) && (l < pow((R1 + R2),2)))
{
fprintf(f, "Intersect") ;
} ;
fclose(f);
return 0;
}