2025-04-22T11:35:38
This commit is contained in:
parent
a00031c009
commit
58ccb873f1
@ -477,9 +477,9 @@ QString PointCalculate::textFormatEndPoint(const QPointF point)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QPointF PointCalculate::getClosestPointByY(const float left,const float right,const float valueY)
|
QPointF PointCalculate::getClosestPointByY(const double left,const double right,const double valueY)
|
||||||
{
|
{
|
||||||
float minValue = std::numeric_limits<float>::infinity(); // 初始化为正无穷
|
double minValue = std::numeric_limits<double>::infinity(); // 初始化为正无穷
|
||||||
QPointF closestPoint;
|
QPointF closestPoint;
|
||||||
|
|
||||||
for (const Global::ExperimentData& ed : _dataVtr) {
|
for (const Global::ExperimentData& ed : _dataVtr) {
|
||||||
@ -541,7 +541,44 @@ QVector<Global::ExperimentData> PointCalculate::getDataInXRange(const float x1,
|
|||||||
|
|
||||||
return targetVtr;
|
return targetVtr;
|
||||||
}
|
}
|
||||||
|
QVector<QPointF> PointCalculate::movingAveragePoint(const QVector<QPointF> &points, int windowSize)
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
QVector<QPointF> result;
|
||||||
|
int n = points.size();
|
||||||
|
for (int i = 0; i < n; ++i) {
|
||||||
|
double sumY = 0.0;
|
||||||
|
double sumX = 0.0;
|
||||||
|
int count = 0;
|
||||||
|
for (int j = std::max(0, i - windowSize / 2); j <= std::min(n - 1, i + windowSize / 2); ++j) {
|
||||||
|
sumY += points[j].y();
|
||||||
|
sumX += points[j].x();
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
if (count > 0) {
|
||||||
|
double avgY = sumY / count;
|
||||||
|
double avgX = sumX / count;
|
||||||
|
result.append(QPointF(avgX, avgY));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
#endif
|
||||||
|
QVector<QPointF> result;
|
||||||
|
int n = points.size();
|
||||||
|
for (int i = 0; i < n; ++i) {
|
||||||
|
double sumY = 0.0;
|
||||||
|
int count = 0;
|
||||||
|
for (int j = std::max(0, i - windowSize / 2); j <= std::min(n - 1, i + windowSize / 2); ++j) {
|
||||||
|
sumY += points[j].y();
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
if (count > 0) {
|
||||||
|
double avgY = sumY / count;
|
||||||
|
result.append(QPointF(points[i].x(), avgY)); // 使用原始的 x 值
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
QVector<QPointF> PointCalculate::getNearbyPointGroupByX(const float targetX)
|
QVector<QPointF> PointCalculate::getNearbyPointGroupByX(const float targetX)
|
||||||
{
|
{
|
||||||
const int conCount = 10;
|
const int conCount = 10;
|
||||||
@ -572,7 +609,7 @@ double PointCalculate::calculateSlope(double x1, double y1, double x2, double y2
|
|||||||
return (y2 - y1) / (x2 - x1);
|
return (y2 - y1) / (x2 - x1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 寻找第一个拐点
|
// 寻找拐点
|
||||||
QVector<double> PointCalculate::findInflectionPoints(
|
QVector<double> PointCalculate::findInflectionPoints(
|
||||||
const QVector<double>& x, const QVector<double>& y) {
|
const QVector<double>& x, const QVector<double>& y) {
|
||||||
QVector<double> inflectionPointsX;
|
QVector<double> inflectionPointsX;
|
||||||
@ -619,3 +656,5 @@ QVector<QPointF> PointCalculate::getPointVtrInXRange(const float x1, const float
|
|||||||
|
|
||||||
return targetVtr;
|
return targetVtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ void setRegionPointX(const float,const float);
|
|||||||
QPointF getClosestPointByX(const float);
|
QPointF getClosestPointByX(const float);
|
||||||
QVector<QPointF> getNearbyPointGroupByX(const float);
|
QVector<QPointF> getNearbyPointGroupByX(const float);
|
||||||
|
|
||||||
QPointF getClosestPointByY(const float left,const float right,const float valueY);
|
QPointF getClosestPointByY(const double left,const double right,const double valueY);
|
||||||
QPointF getPeakPoint();
|
QPointF getPeakPoint();
|
||||||
QPair<float, float> getMaxMinValue();
|
QPair<float, float> getMaxMinValue();
|
||||||
|
|
||||||
@ -59,6 +59,7 @@ QPointF calculateIntersection(const QPointF p1,const QPointF p2,
|
|||||||
const QPointF p3, const QPointF p4);
|
const QPointF p3, const QPointF p4);
|
||||||
QVector<QPointF> getPeakPointGroup();
|
QVector<QPointF> getPeakPointGroup();
|
||||||
std::vector<float> movingAverage(const std::vector<float>& data, int windowSize);
|
std::vector<float> movingAverage(const std::vector<float>& data, int windowSize);
|
||||||
|
QVector<QPointF> movingAveragePoint(const QVector<QPointF>& data, int windowSize);
|
||||||
|
|
||||||
extern QVector<Global::ExperimentData> _dataVtr;
|
extern QVector<Global::ExperimentData> _dataVtr;
|
||||||
extern QPointF _peakPoint;
|
extern QPointF _peakPoint;
|
||||||
|
@ -612,7 +612,9 @@ void CentralWidget::glassTransitionHandle2()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// inflection point.
|
// inflection point.
|
||||||
QVector<QPointF> pointVtr = PointCalculate::getPointVtrInXRange(point1.x(),point2.x());
|
QVector<QPointF> originalPointVtr = PointCalculate::getPointVtrInXRange(point1.x(),point2.x());
|
||||||
|
// QVector<QPointF> pointVtr = PointCalculate::movingAveragePoint(originalPointVtr,3);
|
||||||
|
QVector<QPointF> pointVtr = originalPointVtr;
|
||||||
|
|
||||||
xVtr.clear();
|
xVtr.clear();
|
||||||
yVtr.clear();
|
yVtr.clear();
|
||||||
@ -626,6 +628,7 @@ void CentralWidget::glassTransitionHandle2()
|
|||||||
double targetX = 0.0;
|
double targetX = 0.0;
|
||||||
PointCalculate::Line targetLine;
|
PointCalculate::Line targetLine;
|
||||||
double maxSlopeAbs = 0.0; // 初始化最大斜率绝对值为0
|
double maxSlopeAbs = 0.0; // 初始化最大斜率绝对值为0
|
||||||
|
#if 0
|
||||||
for (auto it = tangentLines.begin(); it != tangentLines.end(); ++it) {
|
for (auto it = tangentLines.begin(); it != tangentLines.end(); ++it) {
|
||||||
if (std::fabs(it.value().slope) > maxSlopeAbs) {
|
if (std::fabs(it.value().slope) > maxSlopeAbs) {
|
||||||
maxSlopeAbs = std::fabs(it.value().slope); // 更新最大斜率绝对值
|
maxSlopeAbs = std::fabs(it.value().slope); // 更新最大斜率绝对值
|
||||||
@ -634,7 +637,35 @@ void CentralWidget::glassTransitionHandle2()
|
|||||||
targetLine = it.value();
|
targetLine = it.value();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
// new method
|
||||||
|
for (auto it = tangentLines.begin(); it != tangentLines.end(); ++it) {
|
||||||
|
if (std::fabs(it.value().slope) > maxSlopeAbs) {
|
||||||
|
maxSlopeAbs = std::fabs(it.value().slope); // 更新最大斜率绝对值
|
||||||
|
|
||||||
|
targetX = it.key();
|
||||||
|
targetLine = it.value();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int index = 0;
|
||||||
|
QPointF prePoint,currentPoint,lastPoint;
|
||||||
|
for (int i = 0;i < pointVtr.size();i++) {
|
||||||
|
currentPoint = pointVtr[i];
|
||||||
|
if(currentPoint.x() == targetX){
|
||||||
|
index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
prePoint = pointVtr[index - 1];
|
||||||
|
lastPoint = pointVtr[index + 1];
|
||||||
|
|
||||||
|
|
||||||
|
targetLine.slope = PointCalculate::calculateSlope(lastPoint.x(),lastPoint.y(),prePoint.x(),prePoint.y());
|
||||||
|
targetLine.intercept = currentPoint.y() - targetLine.slope * currentPoint.x();
|
||||||
|
//
|
||||||
#if 1
|
#if 1
|
||||||
QPointF intersection1 = PointCalculate::getIntersection(targetLine,line1);
|
QPointF intersection1 = PointCalculate::getIntersection(targetLine,line1);
|
||||||
QPointF intersection2 = PointCalculate::getIntersection(targetLine,line2);
|
QPointF intersection2 = PointCalculate::getIntersection(targetLine,line2);
|
||||||
@ -670,12 +701,11 @@ void CentralWidget::glassTransitionHandle2()
|
|||||||
|
|
||||||
QPointF averagePoint = PointCalculate::getClosestPointByY(point1.x(),point2.x(),averageY);
|
QPointF averagePoint = PointCalculate::getClosestPointByY(point1.x(),point2.x(),averageY);
|
||||||
|
|
||||||
|
QString str = PointCalculate::textFormatGlassTranstion(intersection1.x(),
|
||||||
QString str = PointCalculate::textFormatGlassTranstion(intersection2.x(),
|
|
||||||
averagePoint.x(),
|
averagePoint.x(),
|
||||||
intersection1.x());
|
intersection2.x());
|
||||||
|
|
||||||
drawText(averagePoint,str);
|
drawText(averagePoint,str);
|
||||||
|
|
||||||
}
|
}
|
||||||
// 使用最小二乘法计算线性回归
|
// 使用最小二乘法计算线性回归
|
||||||
|
Loading…
Reference in New Issue
Block a user