#pragma once #include "Defines.h" #include "iAlgMath_global.h" class QPointF; class QLineF; // 几何基础类 class I_ALGMATH_EXPORT zxGmyBase { public: zxGmyBase(); virtual ~zxGmyBase(); public: // ccw > 0 double triangle_area(double ax, double ay, double bx, double by, double cx, double cy); // ccw > 0, cw < 0, empty = 0 double triangle_ccw(double ax, double ay, double bx, double by, double cx, double cy); // double triangle_interpolate(double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3,double x, double y); // out < 0, cocircular = 0, in > 0 double in_circle(double ax, double ay, double bx, double by, double cx, double cy, double dx, double dy); // < 0 // a +--- = 0 ----+ b // > 0 double orient2d(double ax, double ay, double bx, double by, double cx, double cy); // | d // | // a --+-- b // | // | c bool is_segment_intersect(double ax, double ay, double bx, double by, double cx, double cy, double dx, double dy); // 角度 double degToRad(double _deg); double radToDeg(double _rad); double kross(const QPointF& a, const QPointF& b); double lengthSquared(const QPointF& a); double pointSegmentDistanceSquared2D(const QPointF& q, const QPointF& p0, const QPointF& p1, double & t); double pointLineDistanceSquared2D(const QPointF& q, const QPointF& p0, const QPointF& p1, double & t); // 距离(有待优化) double dot(double ax, double ay, double bx, double by); double distance_squared(double ax, double ay, double bx, double by); double distance(double ax, double ay, double bx, double by); //double distance(double x0, double y0, double x1, double y1); double distanceSquared(double x0, double y0, double x1, double y1); double dot(const QPointF& a, const QPointF& b); int findIntersection(const QPointF& seg0_a, const QPointF& seg0_b, const QPointF& seg1_a, const QPointF& seg1_b, QPointF ip[2]); int findIntersection(const QLineF & seg0, const QLineF & seg1, QPointF ip[2]); void cubic_bezier(double & _x, double & _y, double t, double _x0, double _y0, double _x1, double _y1, double _x2, double _y2, double _x3, double _y3); bool polygonContainsPoint(const QVector & poly, double x, double y); bool polygonIsCcw(const QVector & poly); double polygonArea(const QVector & poly); void polygonSimplify(QVector & out, const QVector & in, double maxErrDistance2); int _findIntersection(double u0, double u1, double v0, double v1, double w[2]); void simplifyPolygonRdp(QVector & out, const QPointF in[], int in_count, int ia, int ib, double maxErrDistance2); // 计算pt到直线line的垂足。返回值表示垂足是否在线段内部(含端点) bool getPadel(const QPointF& pt, const QLineF& line, QPointF& ptPadel); public: /// @brief 计算直线距离 static double calDistanceOf(QPointF pt1, QPointF pt2); /// @brief 计算点P(x,y)与X轴正方向的夹角, 夹角弧度 static double calRadToAxisX(double x, double y); /// @brief 计算点P(x,y)与X轴正方向的夹角, 夹角° static double calAngleToAxisX(double x, double y); /// @brief 点pt围绕点ptCenter旋转弧度fAngleR后的坐标,fAngleR 旋转弧度 or du,顺时针为正 static QPointF rotatePt(QPointF pt, QPointF ptCenter, \ double fAngleR, bool bRad = true); /// @brief 计算两点形成直线的倾斜角(0-180) static double calSlopeOf(QPointF pt1, QPointF pt2); /// @brief 判断两条直线是否平行; static bool isParallelLines(QLineF line1, QLineF line2); /// @brief 计算两条直线的距离(如果不平行,返回-1); static double calDisOfLines(QLineF line1, QLineF line2); /// @brief 计算两条直线/线段的相交点坐标; /// bOnlySegment:true 只考虑线段,false考虑直线,即线段延长线 static bool calCrossOfLines(QPointF& ptCross, \ QLineF line1, QLineF line2, \ bool bOnlySegment = false); /// @brief 计算点到直线距离 static double calDisOfPt2Line(QPointF pt, QLineF line); static double calDisOfPt2Line(QPointF pt, \ QPointF pt1, QPointF pt2); // y = kx + b static double leastSquareMethodSlop(int cnt,const double x[],const double y[],double &b); static double leastSquareMethodSlopEx(int cnt,const double x[],const double y[],double &b); };