Rotation2d

Rotation2d represents a rotation in 2D space as a point on the unit circle (cosine, sine).

Key Features

  • Internally tracks radians, sine, and cosine

  • Can be created from radians, degrees, or direction vectors

  • Provides methods for rotating, interpolating, mirroring, and inverting

  • Supports arithmetic operations like addition and scalar multiplication

Why It's Useful

Rotation is fundamental to understanding not just where the robot is, but which way it's facing. Since robots have field-relative vs robot-relative behavior, a consistent rotation representation is key.

Common Use Cases

  • Robot heading tracking: From gyros or IMUs

  • Field-oriented control: Convert joystick commands into field-relative vectors for swerve

  • Vision: Determine the angle between the robot and a target

  • Automation: Determine which side of an object you are on

Useful Methods

For the following methods trans represents an instance of the Translation2d class and rot represts an instance of the Rotation2d class

  • rot.rotateBy(otherRot) - Returns the sum of the 2 angles

  • rot.getDegrees() - Returns the angle in degrees

  • rot.getRadians() - Returns the angle in Radians

Last updated