/**
* 点/向量
*/structPoint{double x , y;/**
* 向量加法
* @param rhs 向量
* @return 新向量
*/
Point operator+(const Point &rhs )const{return{ x + rhs.x , y + rhs.y };}/**
* 向量减法
* @param rhs 向量
* @return 新向量
*/
Point operator-(const Point &rhs )const{return{ x - rhs.x , y - rhs.y };}/**
* 向量乘法
* @param rhs 倍数
* @return 新向量
*/
Point operator*(constdouble&rhs )const{return{ x * rhs , y * rhs };}/**
* 向量除法
* @param rhs 倍数
* @return 新向量
*/
Point operator/(constdouble&rhs )const{return{ x / rhs , y / rhs };}/**
* 向量等于判断
* @param rhs 向量
* @return 布尔值
*/booloperator==(const Point &rhs )const{return x == rhs.x && y == rhs.y;}/**
* 向量不等于判断
* @param rhs 向量
* @return 布尔值
*/booloperator!=(const Point &rhs )const{return x != rhs.x || y != rhs.y;}/**
* 向量点积
* @param rhs 向量
* @return 点积值
*/doubleoperator*(const Point &rhs )const{return x * rhs.x + y * rhs.y;}/**
* 向量叉积
* @param rhs 向量
* @return 叉积值
*/doubleoperator^(const Point &rhs )const{return x * rhs.y - y * rhs.x;}/**
* 向量模长
* @return 模长值
*/doubleabs()const{returnsqrt(*this**this);}/**
* 向量模长平方
* @return 模长平方值
*/doubleabs2()const{return*this**this;}/**
* 向量单位化
* @return 弧度值
*/doublearg()const{returnatan2( y , x );}/**
* 向量求三角形面积
* @param rhs 向量
* @return
*/doubletriangleArea(const Point &rhs )const{returnfabs((*this)^ rhs )/2;}};/**
* 直线一般式方程
* Ax + By + C = 0
*/structLine{double A , B , C ;/**
* 初始化构造直线方程
* Ax + By + C = 0
*/Line():A(0),B(0),C(0){}Line(const Point &lhs ,const Point &rhs ):A( rhs.y - lhs.y ),B( lhs.x - rhs.x ),C( rhs.x * lhs.y - lhs.x * rhs.y ){}Line(constdouble&a ,constdouble&b ,constdouble&c ):A( a ),B( b ),C( c ){}/**
* 求两直线的交点
* @param rhs 直线
* @return 交点
*/
Point operator&(const Line &rhs )const{/**
* 共线或者平行,返回不存在交点
*/if( A*rhs.B == rhs.A*B ){returnPoint( INFINITY , INFINITY );}returnPoint(( B*rhs.C - C*rhs.B )/( A*rhs.B - B*rhs.A ),( C*rhs.A - A*rhs.C )/( A*rhs.B - B*rhs.A ));}};
三维模板
structPoint{double x , y , z;Point(double _x =0,double _y =0,double _z =0):x( _x ),y( _y ),z( _z ){}
Point operator+(const Point &b )const{return{ x + b.x , y + b.y , z + b.z };}
Point operator-(const Point &b )const{return{ x - b.x , y - b.y , z - b.z };}
Point operator*(constdouble&k )const{return{ x * k , y * k , z * k };}/**
* @brief 向量积
* 点积等于两个向量的夹角余弦值乘以这两个向量的长度的乘积
* @param b
* @return
*/doubleoperator*(const Point &b )const{return x * b.x + y * b.y + z * b.z;}/**
* @brief 叉积
* 叉积等于两个向量的平行四边形面积的符号,等于两个向量的外积的第三个分量
* @param b
* @return
*/
Point operator^(const Point &b )const{return{ y * b.z - z * b.y , z * b.x - x * b.z , x * b.y - y * b.x };}};structNormal{
Point p;double d;Normal( Point _p =Point(),double _d =0):p( _p ),d( _d ){}};/**
* 获取平面上三个点的法向量
* @param p1 第一个点
* @param p2 第二个点
* @param p3 第三个点
* @return 法向量
*/
Normal getNormal( Point p1 , Point p2 , Point p3 ){
Normal res(Point(),0);
Point v1 = p2 - p1;
Point v2 = p3 - p1;
res.p = v1 ^ v2;
res.d = res.p * p1;return res;}