当前位置:网站首页>Computational geometry (4.17)
Computational geometry (4.17)
2022-07-19 06:05:00 【lovesickman】
Computational geometry
Pre knowledge :
pi = acos(-1)Cosine theorem : c 2 = a 2 + b 2 − 2 a b c o s ( t ) c^2 = a^2+b^2-2abcos(t) c2=a2+b2−2abcos(t)
Floating point comparison .
const double eps = 1e-8; int sign(double x){ if(fabs(x)<eps)return 0; if(x<0)return -1; return 1; }int cmp(double x,double y){ if(fabs(x-y)<eps)return 0; if(x<y)return -1; return 1; }vector
The addition, subtraction and multiplication of vectors .
Inner product ( Dot product ) A ⋅ B = ∣ A ∣ ∣ B ∣ c o s ( C ) A \cdot B=|A||B|cos(C) A⋅B=∣A∣∣B∣cos(C)
Geometric meaning : vector A In vector B The projection multiplication vector on B The length of .
double dot(Point a,Point b){ return a.x*b.x+a.y*b.y; }Exoproduct ( Cross product ) A × B = ∣ A ∣ ∣ B ∣ s i n ( C ) A \times B = |A||B|sin(C) A×B=∣A∣∣B∣sin(C) ( Determinant push )
Geometric meaning : vector A and B The area of a parallelogram ( Directed area ) Half of . The direction follows the rule .
double cross(Point a,Point b){ return a.x*b.y-a.y*b.x }
Common functions extended from dot product and cross product .
Find the length of the vector .
double get_length(Point a){ return sqrt(dot(a,a)); }Calculate the included angle of the vector
double get_angle(Point a,Point b){ return acos(dot(a,b)/get_length(a)/get_length(b)); }Calculate the area of parallelogram
double get_area(Point a,Point b,Point c){ return cross(a-b,c-b); }Rotate a vector by an angle .
take ( x , y ) (x,y) (x,y) Rotate one clockwise θ \theta θ horn .
[ x , y ] [ c o s ( θ ) − s i n ( θ ) s i n ( θ ) c o s ( θ ) ] = [ x c o s ( θ ) + y s i n ( θ ) , − x s i n ( θ ) + y c o s ( θ ) ] \begin{bmatrix} x , y \end{bmatrix} \begin{bmatrix} cos(\theta) & -sin(\theta)\\ sin(\theta) &cos(\theta) \end{bmatrix}=[{xcos(\theta)+ysin(\theta)},{-xsin(\theta)+ycos(\theta)}] [x,y][cos(θ)sin(θ)−sin(θ)cos(θ)]=[xcos(θ)+ysin(θ),−xsin(θ)+ycos(θ)]
Points and lines
Straight line theorem .
- General style a x + b y + c = 0 ax+by+c=0 ax+by+c=0
- Pointwise ( Most used ) p 0 ( ren It means One individual spot ) + v ‾ ( too p 0 Of Not 0 towards The amount ) ∗ t p_0( Any point )+\overline v( too p_0 Non - 0 vector ) *t p0( ren It means One individual spot )+v( too p0 Of Not 0 towards The amount )∗t
- Oblique section type $y = kx+b
Judge whether the point is on a straight line .
A × B = 0 A \times B = 0 A×B=0 Express a spot and towards The amount B On Of some individual spot Group become Of towards The amount A and B the around become Of 3、 ... and horn shape Of Noodles product yes 0 a Points and vectors B A vector consisting of a point on A and B The area of the triangle enclosed is 0 a spot and towards The amount B On Of some individual spot Group become Of towards The amount A and B the around become Of 3、 ... and horn shape Of Noodles product yes 0 , Indicates that the point is on a straight line .
Two straight lines intersect , Find the intersection .
c r o s s ( v , w ) = = 0 cross(v,w)==0 cross(v,w)==0 It is specially judged that two straight lines are parallel or coincide .( Used similarity to prove )
Point get_intersection(Point p,Vector v,Point q,Vector w){ Vector u = p-q; double t = cross(w,u)/cross(v,w); return p+v*t; }The distance between a point and a line .
double distance_to_line(Point a,Point b,Point c){ Vector v1 = b-a; Vector v2 = c-a; return fabs(cross(v1,v2))/getlength(v1);// The area divided by the length of the bottom side is the height . }The distance between a point and a line segment . Two special cases are specially judged .
double distance_to_segment(Point p,Point a,Point b){ if(a==b)return get_length(p-a); Vector v1 = b-a,v2=p-a,v3=p-b; if(sign(dot(v1,v2))<0)return get_length(v2); if(sign(dot(v1,v3))>0)return get_length(v3); return distance_to_line(p,a,b); }Projection from point to line .
Point get_line_projection(Point P,Point a,Point b){ Vector v = b-a; return a+v*(dot(v,p-a)/dot(v,v)); }Whether the point is on the line segment .
bool on_segment(Point p,Point a,Point b){ // Line segment is a->b, Judge p Whether it is on the line segment . Satisfy p On line segments , And p stay [a,b] middle . return sign(cross(p-a),cross(p-b)) == 0 && sign(dot(p-a,p-b))<=0; }Judge whether two line segments intersect ( Straddle experiment )
bool segment_intersection(Point a1,Point a2,Point b1,Point b2){ double c1 = cross(a2-a1,b1-a1); double c2 = cross(a2-a1,b2-a1); double c3 = cross(b2-b1,a2-b1); double c4 = cross(b2-b1,a1-b1); return sign(c1)*sign(c2)<=0 && sign(c3)*sign(c4)<=0; }
polygon .
The four centers of a triangle .
- Outside the heart : The center of a triangle circumscribed circle , The intersection of the vertical lines on three sides , The distance to the three vertices of the triangle is equal .
- inner : The center of the inscribed circle , Intersection of angular bisectors , Equal distance to three sides .
- orthocenter : The intersection of three perpendicular feet .
- Focus : The intersection of the three central lines .( The point where the sum of squares of the distances to the three vertices of a triangle is the smallest , The point where the product of the distance from the triangle to the three sides is the largest ).
Definition : In the same plane , Not in the same straight line , A figure in which multiple line segments are connected sequentially from beginning to end and do not intersect .
Simple polygon : Except adjacent edges , Other edges do not intersect .
Convex polygon :
Make a straight line across any edge of the polygon , If all the other vertices are on one side of this edge , It's a convex polygon .
- The sum of the outer corners of an arbitrary convex polygon is 360 degree .
- The sum of the interior angles of an arbitrary convex polygon is ( n − 2 ) ∗ 180 (n-2)*180 (n−2)∗180 degree .
Common functions :
Find the area of an arbitrary polygon .
You can triangulate polygons , Divide into n − 2 n-2 n−2 Triangles , Reverse all edges , Or sort in order .
You can choose any point on the plane , In order of edges , Traverse every edge , By finding the cross product of two vectors , Get the area sum of the polygon .( Using the property that the cross product area has positive and negative , Very clever )
double polygon_area(Point p[],int n){ // When taking any point , Generally, take the first point of the polygon p[0] double s=0; for(int i=1;i<n-1;i++){ s += cross(p[i]-p[0],p[i+1]-p[i]); } return s/2; }Determine whether a point is within a polygon ( It can be arbitrary polygon )
Ray method or Corner method
Ray method : From this point, make an arbitrary ray that is not parallel to all edges , The number of intersections is even , The point is outside the polygon , Otherwise in the polygon .
Judge whether a point is Convex polygon Inside ( Convex polygons are stored counterclockwise )
Judge whether the point is on the left side of the convex polygon .( Cross product )
Pike theorem
requirement : All points of the polygon must be on the grid .
s = a + b 2 − 1 s = a + {b\over 2}-1 s=a+2b−1 .
a : a: a: The number of whole points inside the polygon .
b : b: b: The number of whole points on the edge of the polygon .
边栏推荐
- uboot 编译前的配置命令make config分析
- Qtss callback routine
- Wide voltage input high voltage output voltage control type
- 配置VsCode中‘log’快捷键去掉console.log(‘‘);中的分号;
- DSL实现Metrics 聚合
- 处理中文分词 ik分词器以及拓展和停止字典
- filezilla传输虚拟机速度慢解决方法
- RestClient查询文档
- 2021-11-10 micropyton tb6600 step drive class
- Minio installation, deployment and simple use
猜你喜欢

HRA2460D-2w高压电源高压模块-高压---高精度hra2460d-2w

Solve cannot read properties of null (reading 'pickalgorithm')

RS-485/232转4-20mA/0-10V隔离D/A转换器

结合图片看常用串口通信UART

DAC7512N 模拟混合信号IC转换器

RestClient-多条件聚合

Introduction to Darwin streaming server

Fs4061a (5V USB input, double lithium battery series application, 5V boost charging, 8.4v Management IC

Thermal resistance PT100 cu50 isolation converter to 4-20mA analog output temperature transmitter 0-10V

MySQL Workbench基本使用 【创建一个数据表】
随机推荐
LTH7五脚芯片的完整方案图FS4054充电电路原理
无线充电芯片IC
DSL实现自动补全查询
Proportional valve amplifier 1a, 2a, 3a, 5A proportional valve drive module 0-10V to 0-24v
Introduction to easydarawin streaming media server
Guess The String (二分,交互)
FS4061A(5V USB输入、双节锂电池串联应用、5v升压充电8.4v管理IC
Lithium battery charging management chip
golang 多项目工作区搭建
Antd is not defined
MEX and Increments
5V升压充电8.4V芯片
转速传感器信号隔离、采集及变换,正弦波、锯齿波信号输入,方波信号输出,信号转换器
RestAPI实现聚合(黑马教程)
js变量提升
Golang multi project workspace construction
Hm8203 linear two string charging management controller IC
【转】Darwin Streaming Server 核心代码分析
Ehab the Xorcist (异或性质,构造)
Go language introduction and application scenario analysis