#include #include #include #include #include #include // --------------------------------------------------- // Tests // --------------------------------------------------- using namespace ipc; using namespace ipc::rigid; RigidBody simple_rigid_body( Eigen::MatrixXd& vertices, Eigen::MatrixXi& edges, Pose velocity) { static int id = 0; int ndof = Pose::dim_to_ndof(vertices.cols()); return RigidBody( vertices, edges, /*pose=*/Pose::Zero(vertices.cols()), velocity, /*force=*/Pose::Zero(vertices.cols()), /*density=*/1.0, /*is_dof_fixed=*/VectorXb::Zero(ndof), /*oriented=*/false, /*group=*/id++); } TEST_CASE("Rigid Body System Transform", "[RB][RB-System][RB-System-transform]") { Eigen::MatrixXd vertices(4, 2); Eigen::MatrixXi edges(4, 2); Pose velocity = Pose::Zero(vertices.cols()); Pose rb1_pose_t1 = Pose::Zero(vertices.cols()); Pose rb2_pose_t1 = Pose::Zero(vertices.cols()); Eigen::MatrixXd expected(4, 2); vertices << -0.5, -0.5, 0.5, -0.5, 0.5, 0.5, -0.5, 0.5; edges << 0, 1, 1, 2, 2, 3, 3, 0; SECTION("Translation Case") { rb1_pose_t1.position << 0.5, 0.5; rb2_pose_t1.position << 1.0, 1.0; // expected displacements expected.resize(8, 2); expected.block(0, 0, 4, 2) = rb1_pose_t1.position.transpose().replicate(4, 1); expected.block(4, 0, 4, 2) = rb2_pose_t1.position.transpose().replicate(4, 1); } SECTION("90 Deg Rotation Case") { rb1_pose_t1.rotation << 0.5 * igl::PI; rb2_pose_t1.rotation << igl::PI; expected.resize(8, 2); expected.block(0, 0, 4, 2) << 1.0, 0.0, 0.0, 1.0, -1.0, 0.0, 0.0, -1.0; expected.block(4, 0, 4, 2) << 1.0, 1.0, -1.0, 1.0, -1.0, -1.0, 1.0, -1.0; } std::vector rbs; rbs.push_back(simple_rigid_body(vertices, edges, velocity)); rbs.push_back(simple_rigid_body(vertices, edges, velocity)); RigidBodyAssembler assembler; assembler.init(rbs); Poses poses = { { rb1_pose_t1, rb2_pose_t1 } }; /// compute displacements between current and given positions /// TODO: update test to not need displacements Eigen::MatrixXd actual = assembler.world_vertices(poses) - assembler.world_vertices(); CHECK((expected - actual).squaredNorm() < 1E-6); }