向量

1
2
3
4
5
6
7
8
9
10
11
12
struct Vector
{
double x, y;
Vector() {}
Vector(double a, double b) { x = a; y = b; }
Vector operator-(Vector a) { return Vector(x - a.x, y - a.y); }
Vector(Vector b, Vector a) { x = a.x - b.x; y = a.y - b.y; }
Vector operator+(Vector a) { return Vector(x + a.x, y + a.y); }
double Dot(Vector a) { return x * a.x + y * a.y; }
double Cross(Vector a) { return x * a.y - y * a.x; }
double Length() { return sqrt(x*x + y * y); }
};

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
struct circle
{
Vector pt;
double r;
circle() {}
circle(double x, double y, double z) { pt = Vector(x, y); r = z; }
circle(int i) { scanf("%lf%lf%lf", &pt.x, &pt.y, &r); }
inline double Area() {//面积
return PI * r*r;
}
inline bool Intersect(circle C) {//相交
double len = (C.pt - pt).Length();
return Compare(len, (C.r + r)) < 0 && Compare(len, fabs(C.r - r)) > 0;
}
inline bool Inscribe(circle C) {//内切
return Compare((C.pt - pt).Length(), fabs(C.r - r)) == 0;
}
inline bool External_Cutting(circle C) {//外切
return Compare((C.pt - pt).Length(), fabs(C.r + r)) == 0;
}
inline double Perimeter() { return PI * 2 * r; }//周长
};