Package jsim.core

Class Vec3

java.lang.Object
jsim.core.Vec3

public final class Vec3 extends Object
Internal 3-component vector math over raw doubles for deterministic physics.
  • Method Summary

    Modifier and Type
    Method
    Description
    static double[]
    add(double[] a, double[] b)
    Returns a + b as a new vector.
    static void
    addScaled(double[] a, double[] b, double s)
    Adds b * s into a in-place.
    static double[]
    cross(double[] a, double[] b)
    Returns the cross product a × b.
    static double
    dot(double[] a, double[] b)
    Returns the dot product a · b.
    static double[]
    fromTranslation(edu.wpi.first.math.geometry.Translation3d t)
    Converts a Translation3d to a raw double array.
    static double
    length(double[] a)
    Returns the length of a.
    static double
    lengthSq(double[] a)
    Returns the squared length of a.
    static double[]
    negate(double[] a)
    Returns -a as a new vector.
    static double[]
    normalize(double[] a)
    Returns a unit vector in the direction of a, or zero if a is near-zero.
    static double[]
    of(double x, double y, double z)
    Returns a new vector [x, y, z].
    static double[]
    scale(double[] a, double s)
    Returns a * s as a new vector.
    static double[]
    sub(double[] a, double[] b)
    Returns a - b as a new vector.
    static edu.wpi.first.math.geometry.Translation3d
    toTranslation(double[] v)
    Converts a raw double array to a Translation3d.

    Methods inherited from class java.lang.Object

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

    • of

      public static double[] of(double x, double y, double z)
      Returns a new vector [x, y, z].
      Parameters:
      x - the x component
      y - the y component
      z - the z component
      Returns:
      a new 3-element double array
    • fromTranslation

      public static double[] fromTranslation(edu.wpi.first.math.geometry.Translation3d t)
      Converts a Translation3d to a raw double array.
      Parameters:
      t - the translation to convert
      Returns:
      a new 3-element double array [x, y, z]
    • toTranslation

      public static edu.wpi.first.math.geometry.Translation3d toTranslation(double[] v)
      Converts a raw double array to a Translation3d.
      Parameters:
      v - the 3-element vector to convert
      Returns:
      a Translation3d with the same components
    • cross

      public static double[] cross(double[] a, double[] b)
      Returns the cross product a × b.
      Parameters:
      a - the left-hand vector
      b - the right-hand vector
      Returns:
      a new vector representing a × b
    • dot

      public static double dot(double[] a, double[] b)
      Returns the dot product a · b.
      Parameters:
      a - the left-hand vector
      b - the right-hand vector
      Returns:
      the scalar dot product
    • add

      public static double[] add(double[] a, double[] b)
      Returns a + b as a new vector.
      Parameters:
      a - the first vector
      b - the second vector
      Returns:
      a new vector representing the sum
    • sub

      public static double[] sub(double[] a, double[] b)
      Returns a - b as a new vector.
      Parameters:
      a - the vector to subtract from
      b - the vector to subtract
      Returns:
      a new vector representing the difference
    • scale

      public static double[] scale(double[] a, double s)
      Returns a * s as a new vector.
      Parameters:
      a - the vector to scale
      s - the scalar multiplier
      Returns:
      a new scaled vector
    • lengthSq

      public static double lengthSq(double[] a)
      Returns the squared length of a.
      Parameters:
      a - the vector
      Returns:
      the squared Euclidean length
    • length

      public static double length(double[] a)
      Returns the length of a.
      Parameters:
      a - the vector
      Returns:
      the Euclidean length
    • normalize

      public static double[] normalize(double[] a)
      Returns a unit vector in the direction of a, or zero if a is near-zero.
      Parameters:
      a - the vector to normalize
      Returns:
      a new unit vector, or [0, 0, 0] if the input length is below 1e-12
    • addScaled

      public static void addScaled(double[] a, double[] b, double s)
      Adds b * s into a in-place.
      Parameters:
      a - the vector to accumulate into
      b - the vector to scale and add
      s - the scalar multiplier
    • negate

      public static double[] negate(double[] a)
      Returns -a as a new vector.
      Parameters:
      a - the vector to negate
      Returns:
      a new vector with all components negated