norm()
计算向量的模长
db det(const pt &a, const pt &b)
计算两个向量的叉积
db dot(const pt &a, const pt &b)
计算两个向量的点积
db dist(const pt &a, const pt &b)
计算两个点的距离
pt rotate_point(const pt &p, db A)
将向量 op
逆时针旋转 A
(弧度)
#include <bits/stdc++.h>
#define nex(i) ((i+1)%n)
#define bef(i) ((i-1+n)%n)
#define INF 1000000000
using namespace std;
typedef double db;
const db eps = 1e-8;
const db pi = acos(-1.0);
inline db sqr(db x) {
return x * x;
}
int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
int cmp(db x){
return fabs(x) < eps ? 0 : (x > 0 ? 1 : -1);
}
namespace Point {
struct pt {
db x, y;
pt() {}
pt(db a, db b) : x(a), y(b) {}
void input() {
scanf("%lf%lf", &x, &y);
}
friend pt operator + (const pt &a, const pt &b) {
return pt(a.x + b.x, a.y + b.y);
}
friend pt operator - (const pt &a, const pt &b) {
return pt(a.x - b.x, a.y - b.y);
}
friend bool operator == (const pt &a, const pt &b) {
return !cmp(a.x - b.x) && !cmp(a.y - b.y);
}
friend pt operator * (const pt &a, const db &b) {
return pt(a.x * b, a.y * b);
}
friend pt operator * (const db &a, const pt &b) {
return pt(a * b.x, a * b.y);
}
friend pt operator / (const pt &a, const db &b) {
return pt(a.x / b, a.y / b);
}
friend bool operator < (const pt &a, const pt &b) {
return cmp(a.x - b.x) < 0 || (cmp(a.x - b.x) == 0 && cmp(a.y - b.y) < 0);
}
double norm() {
return sqrt(sqr(x) + sqr(y));
}
};
db det(const pt &a, const pt &b) {
return a.x * b.y - a.y * b.x;
}
db dot(const pt &a, const pt &b) {
return a.x * b.x + a.y * b.y;
}
db dist(const pt &a, const pt &b) {
return (a - b).norm();
}
pt rotate_point(const pt &p, db A) {
db tx = p.x, ty = p.y;
return pt(tx * cos(A) - ty * sin(A), tx * sin(A) + ty * cos(A));
}
}
using namespace Point;