mirror of
https://github.com/jankae/LibreVNA.git
synced 2026-04-07 23:43:42 +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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue