Skip to content

Commit 0b34f6d

Browse files
srmainwaringazeey
authored andcommitted
Correct calculation in ProjectPointToPlane (#702)
Use unit normal for projection. Update InterpolatePointTest to capture projection edges cases - Resize the sample grid and add a gradient to the field to check projection normalisation. Signed-off-by: Rhys Mainwaring <[email protected]> Co-authored-by: Addisu Z. Taddese <[email protected]> (cherry picked from commit 06d73ac)
1 parent 89d1ff7 commit 0b34f6d

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

include/gz/math/detail/InterpolationPoint.hh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,9 @@ namespace gz::math
211211
(_points[_start_index + 1].position - _points[_start_index].position)
212212
.Cross(
213213
_points[_start_index + 2].position - _points[_start_index].position);
214+
auto n_unit = n.Normalized();
214215
return
215-
_pos - n.Dot(_pos - _points[_start_index].position) * n.Normalized();
216+
_pos - n_unit.Dot(_pos - _points[_start_index].position) * n_unit;
216217
}
217218

218219
/// \brief Trilinear interpolation of eight points in 3D space. It assumes

src/InterpolationPoint_TEST.cc

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,26 +86,26 @@ TEST(Interpolation, TrilinearInterpolate)
8686
{
8787
std::vector<InterpolationPoint3D<double>> vec {
8888
InterpolationPoint3D<double>{Vector3d{0, 0, 0}, 0},
89-
InterpolationPoint3D<double>{Vector3d{1, 0, 0}, 1},
90-
InterpolationPoint3D<double>{Vector3d{0, 1, 0}, 2},
91-
InterpolationPoint3D<double>{Vector3d{1, 1, 0}, 3},
92-
InterpolationPoint3D<double>{Vector3d{0, 0, 1}, 4},
93-
InterpolationPoint3D<double>{Vector3d{1, 0, 1}, 5},
94-
InterpolationPoint3D<double>{Vector3d{0, 1, 1}, 6},
95-
InterpolationPoint3D<double>{Vector3d{1, 1, 1}, 7},
89+
InterpolationPoint3D<double>{Vector3d{2, 0, 0}, 1},
90+
InterpolationPoint3D<double>{Vector3d{0, 2, 0}, 2},
91+
InterpolationPoint3D<double>{Vector3d{2, 2, 0}, 3},
92+
InterpolationPoint3D<double>{Vector3d{0, 0, 2}, 4},
93+
InterpolationPoint3D<double>{Vector3d{2, 0, 2}, 5},
94+
InterpolationPoint3D<double>{Vector3d{0, 2, 2}, 6},
95+
InterpolationPoint3D<double>{Vector3d{2, 2, 2}, 7},
9696
};
9797

98-
std::vector<double> values {0, 0, 0, 0, 1, 1, 1, 1};
98+
std::vector<double> values {0, 0, 0, 0, 1, 1, 2, 2};
9999

100-
auto v0 = TrilinearInterpolate(vec, values, Vector3d{0.5, 0.5, 0.5});
101-
EXPECT_NEAR(v0, 0.5, 1e-3);
100+
auto v0 = TrilinearInterpolate(vec, values, Vector3d{1, 1, 1});
101+
EXPECT_NEAR(v0, 0.75, 1e-3);
102102

103-
auto v1 = TrilinearInterpolate(vec, values, Vector3d{0.5, 0.5, 0});
103+
auto v1 = TrilinearInterpolate(vec, values, Vector3d{1, 1, 0});
104104
EXPECT_NEAR(v1, 0, 1e-3);
105105

106-
auto v2 = TrilinearInterpolate(vec, values, Vector3d{0.5, 0.5, 1});
107-
EXPECT_NEAR(v2, 1, 1e-3);
106+
auto v2 = TrilinearInterpolate(vec, values, Vector3d{1, 1, 2});
107+
EXPECT_NEAR(v2, 1.5, 1e-3);
108108

109-
auto v3 = TrilinearInterpolate(vec, values, Vector3d{1, 1, 1});
110-
EXPECT_NEAR(v3, 1, 1e-3);
109+
auto v3 = TrilinearInterpolate(vec, values, Vector3d{2, 2, 2});
110+
EXPECT_NEAR(v3, 2, 1e-3);
111111
}

0 commit comments

Comments
 (0)