Class Math2

java.lang.Object
org.team1126.lib.math.Math2

public final class Math2 extends Object
General math utilities. We reinvented math. It's called Math 2.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    5PI/6 (150deg)
    static final double
    PI/2 (90deg)
    static final double
    PI/4 (45deg)
    static final double
    PI/6 (30deg)
    static final double
    PI/3 (60deg)
    static final double
    3PI/4 (135deg)
    static final double
    PI*2 (360deg)
    static final double
    2PI/3 (120deg)
  • Method Summary

    Modifier and Type
    Method
    Description
    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 source Twist2d object to another.
    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 source ChassisSpeeds object to another.
    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 source SwerveModulePosition object to another.
    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 source SwerveModuleState object to another.
    static edu.wpi.first.math.kinematics.ChassisSpeeds
    discretizeChassisSpeeds(edu.wpi.first.math.kinematics.ChassisSpeeds speeds, double dtSeconds)
    Discretizes continuous-time chassis speeds in place.
    static boolean
    isNear(edu.wpi.first.math.geometry.Rotation2d expected, edu.wpi.first.math.geometry.Rotation2d actual, double tolerance)
    Checks if the angle between two Rotation2ds is within a specified tolerance.
    static boolean
    isNear(edu.wpi.first.math.geometry.Translation2d expected, edu.wpi.first.math.geometry.Translation2d actual, double tolerance)
    Checks if the distance between two Translation2ds is within a specified tolerance.
    static double
    random(double max)
    Returns a random double from 0.0 to max.
    static double
    random(double min, double max)
    Returns a random double from min to max.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • 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:
      • ChassisSpeeds.discretize(ChassisSpeeds, double)
    • 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 two Translation2ds is within a specified tolerance.
      Parameters:
      expected - The expected Translation2d.
      actual - The actual Translation2d.
      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 two Rotation2ds is within a specified tolerance.
      Parameters:
      expected - The expected Rotation2d.
      actual - The actual Rotation2d.
      tolerance - The allowed difference between the actual and the expected rotations, in radians.
    • random

      public static double random(double max)
      Returns a random double from 0.0 to max.
      Parameters:
      max - The maximum value to return.
    • random

      public static double random(double min, double max)
      Returns a random double from min to max.
      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 source Twist2d object 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 source ChassisSpeeds object 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 source SwerveModulePosition object 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 source SwerveModuleState object to another.
      Parameters:
      source - The swerve module state to copy from.
      output - The swerve module state to copy into.
      Returns:
      The output state.