diff --git a/src/mesh_common/MeshOperations.h b/src/mesh_common/MeshOperations.h index b870817508fe2e00186fc7b0f5dfea7e944e9b70..1694edf876107b953b7e6f02f9d20d843dc9f28c 100644 --- a/src/mesh_common/MeshOperations.h +++ b/src/mesh_common/MeshOperations.h @@ -49,6 +49,9 @@ void translate( MeshType & mesh, const Vector3< typename MeshType::Scalar > & of template< typename MeshType > void scale( MeshType & mesh, const Vector3< typename MeshType::Scalar > & scaleFactors ); +template< typename MeshType > +void rotate( MeshType& mesh, Vector3<typename MeshType::Scalar > axis, typename MeshType::Scalar angle, Vector3< typename MeshType::scalar> axis_foot); + template< typename MeshType > typename MeshType::Scalar computeVolume( const MeshType & mesh ); @@ -182,6 +185,21 @@ void scale( MeshType & mesh, const Vector3< typename MeshType::Scalar > & scaleF } } +template< typename MeshType > +void rotate( MeshType& mesh, Vector3<typename MeshType::Scalar > axis, typename MeshType::Scalar angle, Vector3< typename MeshType::Scalar> axis_foot) +{ + Matrix3< typename MeshType::Scalar > mat(axis, angle); + + for( auto v_it = mesh.vertices_begin(); v_it != mesh.vertices_end(); ++v_it) + { + auto &p = mesh.point(*v_it); + p -= mesh::toOpenMesh(axis_foot); + p = mat*p; + p += mesh::toOpenMesh(axis_foot); + } +} + + template< typename MeshType > typename MeshType::Scalar computeVolume( const MeshType & mesh ) diff --git a/tests/mesh/MeshOperationsTest.cpp b/tests/mesh/MeshOperationsTest.cpp index 6cceae10e9a75ee79a88aa3b2b80737df68a3d94..a17d14c7246b1b8fe59c897ead2fe6abf58d0cc9 100644 --- a/tests/mesh/MeshOperationsTest.cpp +++ b/tests/mesh/MeshOperationsTest.cpp @@ -120,6 +120,28 @@ void testCube() WALBERLA_CHECK_FLOAT_EQUAL( inertiaTensor(0,0), aabb.volume() * ( aabb.ySize() * aabb.ySize() + aabb.zSize() * aabb.zSize() ) / real_t(12) ); WALBERLA_CHECK_FLOAT_EQUAL( inertiaTensor(1,1), aabb.volume() * ( aabb.xSize() * aabb.xSize() + aabb.zSize() * aabb.zSize() ) / real_t(12) ); WALBERLA_CHECK_FLOAT_EQUAL( inertiaTensor(2,2), aabb.volume() * ( aabb.xSize() * aabb.xSize() + aabb.ySize() * aabb.ySize() ) / real_t(12) ); + + + rotate(mesh, Vector3<Scalar>{0, 0, 1}, static_cast<Scalar>(M_PI_2), Vector3<Scalar>{-4, 0, 0}); + aabb = computeAABB( mesh ); + + WALBERLA_CHECK_FLOAT_EQUAL( aabb.xMin(), Scalar(-5.5) ); + WALBERLA_CHECK_FLOAT_EQUAL( aabb.yMin(), Scalar(3) ); + WALBERLA_CHECK_FLOAT_EQUAL( aabb.zMin(), Scalar(-0.25) ); + + WALBERLA_CHECK_FLOAT_EQUAL( aabb.xMax(), Scalar(-2.5) ); + WALBERLA_CHECK_FLOAT_EQUAL( aabb.yMax(), Scalar(5) ); + WALBERLA_CHECK_FLOAT_EQUAL( aabb.zMax(), Scalar(0.25) ); + + + WALBERLA_CHECK_FLOAT_EQUAL( computeSurfaceArea( mesh ), Scalar(2) * ( aabb.xSize() * aabb.ySize() + aabb.xSize() * aabb.zSize() + aabb.ySize() * aabb.zSize() ) ); + WALBERLA_CHECK_FLOAT_EQUAL( computeVolume( mesh ), aabb.volume() ); + centroid = computeCentroid( mesh ); + aabbCenter = aabb.center(); + WALBERLA_CHECK_FLOAT_EQUAL( centroid[0], aabbCenter[0] ); + WALBERLA_CHECK_FLOAT_EQUAL( centroid[1], aabbCenter[1] ); + WALBERLA_CHECK_FLOAT_EQUAL( centroid[2], aabbCenter[2] ); + } int main( int argc, char * argv[] )