src/robolib/trajectory/Velocity3d.java: Tweaks

- getSquareMagnitude() returns double in
m^2s^-2 (no pre-defined unit)
- define getVeritcalVelocity() as an alias of getVZ()
This commit is contained in:
Ray Healy 2026-02-10 17:02:07 -05:00
parent 3bd243f689
commit d43b337f1e
1 changed files with 20 additions and 12 deletions

View File

@ -11,7 +11,7 @@ public class Velocity3d {
private final LinearVelocity vY; private final LinearVelocity vY;
private final LinearVelocity vZ; private final LinearVelocity vZ;
private LinearVelocity cache_squareMagnitudeVelocity; private Double cache_squareMagnitudeVelocity;
private LinearVelocity cache_magnitudeVelocity; private LinearVelocity cache_magnitudeVelocity;
private Angle cache_eleveationAngle; private Angle cache_eleveationAngle;
private Angle cache_azimuthAngle; private Angle cache_azimuthAngle;
@ -22,6 +22,7 @@ public class Velocity3d {
this.vY = vY.copy(); this.vY = vY.copy();
this.vZ = vZ.copy(); this.vZ = vZ.copy();
this.cache_squareMagnitudeVelocity = null;
this.cache_magnitudeVelocity = null; this.cache_magnitudeVelocity = null;
this.cache_eleveationAngle = null; this.cache_eleveationAngle = null;
this.cache_azimuthAngle = null; this.cache_azimuthAngle = null;
@ -89,16 +90,16 @@ public class Velocity3d {
/** /**
* @return The squared magnitude of the velocity vector * @return The squared magnitude of the velocity vector in m^2s^-2
*/ */
public LinearVelocity getSquareMagnitude() { public double getSquareMagnitude() {
if(this.cache_squareMagnitudeVelocity == null) { if(this.cache_squareMagnitudeVelocity == null) {
double vX_mps = this.vX.in(Units.MetersPerSecond); double vX_mps = this.vX.in(Units.MetersPerSecond);
double vY_mps = this.vY.in(Units.MetersPerSecond); double vY_mps = this.vY.in(Units.MetersPerSecond);
double vZ_mps = this.vZ.in(Units.MetersPerSecond); double vZ_mps = this.vZ.in(Units.MetersPerSecond);
this.cache_magnitudeVelocity = Units.MetersPerSecond.of( this.cache_squareMagnitudeVelocity = Math.pow(vX_mps, 2) +
Math.pow(vX_mps, 2) + Math.pow(vY_mps, 2) + Math.pow(vZ_mps, 2) Math.pow(vY_mps, 2) +
); Math.pow(vZ_mps, 2);
} }
return this.cache_squareMagnitudeVelocity; return this.cache_squareMagnitudeVelocity;
} }
@ -109,7 +110,7 @@ public class Velocity3d {
public LinearVelocity getMagnitude() { public LinearVelocity getMagnitude() {
if(this.cache_magnitudeVelocity == null) { if(this.cache_magnitudeVelocity == null) {
this.cache_magnitudeVelocity = Units.MetersPerSecond.of(Math.pow( this.cache_magnitudeVelocity = Units.MetersPerSecond.of(Math.pow(
this.getSquareMagnitude().in(Units.MetersPerSecond), 0.5 this.getSquareMagnitude(), 0.5
)); ));
} }
return this.cache_magnitudeVelocity; return this.cache_magnitudeVelocity;
@ -120,9 +121,16 @@ public class Velocity3d {
// Cylindrical Coordinate getters // Cylindrical Coordinate getters
// //
/**
* @return The magnitude of the vertical component of the velocity (alias of this.getVZ())
*/
public LinearVelocity getVeritcalVelocity() {
return this.getVZ();
}
/** /**
* @return The the magnitude of the horizontal component of the velocity * @return The magnitude of the horizontal component of the velocity
*/ */
public LinearVelocity getHorizontalVelocity() { public LinearVelocity getHorizontalVelocity() {
if (this.cache_horizontalVelocity == null) { if (this.cache_horizontalVelocity == null) {