Skip to content

Commit

Permalink
BezierCP: fix creation of Bezier curves
Browse files Browse the repository at this point in the history
  • Loading branch information
devernay committed Apr 9, 2021
1 parent 874c549 commit 7f86ff4
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions Engine/BezierCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,17 +226,19 @@ BezierCP::getLeftBezierPointAtTime(bool useGuiCurves,
double vx = qx - *x;
double vy = qy - *y;
double v = std::sqrt(vx * vx + vy *vy);
// The normal vector
double nx = vy / v;
double ny = -vx / v;
// The (signed) distance from the position to the segment
double d = nx * (px - *x) + ny * (py - *y);
// displace the key point in the normal direction.
*x += d * nx;
*y += d * ny;
// Verify that d is now zero
// d = nx * (px - *x) + ny * (py - *y);
// qDebug() << 'd' << d;
if (v > 0.) {
// The normal vector
double nx = vy / v;
double ny = -vx / v;
// The (signed) distance from the position to the segment
double d = nx * (px - *x) + ny * (py - *y);
// displace the key point in the normal direction.
*x += d * nx;
*y += d * ny;
// Verify that d is now zero
// d = nx * (px - *x) + ny * (py - *y);
// qDebug() << 'd' << d;
}
}

return ret;
Expand Down Expand Up @@ -292,17 +294,19 @@ BezierCP::getRightBezierPointAtTime(bool useGuiCurves,
double vx = qx - *x;
double vy = qy - *y;
double v = std::sqrt(vx * vx + vy *vy);
// The normal vector
double nx = vy / v;
double ny = -vx / v;
// The (signed) distance from the position to the segment
double d = nx * (px - *x) + ny * (py - *y);
// displace the key point in the normal direction.
*x += d * nx;
*y += d * ny;
// Verify that d is now zero
// d = nx * (px - *x) + ny * (py - *y);
// qDebug() << 'd' << d;
if (v > 0.) {
// The normal vector
double nx = vy / v;
double ny = -vx / v;
// The (signed) distance from the position to the segment
double d = nx * (px - *x) + ny * (py - *y);
// displace the key point in the normal direction.
*x += d * nx;
*y += d * ny;
// Verify that d is now zero
// d = nx * (px - *x) + ny * (py - *y);
// qDebug() << 'd' << d;
}
}

return ret;
Expand Down

0 comments on commit 7f86ff4

Please sign in to comment.