Package org.team1126.lib.math
Class Math2
java.lang.Object
org.team1126.lib.math.Math2
General math utilities.
We reinvented math. It's called Math 2.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final double5PI/6(150deg)static final doublePI/2(90deg)static final doublePI/4(45deg)static final doublePI/6(30deg)static final doublePI/3(60deg)static final double3PI/4(135deg)static final doublePI*2(360deg)static final double2PI/3(120deg) -
Method Summary
Modifier and TypeMethodDescriptionstatic edu.wpi.first.math.geometry.Twist2dcopyInto(edu.wpi.first.math.geometry.Twist2d source, edu.wpi.first.math.geometry.Twist2d output) Copies values from a sourceTwist2dobject to another.static edu.wpi.first.math.kinematics.ChassisSpeedscopyInto(edu.wpi.first.math.kinematics.ChassisSpeeds source, edu.wpi.first.math.kinematics.ChassisSpeeds output) Copies values from a sourceChassisSpeedsobject to another.static edu.wpi.first.math.kinematics.SwerveModulePositioncopyInto(edu.wpi.first.math.kinematics.SwerveModulePosition source, edu.wpi.first.math.kinematics.SwerveModulePosition output) Copies values from a sourceSwerveModulePositionobject to another.static edu.wpi.first.math.kinematics.SwerveModuleStatecopyInto(edu.wpi.first.math.kinematics.SwerveModuleState source, edu.wpi.first.math.kinematics.SwerveModuleState output) Copies values from a sourceSwerveModuleStateobject to another.static edu.wpi.first.math.kinematics.ChassisSpeedsdiscretizeChassisSpeeds(edu.wpi.first.math.kinematics.ChassisSpeeds speeds, double dtSeconds) Discretizes continuous-time chassis speeds in place.static booleanisNear(edu.wpi.first.math.geometry.Rotation2d expected, edu.wpi.first.math.geometry.Rotation2d actual, double tolerance) Checks if the angle between twoRotation2ds is within a specified tolerance.static booleanisNear(edu.wpi.first.math.geometry.Translation2d expected, edu.wpi.first.math.geometry.Translation2d actual, double tolerance) Checks if the distance between twoTranslation2ds is within a specified tolerance.static doublerandom(double max) Returns a random double from0.0tomax.static doublerandom(double min, double max) Returns a random double frommintomax.
-
Field Details
-
SIXTH_PI
public static final double SIXTH_PIPI/6(30deg)- See Also:
-
QUARTER_PI
public static final double QUARTER_PIPI/4(45deg)- See Also:
-
THIRD_PI
public static final double THIRD_PIPI/3(60deg)- See Also:
-
HALF_PI
public static final double HALF_PIPI/2(90deg)- See Also:
-
TWO_THIRDS_PI
public static final double TWO_THIRDS_PI2PI/3(120deg)- See Also:
-
THREE_QUARTERS_PI
public static final double THREE_QUARTERS_PI3PI/4(135deg)- See Also:
-
FIVE_SIXTHS_PI
public static final double FIVE_SIXTHS_PI5PI/6(150deg)- See Also:
-
TWO_PI
public static final double TWO_PIPI*2(360deg)- See Also:
-
-
Method Details
-
discretizeChassisSpeeds
public static edu.wpi.first.math.kinematics.ChassisSpeeds discretizeChassisSpeeds(edu.wpi.first.math.kinematics.ChassisSpeeds speeds, double dtSeconds) Discretizes continuous-time chassis speeds in place.- Parameters:
speeds- The continuous speeds.dtSeconds- The duration of the timestep the speeds should be applied for.- Returns:
- The provided speeds object.
- See Also:
-
isNear
public static boolean isNear(edu.wpi.first.math.geometry.Translation2d expected, edu.wpi.first.math.geometry.Translation2d actual, double tolerance) Checks if the distance between twoTranslation2ds is within a specified tolerance.- Parameters:
expected- The expectedTranslation2d.actual- The actualTranslation2d.tolerance- The allowed distance between the actual and the expected translations, in meters.
-
isNear
public static boolean isNear(edu.wpi.first.math.geometry.Rotation2d expected, edu.wpi.first.math.geometry.Rotation2d actual, double tolerance) Checks if the angle between twoRotation2ds is within a specified tolerance.- Parameters:
expected- The expectedRotation2d.actual- The actualRotation2d.tolerance- The allowed difference between the actual and the expected rotations, in radians.
-
random
public static double random(double max) Returns a random double from0.0tomax.- Parameters:
max- The maximum value to return.
-
random
public static double random(double min, double max) Returns a random double frommintomax.- Parameters:
min- The minimum value to return.max- The maximum value to return.
-
copyInto
public static edu.wpi.first.math.geometry.Twist2d copyInto(edu.wpi.first.math.geometry.Twist2d source, edu.wpi.first.math.geometry.Twist2d output) Copies values from a sourceTwist2dobject to another.- Parameters:
source- The twist to copy from.output- The twist to copy into.- Returns:
- The output twist.
-
copyInto
public static edu.wpi.first.math.kinematics.ChassisSpeeds copyInto(edu.wpi.first.math.kinematics.ChassisSpeeds source, edu.wpi.first.math.kinematics.ChassisSpeeds output) Copies values from a sourceChassisSpeedsobject to another.- Parameters:
source- The speeds to copy from.output- The speeds to copy into.- Returns:
- The output speeds.
-
copyInto
public static edu.wpi.first.math.kinematics.SwerveModulePosition copyInto(edu.wpi.first.math.kinematics.SwerveModulePosition source, edu.wpi.first.math.kinematics.SwerveModulePosition output) Copies values from a sourceSwerveModulePositionobject to another.- Parameters:
source- The swerve module position to copy from.output- The swerve module position to copy into.- Returns:
- The output position.
-
copyInto
public static edu.wpi.first.math.kinematics.SwerveModuleState copyInto(edu.wpi.first.math.kinematics.SwerveModuleState source, edu.wpi.first.math.kinematics.SwerveModuleState output) Copies values from a sourceSwerveModuleStateobject to another.- Parameters:
source- The swerve module state to copy from.output- The swerve module state to copy into.- Returns:
- The output state.
-