Class AllianceFlipUtil

java.lang.Object
com.marswars.geometry.AllianceFlipUtil

public class AllianceFlipUtil extends Object
Utility class for flipping geometric coordinates between alliance perspectives in FRC. This class provides methods to transform coordinates, poses, and regions based on field symmetry.

The utility supports two types of field symmetry:

  • DIAGONAL - Rotates coordinates 180 degrees around the field center
  • DIRECT - Mirrors coordinates horizontally across the field center

Before using any transformation methods, the field geometry must be configured using configureFieldGeometry(SymmetryType, Translation2d).

  • Constructor Details

    • AllianceFlipUtil

      public AllianceFlipUtil()
  • Method Details

    • configureFieldGeometry

      public static void configureFieldGeometry(AllianceFlipUtil.SymmetryType symmetry, Translation2d field_center)
      Configures the field geometry for alliance coordinate transformations. This method must be called before using any transformation methods.
      Parameters:
      symmetry - the type of field symmetry (DIAGONAL or DIRECT)
      field_center - the center point of the field
    • apply

      public static Translation2d apply(Translation2d translation)
      Applies alliance flip transformation to a 2D translation.
      Parameters:
      translation - the original translation to transform
      Returns:
      the transformed translation from the opposite alliance perspective
      Throws:
      IllegalStateException - if the utility has not been configured
    • apply

      public static Translation3d apply(Translation3d translation)
      Applies alliance flip transformation to a 3D translation.
      Parameters:
      translation - the original 3D translation to transform
      Returns:
      the transformed 3D translation from the opposite alliance perspective
      Throws:
      IllegalStateException - if the utility has not been configured
    • apply

      public static Pose2d apply(Pose2d pose)
      Applies alliance flip transformation to a 2D pose. Transforms both the translation and rotation components.
      Parameters:
      pose - the original 2D pose to transform
      Returns:
      the transformed 2D pose from the opposite alliance perspective
      Throws:
      IllegalStateException - if the utility has not been configured
    • apply

      public static Pose3d apply(Pose3d pose)
      Applies alliance flip transformation to a 3D pose. Transforms both the translation and rotation components.
      Parameters:
      pose - the original 3D pose to transform
      Returns:
      the transformed 3D pose from the opposite alliance perspective
      Throws:
      IllegalStateException - if the utility has not been configured
    • apply

      public static Region apply(Region region)
      Applies alliance flip transformation to a region. Automatically determines the region type and applies the appropriate transformation.
      Parameters:
      region - the original region to transform (PolygonRegion or CircularRegion)
      Returns:
      the transformed region from the opposite alliance perspective
      Throws:
      IllegalStateException - if the utility has not been configured
    • apply

      public static PolygonRegion apply(PolygonRegion region)
      Applies alliance flip transformation to a polygon region. Transforms all vertices of the polygon.
      Parameters:
      region - the original polygon region to transform
      Returns:
      the transformed polygon region from the opposite alliance perspective
      Throws:
      IllegalStateException - if the utility has not been configured
    • apply

      public static CircularRegion apply(CircularRegion region)
      Applies alliance flip transformation to a circular region. Transforms the center point while preserving the radius.
      Parameters:
      region - the original circular region to transform
      Returns:
      the transformed circular region from the opposite alliance perspective
      Throws:
      IllegalStateException - if the utility has not been configured
    • apply

      public static TightRope apply(TightRope tightRope)
      Applies alliance flip transformation to a tight rope path. Transforms both endpoint poses and swaps their order to maintain path direction.
      Parameters:
      tightRope - the original tight rope path to transform
      Returns:
      the transformed tight rope path from the opposite alliance perspective
      Throws:
      IllegalStateException - if the utility has not been configured