Skip to content
Snippets Groups Projects
Commit 5cb81cbf authored by Tom Fischer's avatar Tom Fischer
Browse files

[GL] Change signature of compute{2,3}DRotationMatrixToX.

parent 8e464ae1
No related branches found
No related tags found
No related merge requests found
......@@ -70,59 +70,6 @@ std::pair<Eigen::Vector3d, double> getNewellPlane(
return std::make_pair(plane_normal, d);
}
template <class T_MATRIX>
void compute2DRotationMatrixToX(Eigen::Vector3d const& v, T_MATRIX& rot_mat)
{
const double cos_theta = v[0];
const double sin_theta = v[1];
rot_mat(0,0) = rot_mat(1,1) = cos_theta;
rot_mat(0,1) = sin_theta;
rot_mat(1,0) = -sin_theta;
rot_mat(0,2) = rot_mat(1,2) = rot_mat(2,0) = rot_mat(2,1) = 0.0;
rot_mat(2,2) = 1.0;
}
template <class T_MATRIX>
void compute3DRotationMatrixToX(Eigen::Vector3d const& v, T_MATRIX& rot_mat)
{
double const eps = std::numeric_limits<double>::epsilon();
// a vector on the plane
Eigen::Vector3d yy({0, 0, 0});
if (std::abs(v[0]) > 0.0 && std::abs(v[1]) + std::abs(v[2]) < eps)
{
yy[2] = 1.0;
}
else if (std::abs(v[1]) > 0.0 && std::abs(v[0]) + std::abs(v[2]) < eps)
{
yy[0] = 1.0;
}
else if (std::abs(v[2]) > 0.0 && std::abs(v[0]) + std::abs(v[1]) < eps)
{
yy[1] = 1.0;
}
else
{
for (unsigned i = 0; i < 3; i++)
{
if (std::abs(v[i]) > 0.0)
{
yy[i] = -v[i];
break;
}
}
}
// z"_vec
Eigen::Vector3d const zz = v.cross(yy).normalized();
// y"_vec
Eigen::Vector3d const y = zz.cross(v).normalized();
for (unsigned i = 0; i < 3; ++i)
{
rot_mat(0, i) = v[i];
rot_mat(1, i) = y[i];
rot_mat(2, i) = zz[i];
}
}
template <typename InputIterator>
void rotatePoints(Eigen::Matrix3d const& rot_mat, InputIterator pnts_begin,
......
......@@ -681,4 +681,56 @@ void sortSegments(
}
}
Eigen::Matrix3d compute2DRotationMatrixToX(Eigen::Vector3d const& v)
{
Eigen::Matrix3d rot_mat = Eigen::Matrix3d::Zero();
const double cos_theta = v[0];
const double sin_theta = v[1];
rot_mat(0,0) = rot_mat(1,1) = cos_theta;
rot_mat(0,1) = sin_theta;
rot_mat(1,0) = -sin_theta;
rot_mat(2,2) = 1.0;
return rot_mat;
}
Eigen::Matrix3d compute3DRotationMatrixToX(Eigen::Vector3d const& v)
{
// a vector on the plane
Eigen::Vector3d yy = Eigen::Vector3d::Zero();
auto const eps = std::numeric_limits<double>::epsilon();
if (std::abs(v[0]) > 0.0 && std::abs(v[1]) + std::abs(v[2]) < eps)
{
yy[2] = 1.0;
}
else if (std::abs(v[1]) > 0.0 && std::abs(v[0]) + std::abs(v[2]) < eps)
{
yy[0] = 1.0;
}
else if (std::abs(v[2]) > 0.0 && std::abs(v[0]) + std::abs(v[1]) < eps)
{
yy[1] = 1.0;
}
else
{
for (unsigned i = 0; i < 3; i++)
{
if (std::abs(v[i]) > 0.0)
{
yy[i] = -v[i];
break;
}
}
}
// z"_vec
Eigen::Vector3d const zz = v.cross(yy).normalized();
// y"_vec
yy = zz.cross(v).normalized();
Eigen::Matrix3d rot_mat;
rot_mat.row(0) = v;
rot_mat.row(1) = yy;
rot_mat.row(2) = zz;
return rot_mat;
}
} // end namespace GeoLib
......@@ -78,20 +78,20 @@ std::pair<Eigen::Vector3d, double> getNewellPlane(
const std::vector<T_POINT>& pnts);
/**
* Computes a rotation matrix that rotates the given 2D normal vector parallel to X-axis
* @param v a 2D normal vector to be rotated
* @param rot_mat a 2x2 rotation matrix
* Computes a rotation matrix that rotates the given 2D normal vector parallel
* to X-axis
* @param v a 2D normal vector to be rotated
* @return a 3x3 rotation matrix where the upper, left, 2x2 block
* contains the entries necessary for the 2D rotation
*/
template<class T_MATRIX>
void compute2DRotationMatrixToX(Eigen::Vector3d const& v, T_MATRIX & rot_mat);
Eigen::Matrix3d compute2DRotationMatrixToX(Eigen::Vector3d const& v);
/**
* Computes a rotation matrix that rotates the given 3D normal vector parallel to X-axis
* @param v a 3D normal vector to be rotated
* @param rot_mat a 3x3 rotation matrix
* @return a 3x3 rotation matrix
*/
template <class T_MATRIX>
void compute3DRotationMatrixToX(Eigen::Vector3d const& v, T_MATRIX& rot_mat);
Eigen::Matrix3d compute3DRotationMatrixToX(Eigen::Vector3d const& v);
/**
* Method computes the rotation matrix that rotates the given vector parallel to
......
......@@ -42,17 +42,17 @@ MeshLib::RotationMatrix getRotationMatrixToGlobal(
// coordinates
if (element_dimension == 1)
{
auto const a = Eigen::Map<Eigen::Vector3d const>(points[0].getCoords());
auto const b = Eigen::Map<Eigen::Vector3d const>(points[1].getCoords());
Eigen::Vector3d xx = b - a;
xx.normalize();
Eigen::Vector3d const xx =
(Eigen::Map<Eigen::Vector3d const>(points[1].getCoords()) -
Eigen::Map<Eigen::Vector3d const>(points[0].getCoords()))
.normalized();
if (global_dim == 2)
{
GeoLib::compute2DRotationMatrixToX(xx, matR);
matR = GeoLib::compute2DRotationMatrixToX(xx);
}
else
{
GeoLib::compute3DRotationMatrixToX(xx, matR);
matR = GeoLib::compute3DRotationMatrixToX(xx);
}
matR.transposeInPlace();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment