mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[wpimath] Add Rotation3d rotation vector getter (#7564)
The code churn in Java is just making the function order consistent between languages.
This commit is contained in:
@@ -459,6 +459,32 @@ public class Rotation3d
|
||||
return Radians.of(getZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the axis in the axis-angle representation of this rotation.
|
||||
*
|
||||
* @return The axis in the axis-angle representation.
|
||||
*/
|
||||
public Vector<N3> getAxis() {
|
||||
double norm =
|
||||
Math.sqrt(m_q.getX() * m_q.getX() + m_q.getY() * m_q.getY() + m_q.getZ() * m_q.getZ());
|
||||
if (norm == 0.0) {
|
||||
return VecBuilder.fill(0.0, 0.0, 0.0);
|
||||
} else {
|
||||
return VecBuilder.fill(m_q.getX() / norm, m_q.getY() / norm, m_q.getZ() / norm);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the angle in radians in the axis-angle representation of this rotation.
|
||||
*
|
||||
* @return The angle in radians in the axis-angle representation of this rotation.
|
||||
*/
|
||||
public double getAngle() {
|
||||
double norm =
|
||||
Math.sqrt(m_q.getX() * m_q.getX() + m_q.getY() * m_q.getY() + m_q.getZ() * m_q.getZ());
|
||||
return 2.0 * Math.atan2(norm, m_q.getW());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns rotation matrix representation of this rotation.
|
||||
*
|
||||
@@ -486,29 +512,12 @@ public class Rotation3d
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the axis in the axis-angle representation of this rotation.
|
||||
* Returns rotation vector representation of this rotation.
|
||||
*
|
||||
* @return The axis in the axis-angle representation.
|
||||
* @return Rotation vector representation of this rotation.
|
||||
*/
|
||||
public Vector<N3> getAxis() {
|
||||
double norm =
|
||||
Math.sqrt(m_q.getX() * m_q.getX() + m_q.getY() * m_q.getY() + m_q.getZ() * m_q.getZ());
|
||||
if (norm == 0.0) {
|
||||
return VecBuilder.fill(0.0, 0.0, 0.0);
|
||||
} else {
|
||||
return VecBuilder.fill(m_q.getX() / norm, m_q.getY() / norm, m_q.getZ() / norm);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the angle in radians in the axis-angle representation of this rotation.
|
||||
*
|
||||
* @return The angle in radians in the axis-angle representation of this rotation.
|
||||
*/
|
||||
public double getAngle() {
|
||||
double norm =
|
||||
Math.sqrt(m_q.getX() * m_q.getX() + m_q.getY() * m_q.getY() + m_q.getZ() * m_q.getZ());
|
||||
return 2.0 * Math.atan2(norm, m_q.getW());
|
||||
public Vector<N3> toVector() {
|
||||
return m_q.toRotationVector();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -125,7 +125,7 @@ public class Odometry3d<T> {
|
||||
*/
|
||||
public Pose3d update(Rotation3d gyroAngle, T wheelPositions) {
|
||||
var angle = gyroAngle.plus(m_gyroOffset);
|
||||
var angle_difference = angle.minus(m_previousAngle).getQuaternion().toRotationVector();
|
||||
var angle_difference = angle.minus(m_previousAngle).toVector();
|
||||
|
||||
var twist2d = m_kinematics.toTwist2d(m_previousWheelPositions, wheelPositions);
|
||||
var twist =
|
||||
|
||||
Reference in New Issue
Block a user