-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
71 lines (67 loc) · 2.05 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
// CircleRet.cpp : 定義主控台應用程式的進入點。
//
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h> // for atof
#include <math.h>
#include "GraphicsGems.h"
boolean Check_Intersect(Box2 *R, Point2 *C, double Rad)
{
double Rad2;
Rad2 = Rad * Rad;
/* Translate coordinates, placing C at the origin. */
R->max.x -= C->x; R->max.y -= C->y;
R->min.x -= C->x; R->min.y -= C->y;
if (R->max.x < 0) /* R to left of circle center */
if (R->max.y < 0) /* R in lower left corner */
return ((R->max.x * R->max.x + R->max.y * R->max.y) < Rad2);
else if (R->min.y > 0) /* R in upper left corner */
return ((R->max.x * R->max.x + R->min.y * R->min.y) < Rad2);
else /* R due West of circle */
return(ABS(R->max.x) < Rad);
else if (R->min.x > 0) /* R to right of circle center */
if (R->max.y < 0) /* R in lower right corner */
return ((R->min.x * R->min.x + R->max.y * R->max.y) < Rad2);
else if (R->min.y > 0) /* R in upper right corner */
return ((R->min.x * R->min.x + R->min.y * R->min.y) < Rad2);
else /* R due East of circle */
return (R->min.x < Rad);
else /* R on circle vertical centerline */
if (R->max.y < 0) /* R due South of circle */
return (ABS(R->max.y) < Rad);
else if (R->min.y > 0) /* R due North of circle */
return (R->min.y < Rad);
else /* R contains circle centerpoint */
return(TRUE);
}
int main(int argc, char *argv[])
{
if (argc != 8) {
printf("%d", 0);
exit(1);
}
else {
//double x1, y1, x2, y2, cx, cy, rr;
double x1 = atof(argv[1]);
double y1 = atof(argv[2]);
double x2 = atof(argv[3]);
double y2 = atof(argv[4]);
double cx = atof(argv[5]);
double cy = atof(argv[6]);
double rr = atof(argv[7]);
//printf("%lf %lf %lf %lf %lf %lf %lf\n", x1, y1, x2, y2, cx, cy, rr);
Point2 min_Rect, max_Rect, Circ;
Box2 Rect;
min_Rect.x = x1;
min_Rect.y = y1;
max_Rect.x = x2;
max_Rect.y = y2;
Circ.x = cx;
Circ.y = cy;
Rect.min = min_Rect;
Rect.max = max_Rect;
boolean react = Check_Intersect(&Rect, &Circ, rr);
printf("out %d", react);
}
exit(0);
}