Commit 24a64679 authored by NicolaiO's avatar NicolaiO 🐼 Committed by TIGERs GitLab
Browse files

Resolve "Improve Keeper Positioning to take care of the deflection angles"

Closes #1666

See merge request main/Sumatra!1420

sumatra-commit: 98fcf4bbf1375df55f8722a6ffcbba359f3e9cf4
parent ec34615b
Pipeline #17124 passed with stage
in 10 minutes and 19 seconds
/*
* Copyright (c) 2009 - 2020, DHBW Mannheim - TIGERs Mannheim
* Copyright (c) 2009 - 2021, DHBW Mannheim - TIGERs Mannheim
*/
package edu.tigers.sumatra.math;
......@@ -71,11 +71,13 @@ public final class AngleMath
public static double rotateAngle(final double angleStart, final double angleAmount,
final ERotationDirection rotationDirection)
{
return normalizeAngle(
rotationDirection == ERotationDirection.NO_ROTATION ? angleStart :
rotationDirection == ERotationDirection.CCW_ROTATION ?
angleStart + angleAmount :
angleStart - angleAmount
if (rotationDirection == ERotationDirection.NONE)
{
return normalizeAngle(angleStart);
}
return normalizeAngle(rotationDirection == ERotationDirection.COUNTER_CLOCKWISE ?
angleStart + angleAmount :
angleStart - angleAmount
);
}
......@@ -85,25 +87,17 @@ public final class AngleMath
final var difference = AngleMath.difference(angleEnd, angleStart);
if (Math.abs(difference) < 1e-6)
{
return ERotationDirection.NO_ROTATION;
return ERotationDirection.NONE;
} else if (difference < 0)
{
return ERotationDirection.CW_ROTATION;
return ERotationDirection.CLOCKWISE;
} else
{
return ERotationDirection.CCW_ROTATION;
return ERotationDirection.COUNTER_CLOCKWISE;
}
}
public enum ERotationDirection
{
NO_ROTATION,
CW_ROTATION,
CCW_ROTATION
}
/**
* Get the absolute smallest difference between angle1 and angle2.<br>
* <code>abs(norm(angle1-angle2))</code>
......
/*
* Copyright (c) 2009 - 2021, DHBW Mannheim - TIGERs Mannheim
*/
package edu.tigers.sumatra.math;
public enum ERotationDirection
{
NONE,
CLOCKWISE,
COUNTER_CLOCKWISE
}
/*
* Copyright (c) 2009 - 2017, DHBW Mannheim - TIGERs Mannheim
* Copyright (c) 2009 - 2021, DHBW Mannheim - TIGERs Mannheim
*/
package edu.tigers.sumatra.math;
......@@ -68,12 +68,11 @@ public class AngleMathTest
@Test
public void testRotateAngle()
{
assertThat(AngleMath.rotateAngle(-1, 2, AngleMath.ERotationDirection.CCW_ROTATION)).isEqualTo(1);
assertThat(AngleMath.rotateAngle(1, 2, AngleMath.ERotationDirection.CW_ROTATION)).isEqualTo(-1);
assertThat(AngleMath.rotateAngle(0, 42, AngleMath.ERotationDirection.NO_ROTATION)).isEqualTo(0);
assertThat(AngleMath.rotateAngle(15 * AngleMath.PI_TWO, 42, AngleMath.ERotationDirection.NO_ROTATION))
.isEqualTo(0);
assertThat(AngleMath.rotateAngle(-1, 2 + 10 * AngleMath.PI_TWO, AngleMath.ERotationDirection.CCW_ROTATION))
assertThat(AngleMath.rotateAngle(-1, 2, ERotationDirection.COUNTER_CLOCKWISE)).isEqualTo(1);
assertThat(AngleMath.rotateAngle(1, 2, ERotationDirection.CLOCKWISE)).isEqualTo(-1);
assertThat(AngleMath.rotateAngle(0, 42, ERotationDirection.NONE)).isZero();
assertThat(AngleMath.rotateAngle(15 * AngleMath.PI_TWO, 42, ERotationDirection.NONE)).isZero();
assertThat(AngleMath.rotateAngle(-1, 2 + 10 * AngleMath.PI_TWO, ERotationDirection.COUNTER_CLOCKWISE))
.isEqualTo(1);
}
......@@ -81,15 +80,15 @@ public class AngleMathTest
@Test
public void testRotationDirection()
{
assertThat(AngleMath.rotationDirection(-1, 1)).isEqualTo(AngleMath.ERotationDirection.CCW_ROTATION);
assertThat(AngleMath.rotationDirection(1, -1)).isEqualTo(AngleMath.ERotationDirection.CW_ROTATION);
assertThat(AngleMath.rotationDirection(1, 1)).isEqualTo(AngleMath.ERotationDirection.NO_ROTATION);
assertThat(AngleMath.rotationDirection(-1, 1)).isEqualTo(ERotationDirection.COUNTER_CLOCKWISE);
assertThat(AngleMath.rotationDirection(1, -1)).isEqualTo(ERotationDirection.CLOCKWISE);
assertThat(AngleMath.rotationDirection(1, 1)).isEqualTo(ERotationDirection.NONE);
assertThat(AngleMath.rotationDirection(-1 + 10 * AngleMath.PI_TWO, 1 + 10 * AngleMath.PI_TWO))
.isEqualTo(AngleMath.ERotationDirection.CCW_ROTATION);
.isEqualTo(ERotationDirection.COUNTER_CLOCKWISE);
assertThat(AngleMath.rotationDirection(1 + 10 * AngleMath.PI_TWO, -1))
.isEqualTo(AngleMath.ERotationDirection.CW_ROTATION);
.isEqualTo(ERotationDirection.CLOCKWISE);
assertThat(AngleMath.rotationDirection(15 * AngleMath.PI_TWO, 10 * AngleMath.PI_TWO))
.isEqualTo(AngleMath.ERotationDirection.NO_ROTATION);
.isEqualTo(ERotationDirection.NONE);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment