Skip to content

Commit 0e62589

Browse files
achim-kViktor Kunovski
authored andcommitted
Add some utility functions to math/Pose. (#294)
* Add multiply method to math/Pose. * Add getInverse function to math/Pose.
1 parent b994d30 commit 0e62589

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/math/Pose.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,30 @@ Pose.prototype.clone = function() {
4343
return new Pose(this);
4444
};
4545

46+
/**
47+
* Multiplies this pose with another pose without altering this pose.
48+
*
49+
* @returns Result of multiplication.
50+
*/
51+
Pose.prototype.multiply = function(pose) {
52+
var p = pose.clone();
53+
p.applyTransform({ rotation: this.orientation, translation: this.position });
54+
return p;
55+
};
56+
57+
/**
58+
* Computes the inverse of this pose.
59+
*
60+
* @returns Inverse of pose.
61+
*/
62+
Pose.prototype.getInverse = function() {
63+
var inverse = this.clone();
64+
inverse.orientation.invert();
65+
inverse.position.multiplyQuaternion(inverse.orientation);
66+
inverse.position.x *= -1;
67+
inverse.position.y *= -1;
68+
inverse.position.z *= -1;
69+
return inverse;
70+
};
71+
4672
module.exports = Pose;

0 commit comments

Comments
 (0)