Skip to content

Commit

Permalink
Fixed an error where the correction for crossing the +-180deg heading…
Browse files Browse the repository at this point in the history
… boundary using an interactive handle was in KochanekBartelsSpline.ControlPoint.setFieldHeading() rather than in KochanekBartelsSpline.ControlPoint.setHeadingLocation which is used by interactive code. This created errors when a dialog was used to explicitly set the heading.
  • Loading branch information
STHobbes committed Jul 19, 2023
1 parent 6c16205 commit f5d5b6f
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/main/java/org/a05annex/util/geo2d/KochanekBartelsSpline.java
Original file line number Diff line number Diff line change
Expand Up @@ -843,9 +843,20 @@ public double getHeadingY() {
*/
public void setHeadingLocation(Point2D pt) {
// OK, the simple action here is to look at the current mouse position relative to the control
// point position, use the atan2, and get a heading. However, tis does not handle the -180/180 degree
// transition, so we need some logic like the NavX logic. for passing over the boundary
setFieldHeading(new AngleD().atan2(pt.getX() - m_fieldX, pt.getY() - m_fieldY));
// point position, use the atan2, and get a heading. However, this does not handle the -180/180 degree
// transition, so we need some logic like the NavX logic. for passing over the boundary.
//
// Since this is being set by interactive editing the interaction can't put in a half rotation in one
// step, so if the difference is greater than +-MATH.PI, we need to correct (and there may be multiple
// rotations to correct for.
AngleD adjustedHeading = new AngleD().atan2(pt.getX() - m_fieldX, pt.getY() - m_fieldY);
while ((adjustedHeading.getRadians() - m_fieldHeading.getRadians()) > Math.PI) {
adjustedHeading.subtract(AngleD.TWO_PI);
}
while ((adjustedHeading.getRadians() - m_fieldHeading.getRadians()) < -Math.PI) {
adjustedHeading.add(AngleD.TWO_PI);
}
setFieldHeading(adjustedHeading);
}

/**
Expand All @@ -854,14 +865,7 @@ public void setHeadingLocation(Point2D pt) {
* @param heading (AngleConstantD) The heading direction for this control point.
*/
public void setFieldHeading(AngleConstantD heading) {
AngleD adjustedHeading = new AngleD(heading);
while ((adjustedHeading.getRadians() - m_fieldHeading.getRadians()) > Math.PI) {
adjustedHeading.subtract(AngleD.TWO_PI);
}
while ((adjustedHeading.getRadians() - m_fieldHeading.getRadians()) < -Math.PI) {
adjustedHeading.add(AngleD.TWO_PI);
}
m_fieldHeading = adjustedHeading;
m_fieldHeading = new AngleD(heading);
// update the derivatives
updateHeadingDerivative();
if (m_last != null) {
Expand Down

0 comments on commit f5d5b6f

Please sign in to comment.