mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-27 02:01:42 +00:00
[wpimath] Replace constexpr coeff() and coeffRef() with operator() (#7391)
This commit is contained in:
@@ -35,12 +35,10 @@ class WPILIB_DLLEXPORT CoordinateSystem {
|
||||
// the NWU coordinate system. Each column vector in the change of basis
|
||||
// matrix is one of the old basis vectors mapped to its representation in
|
||||
// the new basis.
|
||||
Eigen::Matrix3d R{{positiveX.m_axis.coeff(0), positiveY.m_axis.coeff(0),
|
||||
positiveZ.m_axis.coeff(0)},
|
||||
{positiveX.m_axis.coeff(1), positiveY.m_axis.coeff(1),
|
||||
positiveZ.m_axis.coeff(1)},
|
||||
{positiveX.m_axis.coeff(2), positiveY.m_axis.coeff(2),
|
||||
positiveZ.m_axis.coeff(2)}};
|
||||
Eigen::Matrix3d R{
|
||||
{positiveX.m_axis(0), positiveY.m_axis(0), positiveZ.m_axis(0)},
|
||||
{positiveX.m_axis(1), positiveY.m_axis(1), positiveZ.m_axis(1)},
|
||||
{positiveX.m_axis(2), positiveY.m_axis(2), positiveZ.m_axis(2)}};
|
||||
|
||||
// The change of basis matrix should be a pure rotation. The Rotation3d
|
||||
// constructor will verify this by checking for special orthogonality.
|
||||
|
||||
@@ -281,9 +281,9 @@ constexpr Eigen::Matrix3d RotationVectorToMatrix(
|
||||
// [ 0 -c b]
|
||||
// Omega = [ c 0 -a]
|
||||
// [-b a 0]
|
||||
return Eigen::Matrix3d{{0.0, -rotation.coeff(2), rotation.coeff(1)},
|
||||
{rotation.coeff(2), 0.0, -rotation.coeff(0)},
|
||||
{-rotation.coeff(1), rotation.coeff(0), 0.0}};
|
||||
return Eigen::Matrix3d{{0.0, -rotation(2), rotation(1)},
|
||||
{rotation(2), 0.0, -rotation(0)},
|
||||
{-rotation(1), rotation(0), 0.0}};
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
@@ -299,7 +299,7 @@ class WPILIB_DLLEXPORT Quaternion {
|
||||
// 𝑞 = std::cos(θ/2) + std::sin(θ/2) * v̂
|
||||
// 𝑞 = std::cos(θ/2) + std::sin(θ/2) / θ * 𝑣⃗
|
||||
|
||||
double theta = gcem::hypot(rvec.coeff(0), rvec.coeff(1), rvec.coeff(2));
|
||||
double theta = gcem::hypot(rvec(0), rvec(1), rvec(2));
|
||||
double cos = gcem::cos(theta / 2);
|
||||
|
||||
double axial_scalar;
|
||||
@@ -312,9 +312,8 @@ class WPILIB_DLLEXPORT Quaternion {
|
||||
axial_scalar = gcem::sin(theta / 2) / theta;
|
||||
}
|
||||
|
||||
return Quaternion{cos, axial_scalar * rvec.coeff(0),
|
||||
axial_scalar * rvec.coeff(1),
|
||||
axial_scalar * rvec.coeff(2)};
|
||||
return Quaternion{cos, axial_scalar * rvec(0), axial_scalar * rvec(1),
|
||||
axial_scalar * rvec(2)};
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -85,11 +85,10 @@ class WPILIB_DLLEXPORT Rotation3d {
|
||||
}
|
||||
|
||||
// https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles#Definition
|
||||
Eigen::Vector3d v{{axis.coeff(0) / norm * units::math::sin(angle / 2.0),
|
||||
axis.coeff(1) / norm * units::math::sin(angle / 2.0),
|
||||
axis.coeff(2) / norm * units::math::sin(angle / 2.0)}};
|
||||
m_q = Quaternion{units::math::cos(angle / 2.0), v.coeff(0), v.coeff(1),
|
||||
v.coeff(2)};
|
||||
Eigen::Vector3d v{{axis(0) / norm * units::math::sin(angle / 2.0),
|
||||
axis(1) / norm * units::math::sin(angle / 2.0),
|
||||
axis(2) / norm * units::math::sin(angle / 2.0)}};
|
||||
m_q = Quaternion{units::math::cos(angle / 2.0), v(0), v(1), v(2)};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,9 +190,9 @@ class WPILIB_DLLEXPORT Rotation3d {
|
||||
// rotation is required. Any other vector can be used to generate an
|
||||
// orthogonal one.
|
||||
|
||||
double x = gcem::abs(initial.coeff(0));
|
||||
double y = gcem::abs(initial.coeff(1));
|
||||
double z = gcem::abs(initial.coeff(2));
|
||||
double x = gcem::abs(initial(0));
|
||||
double y = gcem::abs(initial(1));
|
||||
double z = gcem::abs(initial(2));
|
||||
|
||||
// Find vector that is most orthogonal to initial vector
|
||||
Eigen::Vector3d other;
|
||||
|
||||
@@ -60,8 +60,7 @@ class WPILIB_DLLEXPORT Translation2d {
|
||||
* @param vector The translation vector to represent.
|
||||
*/
|
||||
constexpr explicit Translation2d(const Eigen::Vector2d& vector)
|
||||
: m_x{units::meter_t{vector.coeff(0)}},
|
||||
m_y{units::meter_t{vector.coeff(1)}} {}
|
||||
: m_x{units::meter_t{vector(0)}}, m_y{units::meter_t{vector(1)}} {}
|
||||
|
||||
/**
|
||||
* Calculates the distance between two translations in 2D space.
|
||||
|
||||
Reference in New Issue
Block a user