[wpimath] Quaternion::Log(): Remove duplicate calls to norm() (#6358)

This commit is contained in:
Thad House
2024-02-10 10:41:19 -08:00
committed by GitHub
parent 300419c151
commit e9c744c456
2 changed files with 6 additions and 4 deletions

View File

@@ -285,11 +285,12 @@ public class Quaternion implements ProtobufSerializable, StructSerializable {
* @return The logarithm of this quaternion.
*/
public Quaternion log() {
var scalar = Math.log(norm());
var norm = norm();
var scalar = Math.log(norm);
var v_norm = Math.sqrt(getX() * getX() + getY() * getY() + getZ() * getZ());
var s_norm = getW() / norm();
var s_norm = getW() / norm;
if (Math.abs(s_norm + 1) < 1e-9) {
return new Quaternion(scalar, -Math.PI, 0, 0);

View File

@@ -136,11 +136,12 @@ Quaternion Quaternion::Log(const Quaternion& other) const {
}
Quaternion Quaternion::Log() const {
double scalar = std::log(Norm());
double norm = Norm();
double scalar = std::log(norm);
double v_norm = m_v.norm();
double s_norm = W() / Norm();
double s_norm = W() / norm;
if (std::abs(s_norm + 1) < 1e-9) {
return Quaternion{scalar, -std::numbers::pi, 0, 0};