Class Polar

java.lang.Object
me.autobot.lib.math.coordinates.Polar

public class Polar extends Object
Polar coordinates represent a vector by its magnitude and the angle it makes with the x-axis.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Polar(double r, Rotation2d theta)
    Constructs a Polar object with the given magnitude and angle.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    cos()
    Returns the x-component of the vector, calculated as r * cos(theta).
    double
    Returns the angle of the vector in degrees.
    double
    Returns the magnitude of the vector (the radius value).
    double
    Returns the angle of the vector in radians.
    Returns the angle of the vector.
    Returns the inverse of the vector, with the same magnitude and the opposite angle.
    Gets the normal of the vector, with the same magnitude (this implies a 90 degree rotation).
    Rotates the vector by the given angle.
    void
    setR(double r)
    Sets the magnitude of the vector (the radius value).
    void
    Sets the angle of the vector.
    double
    sin()
    Returns the y-component of the vector, calculated as r * sin(theta).
    double
    tan()
    Returns the tangent of the vector, calculated as sin(theta) / cos(theta).
    Converts the Polar object to a Vector2d object.

    Methods inherited from class java.lang.Object

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

    • Polar

      public Polar(double r, Rotation2d theta)
      Constructs a Polar object with the given magnitude and angle.
      Parameters:
      r - The magnitude of the vector. This is the distance from the origin to the point.
      theta - The angle of the vector. This is the angle the vector makes with the x-axis.
  • Method Details

    • getR

      public double getR()
      Returns the magnitude of the vector (the radius value).
      Returns:
      The magnitude of the vector.
    • setR

      public void setR(double r)
      Sets the magnitude of the vector (the radius value).
      Parameters:
      r - The new magnitude of the vector.
    • getTheta

      public Rotation2d getTheta()
      Returns the angle of the vector.
      Returns:
      The angle of the vector.
    • setTheta

      public void setTheta(Rotation2d theta)
      Sets the angle of the vector.
      Parameters:
      theta - The new angle of the vector.
    • rotateBy

      public Polar rotateBy(Rotation2d other)
      Rotates the vector by the given angle.
      Parameters:
      other - The angle by which to rotate the vector.
      Returns:
      The vector rotated by the given angle.
    • normal

      public Polar normal()
      Gets the normal of the vector, with the same magnitude (this implies a 90 degree rotation).
      Returns:
      The normal of the vector.
    • inverse

      public Polar inverse()
      Returns the inverse of the vector, with the same magnitude and the opposite angle.
      Returns:
      The inverse of the vector.
    • cos

      public double cos()
      Returns the x-component of the vector, calculated as r * cos(theta).
      Returns:
      The x-component of the vector (cos(theta) * r).
    • sin

      public double sin()
      Returns the y-component of the vector, calculated as r * sin(theta).
      Returns:
      The y-component of the vector (sin(theta) * r).
    • tan

      public double tan()
      Returns the tangent of the vector, calculated as sin(theta) / cos(theta).
      Returns:
      The tangent of the vector (sin(theta) / cos(theta)).
    • getRadians

      public double getRadians()
      Returns the angle of the vector in radians.
      Returns:
      The angle of the vector in radians.
    • getDegrees

      public double getDegrees()
      Returns the angle of the vector in degrees.
      Returns:
      The angle of the vector in degrees.
    • toVector

      public Vector2d toVector()
      Converts the Polar object to a Vector2d object.
      Returns:
      The Vector2d object equivalent to the Polar object.