Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/gz/math/detail/InterpolationPoint.hh
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,9 @@ namespace gz::math
(_points[_start_index + 1].position - _points[_start_index].position)
.Cross(
_points[_start_index + 2].position - _points[_start_index].position);
auto n_unit = n.Normalized();
return
_pos - n.Dot(_pos - _points[_start_index].position) * n.Normalized();
_pos - n_unit.Dot(_pos - _points[_start_index].position) * n_unit;
}

/// \brief Trilinear interpolation of eight points in 3D space. It assumes
Expand Down
30 changes: 15 additions & 15 deletions src/InterpolationPoint_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,26 @@ TEST(Interpolation, TrilinearInterpolate)
{
std::vector<InterpolationPoint3D<double>> vec {
InterpolationPoint3D<double>{Vector3d{0, 0, 0}, 0},
InterpolationPoint3D<double>{Vector3d{1, 0, 0}, 1},
InterpolationPoint3D<double>{Vector3d{0, 1, 0}, 2},
InterpolationPoint3D<double>{Vector3d{1, 1, 0}, 3},
InterpolationPoint3D<double>{Vector3d{0, 0, 1}, 4},
InterpolationPoint3D<double>{Vector3d{1, 0, 1}, 5},
InterpolationPoint3D<double>{Vector3d{0, 1, 1}, 6},
InterpolationPoint3D<double>{Vector3d{1, 1, 1}, 7},
InterpolationPoint3D<double>{Vector3d{2, 0, 0}, 1},
InterpolationPoint3D<double>{Vector3d{0, 2, 0}, 2},
InterpolationPoint3D<double>{Vector3d{2, 2, 0}, 3},
InterpolationPoint3D<double>{Vector3d{0, 0, 2}, 4},
InterpolationPoint3D<double>{Vector3d{2, 0, 2}, 5},
InterpolationPoint3D<double>{Vector3d{0, 2, 2}, 6},
InterpolationPoint3D<double>{Vector3d{2, 2, 2}, 7},
};

std::vector<double> values {0, 0, 0, 0, 1, 1, 1, 1};
std::vector<double> values {0, 0, 0, 0, 1, 1, 2, 2};

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

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

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

auto v3 = TrilinearInterpolate(vec, values, Vector3d{1, 1, 1});
EXPECT_NEAR(v3, 1, 1e-3);
auto v3 = TrilinearInterpolate(vec, values, Vector3d{2, 2, 2});
EXPECT_NEAR(v3, 2, 1e-3);
}
Loading