Class XYPair

java.lang.Object
xbot.common.math.XYPair
All Implemented Interfaces:
StructSerializable, WPISerializable

public class XYPair extends Object implements StructSerializable
Pair of X and Y coordinates. Can be used for points, vectors, or anything else that requires a coordinate pair.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final XYPairStruct
    Translation2d struct for serialization.
    double
     
    double
     
    static final XYPair
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a coordinate at the origin.
    XYPair(double x, double y)
    Create a coordinate with the specified x and y value.
    XYPair(Rotation2d rotation)
    Creates a coordinate representing the unit vector for a rotation.
  • Method Summary

    Modifier and Type
    Method
    Description
    add(XYPair pair)
    Adds the value of a second coordinate to the current coordinate.
    addMagnitude(double magnitudeToAdd)
    Add the magnitude to the vector represented by the coordinate.
    Clone the object
    double
    dotProduct(XYPair otherPoint)
    Calculate the dot-product between this and another point.
    static XYPair
    fromPolar(double angle, double magnitude)
    Create a coordinate from an angle and magnitude
    static XYPair
    fromUnitPolar(double angle)
    Create a coordinate of magnitude 1 with an angle
    double
    Get the angle of the vector in degrees
    double
    Get the distance between the current point and a second point.
    double
    Get the magnitude of the vector (i.e.
    rotate(double angle)
    Rotates the vector by a given angle.
    scale(double scalarMagnitude)
    Scales the current coordinate by a magnitude equally in both dimensions.
    scale(double xMagnitude, double yMagnitude)
    Scales the coordinate by an x- and y- magnitude.
     
     

    Methods inherited from class java.lang.Object

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

    • ZERO

      public static final XYPair ZERO
    • x

      public double x
    • y

      public double y
    • struct

      public static final XYPairStruct struct
      Translation2d struct for serialization.
  • Constructor Details

    • XYPair

      public XYPair(double x, double y)
      Create a coordinate with the specified x and y value.
      Parameters:
      x - the x value to use
      y - the y value to use
    • XYPair

      public XYPair(Rotation2d rotation)
      Creates a coordinate representing the unit vector for a rotation.
      Parameters:
      rotation - The rotation value.
    • XYPair

      public XYPair()
      Create a coordinate at the origin.
  • Method Details

    • clone

      public XYPair clone()
      Clone the object
      Overrides:
      clone in class Object
    • fromPolar

      public static XYPair fromPolar(double angle, double magnitude)
      Create a coordinate from an angle and magnitude
      Parameters:
      angle - angle in degrees
      magnitude - magnitude
      Returns:
      coordinate
    • fromUnitPolar

      public static XYPair fromUnitPolar(double angle)
      Create a coordinate of magnitude 1 with an angle
      Parameters:
      angle - angle in degrees
      Returns:
      coordinate
    • scale

      public XYPair scale(double scalarMagnitude)
      Scales the current coordinate by a magnitude equally in both dimensions.
      Parameters:
      scalarMagnitude - the magnitude to scale the coordinate by
      Returns:
      the scaled object
    • scale

      public XYPair scale(double xMagnitude, double yMagnitude)
      Scales the coordinate by an x- and y- magnitude.
      Parameters:
      xMagnitude - the magnitude to scale the x-coordinate by
      yMagnitude - the magnitude to scale the y-coordinate by
      Returns:
      the scaled object
    • addMagnitude

      public XYPair addMagnitude(double magnitudeToAdd)
      Add the magnitude to the vector represented by the coordinate.
      Parameters:
      magnitudeToAdd - magnitude to add
      Returns:
      the modified coordinate
    • rotate

      public XYPair rotate(double angle)
      Rotates the vector by a given angle.
      Parameters:
      angle - the angle in degrees to rotate the pair by
      Returns:
      the rotated object
    • getAngle

      public double getAngle()
      Get the angle of the vector in degrees
      Returns:
      angle in degrees
    • getMagnitude

      public double getMagnitude()
      Get the magnitude of the vector (i.e. distance from origin to the coordinate).
      Returns:
      magnitude
    • add

      public XYPair add(XYPair pair)
      Adds the value of a second coordinate to the current coordinate.
      Parameters:
      pair - coordinate to add
      Returns:
      the combined object
    • getDistanceToPoint

      public double getDistanceToPoint(XYPair otherPoint)
      Get the distance between the current point and a second point.
      Parameters:
      otherPoint - the point to calculate the distance from
      Returns:
      the distance
    • dotProduct

      public double dotProduct(XYPair otherPoint)
      Calculate the dot-product between this and another point.
      Parameters:
      otherPoint - the second point to use for calculating dot product
      Returns:
      the dot product value
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toTranslation2d

      public Translation2d toTranslation2d()