mirror of
https://github.com/jankae/LibreVNA.git
synced 2026-04-07 15:33:51 +00:00
Optionally interpolate markers
This commit is contained in:
parent
367451dc04
commit
2f7449ed21
8 changed files with 210 additions and 42 deletions
|
|
@ -1,5 +1,7 @@
|
|||
#include "util.h"
|
||||
|
||||
#include <QVector2D>
|
||||
|
||||
void Util::unwrapPhase(std::vector<double> &phase)
|
||||
{
|
||||
for (unsigned int i = 1; i < phase.size(); i++) {
|
||||
|
|
@ -24,3 +26,31 @@ void Util::linearRegression(const std::vector<double> &input, double &B_0, doubl
|
|||
B_1 = ss_xy / ss_xx;
|
||||
B_0 = y_mean - B_1 * x_mean;
|
||||
}
|
||||
|
||||
double Util::distanceToLine(QPointF point, QPointF l1, QPointF l2, QPointF *closestLinePoint, double *pointRatio)
|
||||
{
|
||||
auto M = l2 - l1;
|
||||
auto t0 = QPointF::dotProduct(M, point - l1) / QPointF::dotProduct(M, M);
|
||||
QPointF closestPoint;
|
||||
QVector2D orthVect;
|
||||
if (t0 <= 0) {
|
||||
orthVect = QVector2D(point - l1);
|
||||
closestPoint = l1;
|
||||
t0 = 0;
|
||||
} else if(t0 >= 1) {
|
||||
orthVect = QVector2D(point - l2);
|
||||
closestPoint = l2;
|
||||
t0 = 1;
|
||||
} else {
|
||||
auto intersect = l1 + t0 * M;
|
||||
orthVect = QVector2D(point - intersect);
|
||||
closestPoint = intersect;
|
||||
}
|
||||
if(closestLinePoint) {
|
||||
*closestLinePoint = closestPoint;
|
||||
}
|
||||
if(pointRatio) {
|
||||
*pointRatio = t0;
|
||||
}
|
||||
return orthVect.length();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include <QColor>
|
||||
#include <QPoint>
|
||||
|
||||
namespace Util {
|
||||
template<typename T> T Scale(T value, T from_low, T from_high, T to_low, T to_high, bool log_from = false, bool log_to = false) {
|
||||
|
|
@ -69,6 +70,8 @@ namespace Util {
|
|||
|
||||
// input values are Y coordinates, assumes evenly spaced linear X values from 0 to input.size() - 1
|
||||
void linearRegression(const std::vector<double> &input, double &B_0, double &B_1);
|
||||
|
||||
double distanceToLine(QPointF point, QPointF l1, QPointF l2, QPointF *closestLinePoint = nullptr, double *pointRatio = nullptr);
|
||||
}
|
||||
|
||||
#endif // UTILH_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue