Skip to content

Commit

Permalink
Resolve "Ball placement role should pull ball with exact 45 degree an…
Browse files Browse the repository at this point in the history
…gle out of goal corners"

Closes #1946

See merge request main/Sumatra!1868

sumatra-commit: 36f058f7ca836b109a153ebe805226df6b9e5af1
  • Loading branch information
g3force authored and TIGERs GitLab committed Jul 13, 2024
1 parent 8ed9db2 commit 59b446f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,19 @@ public static int cap(final int value, final int bound1, final int bound2)
}


/**
* Add a magnitude to the absolute of a value.
*
* @param baseValue the base value
* @param offset the magnitude to add to the absolute of the base value
* @return the result
*/
public static double addMagnitude(double baseValue, double offset)
{
return Math.signum(baseValue) * (Math.abs(baseValue) + offset);
}


/**
* Solves for the real roots of a quadratic equation with real
* coefficients. The quadratic equation is of the form
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,14 @@ public Vector2 projectOntoThis(IVector2 other)
var normalized = normalizeNew();
return normalized.multiply(normalized.scalarProduct(other));
}


@Override
public Vector2 addMagnitude(IVector2 offset)
{
return Vector2.fromXY(
SumatraMath.addMagnitude(x(), offset.x()),
SumatraMath.addMagnitude(y(), offset.y())
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,12 @@ default int getNumDimensions()
* @return
*/
Vector2 projectOntoThis(IVector2 other);

/**
* Add a magnitude to the absolute of this vector.
*
* @param offset the magnitude to add
* @return the result
*/
Vector2 addMagnitude(IVector2 offset);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import edu.tigers.sumatra.math.vector.Vector2;
import edu.tigers.sumatra.math.vector.Vector2f;

import java.util.List;


/**
* This is an immutable representation of a goal.
Expand Down Expand Up @@ -94,6 +96,15 @@ public Vector2f getRightPost()
}


public List<IVector2> getGoalPosts()
{
return List.of(
getLeftPost(),
getRightPost()
);
}


/**
* @return the unbound goal line
*/
Expand Down Expand Up @@ -127,6 +138,15 @@ public IRectangle getRectangle()
}


public List<IVector2> getCorners()
{
return List.of(
leftPost.addMagnitude(Vector2.fromXY(depth, 0)),
rightPost.addMagnitude(Vector2.fromXY(depth, 0))
);
}


/**
* @param point
* @param margin
Expand Down

0 comments on commit 59b446f

Please sign in to comment.