2025-03-31T13:19:01
This commit is contained in:
parent
6021f8132a
commit
e4f3cc75f3
@ -188,6 +188,73 @@ QVector<QPointF> PeakPoint::getPeakPointGroup()
|
||||
return pointVtr;
|
||||
}
|
||||
|
||||
double PeakPoint::calculateArea() {
|
||||
//getPoint group
|
||||
QVector<QPointF> points = getPeakPointGroup();
|
||||
#if 0
|
||||
for(QPointF point:points){
|
||||
qDebug()<<"x,y:"<<QString::number(point.x(),'f',3)<<","
|
||||
<<QString::number(point.y(),'f',3);
|
||||
}
|
||||
#endif
|
||||
qDebug()<<QString::number(points.at(0).x(),'f',3)<<","<<
|
||||
QString::number(points.at(points.size() - 1).x(),'f',3);
|
||||
|
||||
//calculate Area
|
||||
float integral = 0.0;
|
||||
size_t n = points.size();
|
||||
|
||||
if (n < 2) {
|
||||
return integral; // 至少需要两个点才能计算积分
|
||||
}
|
||||
|
||||
#if 0
|
||||
for (size_t i = 1; i < n; ++i) {
|
||||
float dx = points[i].x() - points[i - 1].x();
|
||||
float avg_y = (points[i].y() + points[i - 1].y()) / 2.0;
|
||||
|
||||
#if 0
|
||||
float step = dx * std::abs(avg_y);
|
||||
qDebug()<<points[i].x()<<","<<points[i].y()<<"integral:"<<integral<<","<<step;
|
||||
#endif
|
||||
|
||||
integral += dx * std::abs(avg_y);
|
||||
}
|
||||
#endif
|
||||
#if 0
|
||||
double k = (y2 - y1) / (x2 - x1);
|
||||
double b = y1 - k * x1;
|
||||
#endif
|
||||
//find a line.
|
||||
double k = (_leftSelectedPoint.y() - _rightSelectedPoint.y()) /
|
||||
(_leftSelectedPoint.x() - _rightSelectedPoint.x());
|
||||
double b = _leftSelectedPoint.y() - k * _leftSelectedPoint.x();
|
||||
|
||||
for (size_t i = 0; i < n - 1; ++i) {
|
||||
#if 1
|
||||
double x1 = points[i].x();
|
||||
double y1 = points[i].y();
|
||||
|
||||
double x2 = points[i + 1].x();
|
||||
double y2 = points[i + 1].y();
|
||||
#endif
|
||||
double yLine1 = k * x1 + b;
|
||||
double yLine2 = k * x2 + b;
|
||||
|
||||
double diff1 = y1 - yLine1;
|
||||
double diff2 = y2 - yLine2;
|
||||
|
||||
double dx = x2 - x1;
|
||||
|
||||
double cellArea = (diff1 + diff2) * dx /2.0;
|
||||
|
||||
integral += std::abs(cellArea);
|
||||
}
|
||||
|
||||
|
||||
return integral;
|
||||
}
|
||||
|
||||
QPair<QPointF, QPointF> PeakPoint::calculateStartAndEndPoint()
|
||||
{
|
||||
QPair<QPointF,QPointF> leftMaxDiffPointPair = PeakPoint::calculateMaxDiffPointLeft();
|
||||
@ -262,39 +329,6 @@ QPointF PeakPoint::calculateIntersection(const QPointF p1,const QPointF p2,
|
||||
}
|
||||
}
|
||||
|
||||
float PeakPoint::calculateArea() {
|
||||
//getPoint group
|
||||
QVector<QPointF> points = getPeakPointGroup();
|
||||
#if 0
|
||||
for(QPointF point:points){
|
||||
qDebug()<<"x,y:"<<QString::number(point.x(),'f',3)<<","
|
||||
<<QString::number(point.y(),'f',3);
|
||||
}
|
||||
#endif
|
||||
qDebug()<<QString::number(points.at(0).x(),'f',3)<<","<<
|
||||
QString::number(points.at(points.size() - 1).x(),'f',3);
|
||||
|
||||
//calculate Area
|
||||
float integral = 0.0;
|
||||
size_t n = points.size();
|
||||
|
||||
if (n < 2) {
|
||||
return integral; // 至少需要两个点才能计算积分
|
||||
}
|
||||
|
||||
for (size_t i = 1; i < n; ++i) {
|
||||
float dx = points[i].x() - points[i - 1].x();
|
||||
float avg_y = (points[i].y() + points[i - 1].y()) / 2.0;
|
||||
|
||||
float step = dx * std::abs(avg_y);
|
||||
qDebug()<<points[i].x()<<","<<points[i].y()<<"integral:"<<integral<<","<<step;
|
||||
|
||||
integral += dx * std::abs(avg_y);
|
||||
}
|
||||
|
||||
return integral;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -16,7 +16,8 @@ QString textFormat(const float enthalpyValue,
|
||||
const float startPoint,
|
||||
const float endPoint);
|
||||
QPair<QPointF,QPointF> calculateStartAndEndPoint();
|
||||
float calculateArea();
|
||||
double calculateArea();
|
||||
|
||||
//private
|
||||
void updateStartEndPoint();
|
||||
QPair<QPointF,QPointF> calculateMaxDiffPointLeft();
|
||||
|
Loading…
Reference in New Issue
Block a user