计算几何——交点、面积的计算
作者:互联网
交点、面积的计算
一·、基本操作
0、准备
1 const int maxn = 10005; 2 typedef pair<double, double> _pair; 3 _pair point[maxn];
1、两点间距离的计算
Dis= sqrt[ (x2- x1)2+ (y2- y1)2 ];
1 double Get_Dis (_pair point1, _pair point2) 2 { 3 //计算两点间距离 4 return sqrt(((point1.first- point2.first)* (point1.first- point2.first) ) 5 + ((point1.second- point2.second)* (point1.second- point2.second) ) ); 6 }
2、计算叉乘(向量积/外积)
PAxQB= { [ (A.x- P.x)* (B.y- Q.y) ]- [ (B.x- Q.x)* (A.y- P.y) ] };
1 double Get_axb (_pair a_point1, _pair a_point2, _pair b_point1, _pair b_point2) 2 { 3 //计算两条向量的叉积 4 //向量a= a_point1 --> a_point2= a_point2- a_point1; 5 //向量b= b_point1 --> b_point2= b_point2- b_point1; 6 //叉积axb= (a.x* b.y)- (b.x* a.y); 7 //a.x= a_point2.x- a_point1.x; a.y= a_point2.y- a_point1.y; 8 return (((a_point2.first- a_point1.first)* (b_point2.second- b_point1.second) ) 9 - ((b_point2.first- b_point1.first)* (a_point2.second- a_point1.second) ) ); 10 }
3、计算点乘(内积)
(待填)
end;
标签:交点,second,point1,point2,计算,几何,pair,first 来源: https://www.cnblogs.com/Amaris-diana/p/10744087.html