[持续缓慢更新中]计算几何 学习笔记

Part 0 基本部分

const double eps=1e-8;//精度问题
const double PI=acos(-1);//圆周率
I int Cmp(double x){return fabs(x)<eps?0:(x<0?-1:1);}//比较浮点数
I double sqr(double x){return x*x;}//平方

(有待补充)

Part 1 二维点线面、向量、圆基础

struct Point{
	double x,y;
	Point(double x=0,double y=0):x(x),y(y){}//新点
	I bool operator<(Point o){return Cmp(x-o.x)<0||(Cmp(x-o.x)==0&&Cmp(y-o.y)<0);}//点的比较
	I bool operator==(Point o){return Cmp(x-o.x)==0&&Cmp(y-o.y)==0;}//点重合判断
	I void input(){cin>>x>>y;}
	I void output(){printf("(%.5lf,%.5lf)",x,y);}
};

向量

struct Vector{
	double x,y;
	Vector(double x=0,double y=0):x(x),y(y){}
	I bool operator<(Vector o){return Cmp(x-o.x)<0||(Cmp(x-o.x)==0&&Cmp(y-o.y)<0);}
	I bool operator==(Vector o){return Cmp(x-o.x)==0&&Cmp(y-o.y)==0;}
	I Vector operator+(Vector o){return Vector(x+o.x,y+o.y);}//向量四则运算
	I Vector operator-(Vector o){return Vector(x-o.x,y-o.y);}
	I Vector operator*(Vector o){return Vector(x*o.x,y*o.y);}
	I Vector operator/(Vector o){return Vector(x/o.x,y/o.y);}
	I void input(){cin>>x>>y;}
	I void output(){printf("(%.5lf,%.5lf)",x,y);}
};

直线

struct Line{
	Point p;Vector v;double ang;
	Line(){}
	Line(Point p,Vector v):p(p),v(v){v=v/sqrt(sqr(v.x)+sqr(v.y));ang=atan2(v.y,v.x);}//转化为单位向量
	I bool operator<(Cn Line& o)const{return ang<o.ang;//按照极角排序
	I void output(){p.output();pc(' ');v.output();pc('\n');}
};

struct Circle{
	Point o;double r;
	Circle(){}
	Circle(Point o,double r):o(o),r(r){}
	I Point point(double a){return Point(o.x+cos(a)*r,o.y+sin(a)*r);}//已知角度,求圆上的点
	I void input(){o.input();cin>>r;}
};

平面

struct Flat{
	Point p;Vector n;
	Flat(Point p,Vector n):p(p),n(n){}
};

Part 2 点线面、向量、圆相关计算

向量

I double Dot(Vector A,Vector B){return A.x*B.x+A.y*B.y;}//点积
I double Cross(Vector A,Vector B){return A.x*B.y-A.y*B.x;}//叉积
I double Length(Vector A){return sqrt(Dot(A,A));}//向量长度
I double Angle(Vector A,Vector B){return acos(Dot(A,B)/Length(A)/Length(B));}//两向量转角
I double Angle(Vector A){return atan2(A.y,A.x);}//向量极角[-PI,PI)
I Vector Rotate(Vector A,double rad){return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));}//向量旋转
I Vector Normal(Vector A){return Vector(-A.y/Length(A),A.x/Length(A));}//法向量

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇