心得
怎么感觉计算几何一直都在整理最基础的板子
Point板子
来自jiangly代码
包含Point的+-*,点积dot,叉积cross
#include <bits/stdc++.h>
using i64 = long long;
using T = long long;
struct Point {
T x;
T y;
Point(T x = 0, T y = 0) : x(x), y(y) {}
Point &operator+=(const Point &p) {
x += p.x, y += p.y;
return *this;
}
Point &operator-=(const Point &p) {
x -= p.x, y -= p.y;
return *this;
}
Point &operator*=(const T &v) {
x *= v, y *= v;
return *this;
}
friend Point operator-(const Point &p) {
return Point(-p.x, -p.y);
}
friend Point operator+(Point lhs, const Point &rhs) {
return lhs += rhs;
}
friend Point operator-(Point lhs, const Point &rhs) {
return lhs -= rhs;
}
friend Point operator*(Point lhs, const T &rhs) {
return lhs *= rhs;
}
};
T dot(const Point &a, const Point &b) {
return a.x * b.x + a.y * b.y;
}
T cross(const Point &a, const Point &b) {
return a.x * b.y - a.y * b.x;
}
圆的交面积
先判断圆心d和r1、r2的距离,确定外离、内含、相交
外离交面积为0,内含交面积为小面积,
相交时,面积为两个小扇形面积减r1r1r2r2围成的四边形面积,
而扇形面积=弧度*r*r,扇形角用余弦定理acos确认的角大小,
四边形面积可以用1/2sinA*bc,这里因为已知三边长,用的海伦公式
typedef double db;
struct cir{
db x,y,r;
void read(){
scanf("%lf%lf%lf",&x,&y,&r);
}
}e[N];
db sq(db x){return x*x;}
db cal(cir a,cir b){
db sql=sq(a.x-b.x)+sq(a.y-b.y);
if(sql>=sq(a.r+b.r))return 0;
if(sql<=sq(a.r-b.r)){
if(a.r<b.r)return pi*a.r*a.r;
else return pi*b.r*b.r;
}
db l=sqrt(sql),sqa=sq(a.r),sqb=sq(b.r);
db p=(l+a.r+b.r)/2.0;
db v=2.0*sqrt(p*(p-l)*(p-a.r)*(p-b.r));
return acos((sqa+sql-sqb)/(2.0*a.r*l))*sqa+acos((sqb+sql-sqa)/(2.0*b.r*l))*sqb-v;
}
文章介绍了计算几何中基础的Point结构体,包括点的加减乘运算以及点积和叉积的计算方法。接着讨论了圆的交面积问题,涉及外离、内含和相交三种情况,给出了利用余弦定理和海伦公式计算相交圆交集面积的方法。
999

被折叠的 条评论
为什么被折叠?



