Package jsim.core
Class Vec3
java.lang.Object
jsim.core.Vec3
Internal 3-component vector math over raw doubles for deterministic physics.
-
Method Summary
Modifier and TypeMethodDescriptionstatic double[]add(double[] a, double[] b) Returnsa + bas a new vector.static voidaddScaled(double[] a, double[] b, double s) Addsb * sintoain-place.static double[]cross(double[] a, double[] b) Returns the cross producta × b.static doubledot(double[] a, double[] b) Returns the dot producta · b.static double[]fromTranslation(edu.wpi.first.math.geometry.Translation3d t) Converts aTranslation3dto a raw double array.static doublelength(double[] a) Returns the length ofa.static doublelengthSq(double[] a) Returns the squared length ofa.static double[]negate(double[] a) Returns-aas a new vector.static double[]normalize(double[] a) Returns a unit vector in the direction ofa, or zero ifais 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) Returnsa * sas a new vector.static double[]sub(double[] a, double[] b) Returnsa - bas a new vector.static edu.wpi.first.math.geometry.Translation3dtoTranslation(double[] v) Converts a raw double array to aTranslation3d.
-
Method Details
-
of
public static double[] of(double x, double y, double z) Returns a new vector[x, y, z].- Parameters:
x- the x componenty- the y componentz- the z component- Returns:
- a new 3-element double array
-
fromTranslation
public static double[] fromTranslation(edu.wpi.first.math.geometry.Translation3d t) Converts aTranslation3dto 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 aTranslation3d.- Parameters:
v- the 3-element vector to convert- Returns:
- a
Translation3dwith the same components
-
cross
public static double[] cross(double[] a, double[] b) Returns the cross producta × b.- Parameters:
a- the left-hand vectorb- the right-hand vector- Returns:
- a new vector representing
a × b
-
dot
public static double dot(double[] a, double[] b) Returns the dot producta · b.- Parameters:
a- the left-hand vectorb- the right-hand vector- Returns:
- the scalar dot product
-
add
public static double[] add(double[] a, double[] b) Returnsa + bas a new vector.- Parameters:
a- the first vectorb- the second vector- Returns:
- a new vector representing the sum
-
sub
public static double[] sub(double[] a, double[] b) Returnsa - bas a new vector.- Parameters:
a- the vector to subtract fromb- the vector to subtract- Returns:
- a new vector representing the difference
-
scale
public static double[] scale(double[] a, double s) Returnsa * sas a new vector.- Parameters:
a- the vector to scales- the scalar multiplier- Returns:
- a new scaled vector
-
lengthSq
public static double lengthSq(double[] a) Returns the squared length ofa.- Parameters:
a- the vector- Returns:
- the squared Euclidean length
-
length
public static double length(double[] a) Returns the length ofa.- Parameters:
a- the vector- Returns:
- the Euclidean length
-
normalize
public static double[] normalize(double[] a) Returns a unit vector in the direction ofa, or zero ifais 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) Addsb * sintoain-place.- Parameters:
a- the vector to accumulate intob- the vector to scale and adds- the scalar multiplier
-
negate
public static double[] negate(double[] a) Returns-aas a new vector.- Parameters:
a- the vector to negate- Returns:
- a new vector with all components negated
-