Skip to content

Commit 2827584

Browse files
committed
add expressions for cross() and dot()
1 parent 19d3fe0 commit 2827584

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

gtsam/slam/expressions.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ inline Line3_ transformTo(const Pose3_ &wTc, const Line3_ &wL) {
4848
return Line3_(f, wTc, wL);
4949
}
5050

51+
inline Point3_ cross(const Point3_& a, const Point3_& b) {
52+
Point3 (*f)(const Point3 &, const Point3 &,
53+
OptionalJacobian<3, 3>, OptionalJacobian<3, 3>) = &cross;
54+
return Point3_(f, a, b);
55+
}
56+
57+
inline Double_ dot(const Point3_& a, const Point3_& b) {
58+
double (*f)(const Point3 &, const Point3 &,
59+
OptionalJacobian<1, 3>, OptionalJacobian<1, 3>) = &dot;
60+
return Double_(f, a, b);
61+
}
62+
5163
namespace internal {
5264
// define getter that returns value rather than reference
5365
inline Rot3 rotation(const Pose3& pose, OptionalJacobian<3, 6> H) {

tests/testExpressionFactor.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,39 @@ TEST(ExpressionFactor, variadicTemplate) {
727727
}
728728

729729

730+
TEST(ExpressionFactor, crossProduct) {
731+
auto model = noiseModel::Isotropic::Sigma(3, 1);
732+
733+
// Create expression
734+
const auto a = Vector3_(1);
735+
const auto b = Vector3_(2);
736+
Vector3_ f_expr = cross(a, b);
737+
738+
// Check derivatives
739+
Values values;
740+
values.insert(1, Vector3(0.1, 0.2, 0.3));
741+
values.insert(2, Vector3(0.4, 0.5, 0.6));
742+
ExpressionFactor<Vector3> factor(model, Vector3::Zero(), f_expr);
743+
EXPECT_CORRECT_FACTOR_JACOBIANS(factor, values, 1e-5, 1e-5);
744+
}
745+
746+
TEST(ExpressionFactor, dotProduct) {
747+
auto model = noiseModel::Isotropic::Sigma(1, 1);
748+
749+
// Create expression
750+
const auto a = Vector3_(1);
751+
const auto b = Vector3_(2);
752+
Double_ f_expr = dot(a, b);
753+
754+
// Check derivatives
755+
Values values;
756+
values.insert(1, Vector3(0.1, 0.2, 0.3));
757+
values.insert(2, Vector3(0.4, 0.5, 0.6));
758+
ExpressionFactor<double> factor(model, .0, f_expr);
759+
EXPECT_CORRECT_FACTOR_JACOBIANS(factor, values, 1e-5, 1e-5);
760+
}
761+
762+
730763
/* ************************************************************************* */
731764
int main() {
732765
TestResult tr;

0 commit comments

Comments
 (0)