|
|
#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);
|
|
|
|
|
|
// 角度
|
|
|
float degToRad(float _deg);
|
|
|
float radToDeg(float _rad);
|
|
|
float kross(const QPointF& a, const QPointF& b);
|
|
|
float lengthSquared(const QPointF& a);
|
|
|
float pointSegmentDistanceSquared2D(const QPointF& q, const QPointF& p0, const QPointF& p1, float & t);
|
|
|
float pointLineDistanceSquared2D(const QPointF& q, const QPointF& p0, const QPointF& p1, float & 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);
|
|
|
float distance(float x0, float y0, float x1, float y1);
|
|
|
float distanceSquared(float x0, float y0, float x1, float y1);
|
|
|
float 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(float & _x, float & _y, float t,
|
|
|
float _x0, float _y0, float _x1, float _y1,
|
|
|
float _x2, float _y2, float _x3, float _y3);
|
|
|
|
|
|
bool polygonContainsPoint(const QVector<QPointF> & poly, float x, float y);
|
|
|
bool polygonIsCcw(const QVector<QPointF> & poly);
|
|
|
float polygonArea(const QVector<QPointF> & poly);
|
|
|
void polygonSimplify(QVector<QPointF> & out, const QVector<QPointF> & in, float maxErrDistance2);
|
|
|
|
|
|
int _findIntersection(float u0, float u1, float v0, float v1, float w[2]);
|
|
|
void simplifyPolygonRdp(QVector<QPointF> & out, const QPointF in[], int in_count, int ia, int ib, float maxErrDistance2);
|
|
|
|
|
|
// 计算pt到直线line的垂足。返回值表示垂足是否在线段内部(含端点)
|
|
|
bool getPadel(const QPointF& pt, const QLineF& line, QPointF& ptPadel);
|
|
|
|
|
|
public:
|
|
|
|
|
|
/// @brief 计算直线距离
|
|
|
static float calDistanceOf(QPointF pt1, QPointF pt2);
|
|
|
|
|
|
/// @brief 计算点P(x,y)与X轴正方向的夹角, 夹角弧度
|
|
|
static float calRadToAxisX(float x, float y);
|
|
|
|
|
|
/// @brief 计算点P(x,y)与X轴正方向的夹角, 夹角°
|
|
|
static float calAngleToAxisX(float x, float y);
|
|
|
|
|
|
/// @brief 点pt围绕点ptCenter旋转弧度fAngleR后的坐标,fAngleR 旋转弧度 or du,顺时针为正
|
|
|
static QPointF rotatePt(QPointF pt, QPointF ptCenter, \
|
|
|
float fAngleR, bool bRad = true);
|
|
|
|
|
|
/// @brief 计算两点形成直线的倾斜角(0-180)
|
|
|
static float calSlopeOf(QPointF pt1, QPointF pt2);
|
|
|
|
|
|
/// @brief 判断两条直线是否平行;
|
|
|
static bool isParallelLines(QLineF line1, QLineF line2);
|
|
|
|
|
|
/// @brief 计算两条直线的距离(如果不平行,返回-1);
|
|
|
static float calDisOfLines(QLineF line1, QLineF line2);
|
|
|
|
|
|
/// @brief 计算两条直线/线段的相交点坐标;
|
|
|
/// bOnlySegment:true 只考虑线段,false考虑直线,即线段延长线
|
|
|
static bool calCrossOfLines(QPointF& ptCross, \
|
|
|
QLineF line1, QLineF line2, \
|
|
|
bool bOnlySegment = false);
|
|
|
|
|
|
/// @brief 计算点到直线距离
|
|
|
static float calDisOfPt2Line(QPointF pt, QLineF line);
|
|
|
static float calDisOfPt2Line(QPointF pt, \
|
|
|
QPointF pt1, QPointF pt2);
|
|
|
|
|
|
// y = kx + b
|
|
|
static double leastSquareMethodSlop(int cnt,const float x[],const float y[],double &b);
|
|
|
static double leastSquareMethodSlopEx(int cnt,const float x[],const float y[],double &b);
|
|
|
|
|
|
};
|