Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rotation params #3559

Merged
merged 2 commits into from
Mar 3, 2020
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 samples/visualization_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
system,
background_color=[1, 1, 1],
drag_enabled=True,
quality_constraints=200,
rasterize_resolution=50.0,
rasterize_pointsize=5,
camera_position=[150, 25, 25],
Expand Down Expand Up @@ -104,7 +105,7 @@
elif args.shape == "HollowConicalFrustum":
system.constraints.add(shape=espressomd.shapes.HollowConicalFrustum(
r1=12, r2=8, length=15.0, thickness=3,
axis=[0.0, 0.0, 1.0], center=[25, 25, 25], direction=1),
axis=[0.0, 1.0, 1.0], center=[25, 25, 25], direction=1),
particle_type=0, penetrable=True)

else:
Expand Down
2 changes: 1 addition & 1 deletion src/shapes/unit_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
include(unit_test)
unit_test(NAME Wall_test SRC Wall_test.cpp DEPENDS shapes utils)
unit_test(NAME ConicalFrustum_test SRC HollowConicalFrustum_test.cpp DEPENDS shapes utils)
unit_test(NAME HollowConicalFrustum_test SRC HollowConicalFrustum_test.cpp DEPENDS shapes utils)
unit_test(NAME Union_test SRC Union_test.cpp DEPENDS shapes utils)
unit_test(NAME Ellipsoid_test SRC Ellipsoid_test.cpp DEPENDS shapes utils)
79 changes: 55 additions & 24 deletions src/shapes/unit_tests/HollowConicalFrustum_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,72 @@

#define BOOST_TEST_MODULE Cone test
#define BOOST_TEST_DYN_LINK

#include <boost/test/unit_test.hpp>
#include <shapes/HollowConicalFrustum.hpp>
#include <utils/Vector.hpp>

BOOST_AUTO_TEST_CASE(dist_function) {
constexpr double L = 8.0;
constexpr double R1 = 2.0;
constexpr double R2 = 3.0;

constexpr double eps = 100 * std::numeric_limits<double>::epsilon();

{
Shapes::HollowConicalFrustum c;
c.set_r1(R1);
c.set_r2(R2);
c.set_length(L);
c.set_axis(Utils::Vector3d{0, 0, 1});

auto pos = Utils::Vector3d{0.0, 0.0, L / 2.0};
Utils::Vector3d vec;
double dist;

c.calculate_dist(pos, dist, vec);
BOOST_CHECK_CLOSE(dist, 2.0, eps);
BOOST_CHECK_CLOSE(dist, vec.norm(), eps);

pos = {{R1, 0.0, L / 2.0}};
c.calculate_dist(pos, dist, vec);
BOOST_CHECK_SMALL(dist, eps);
BOOST_CHECK_CLOSE(dist, vec.norm(), eps);

Shapes::HollowConicalFrustum c;
c.set_r1(R1);
c.set_r2(3.0);
c.set_length(L);
c.set_axis(Utils::Vector3d{0, 0, 1});
pos = {{3.0, 0.0, -L / 2.0}};
c.calculate_dist(pos, dist, vec);
BOOST_CHECK_SMALL(dist, eps);
BOOST_CHECK_CLOSE(dist, vec.norm(), eps);

auto pos = Utils::Vector3d{0.0, 0.0, L / 2.0};
Utils::Vector3d vec;
double dist;
c.set_thickness(1.0);
c.set_r2(R1);
pos = {{R1 + 1.0, 0.0, L / 2.0}};
c.calculate_dist(pos, dist, vec);
BOOST_CHECK_CLOSE(dist, .5, eps);
}
{
Shapes::HollowConicalFrustum c;
c.set_r1(R1);
c.set_r2(R2);
c.set_length(L);
c.set_axis(Utils::Vector3d{1, 0, 0});

c.calculate_dist(pos, dist, vec);
BOOST_CHECK_CLOSE(dist, 2.0, 1e-7);
BOOST_CHECK_CLOSE(dist, vec.norm(), 1e-7);
auto pos = Utils::Vector3d{L / 2.0, 0.0, 0.0};
Utils::Vector3d vec;
double dist;

pos = {{R1, 0.0, L / 2.0}};
c.calculate_dist(pos, dist, vec);
BOOST_CHECK_CLOSE(dist, 0.0, 1e-7);
BOOST_CHECK_CLOSE(dist, vec.norm(), 1e-7);
c.calculate_dist(pos, dist, vec);
BOOST_CHECK_CLOSE(dist, 2.0, eps);
BOOST_CHECK_CLOSE(dist, vec.norm(), eps);

pos = {{3.0, 0.0, -L / 2.0}};
c.calculate_dist(pos, dist, vec);
BOOST_CHECK_CLOSE(dist, 0.0, 1e-7);
BOOST_CHECK_CLOSE(dist, vec.norm(), 1e-7);
pos = {{L / 2.0, R1, 0.0}};
c.calculate_dist(pos, dist, vec);
BOOST_CHECK_SMALL(dist, eps);
BOOST_CHECK_CLOSE(dist, vec.norm(), eps);

c.set_thickness(1.0);
c.set_r2(R1);
pos = {{R1 + 1.0, 0.0, L / 2.0}};
c.calculate_dist(pos, dist, vec);
BOOST_CHECK_CLOSE(dist, .5, 1e-7);
pos = {{-L / 2.0, R2, 0.0}};
c.calculate_dist(pos, dist, vec);
BOOST_CHECK_SMALL(dist, eps);
BOOST_CHECK_CLOSE(dist, vec.norm(), eps);
}
}
2 changes: 1 addition & 1 deletion src/utils/include/utils/math/vec_rotate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ inline Vector3d vec_rotate(const Vector3d &axis, double alpha,
inline std::tuple<double, Vector3d>
rotation_params(Vector3d const &vec, Vector3d const &target_vec) {
auto const theta =
std::acos(vec * target_vec) / (vec.norm() * target_vec.norm());
std::acos(vec * target_vec / (vec.norm() * target_vec.norm()));
auto const rotation_axis = Utils::vector_product(vec, target_vec).normalize();
return std::make_tuple(theta, rotation_axis);
}
Expand Down
15 changes: 14 additions & 1 deletion src/utils/tests/vec_rotate_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>

#include "utils/math/vec_rotate.hpp"
#include <utils/constants.hpp>
#include <utils/math/vec_rotate.hpp>
using Utils::vec_rotate;

#include <cmath>
Expand All @@ -45,3 +46,15 @@ BOOST_AUTO_TEST_CASE(rotation) {

BOOST_CHECK(rel_diff < std::numeric_limits<double>::epsilon());
}

BOOST_AUTO_TEST_CASE(rotation_params) {
Utils::Vector3d v1 = {1.0, 0.0, 0.0};
Utils::Vector3d v2 = {1.0, 1.0, 0.0};

double angle;
Utils::Vector3d rotation_axis;
std::tie(angle, rotation_axis) = Utils::rotation_params(v1, v2);
BOOST_CHECK_CLOSE(angle, Utils::pi() / 4.0, 1e-7);
BOOST_CHECK_SMALL((rotation_axis * v1), 1e-7);
BOOST_CHECK_SMALL((rotation_axis * v2), 1e-7);
}