[MOAB-dev] r4344 - MOAB/trunk/src
kraftche at cae.wisc.edu
kraftche at cae.wisc.edu
Thu Dec 9 14:24:52 CST 2010
Author: kraftche
Date: 2010-12-09 14:24:52 -0600 (Thu, 09 Dec 2010)
New Revision: 4344
Modified:
MOAB/trunk/src/AffineXform.cpp
MOAB/trunk/src/AffineXform.hpp
Log:
add a few utility methods to AffineXform
Modified: MOAB/trunk/src/AffineXform.cpp
===================================================================
--- MOAB/trunk/src/AffineXform.cpp 2010-12-09 20:24:25 UTC (rev 4343)
+++ MOAB/trunk/src/AffineXform.cpp 2010-12-09 20:24:52 UTC (rev 4344)
@@ -24,10 +24,13 @@
#include "moab/Interface.hpp"
#include <assert.h>
-#ifndef TEST
namespace moab {
+// Don't include tag-related stuff in test build because we don't
+// link to MOAB to test all other functionality.
+#ifndef TEST
+
const char* const AFFINE_XFORM_TAG_NAME = "AFFINE_TRANSFORM";
ErrorCode AffineXform::get_tag( Tag& tag_out,
@@ -65,11 +68,49 @@
return MB_SUCCESS;
}
+
+#endif //TEST
+
+AffineXform AffineXform::rotation( const double* from_vec, const double* to_vec )
+{
+ CartVect from(from_vec);
+ CartVect to(to_vec);
+ CartVect a = from * to;
+ double len = a.length();
+ // If input vectors are not parallel (the normal case)
+ if (len >= std::numeric_limits<double>::epsilon()) {
+ from.normalize();
+ to.normalize();
+ return rotation( from % to, (from * to).length(), a/len );
+ }
+
+ // Vectors are parallel:
+ //
+ // If vectors are in same direction then rotation is identity (no transform)
+ if (from % to >= 0.0)
+ return AffineXform();
+
+ // Parallel vectors in opposite directions:
+ //
+ // NOTE: This case is ill-defined. There are infinitely
+ // many rotations that can align the two vectors. The angle
+ // of rotation is 180 degrees, but the axis of rotation may
More information about the moab-dev
mailing list