Constructor for Trafo by rotation along an arbitrary axes, combine trafos

This commit is contained in:
Joachim Schöberl 2019-03-25 12:33:16 +01:00
parent c0bb877ea5
commit dab8c827fe
3 changed files with 30 additions and 1 deletions

View File

@ -163,7 +163,31 @@ ostream & operator<< (ostream & ost, Transformation3d & trans)
return ost; return ost;
} }
template <>
Transformation<3> :: Transformation (const Point<3> & c, const Vec<3> & axes, double angle)
{
Vec<3> vc(c);
Transformation<3> tc(vc);
Transformation<3> tcinv(-vc);
Transformation<3> r, ht, ht2;
// r.SetAxisRotation (3, alpha);
Vec<3> naxes = axes;
naxes.Normalize();
Vec<3> n1 = naxes.GetNormal();
Vec<3> n2 = Cross(naxes, n1);
r.v = Vec<3>(0,0,0);
double co = cos(angle);
double si = sin(angle);
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
r.m(i,j) = naxes(i)*naxes(j) + co*(n1(i)*n1(j)+n2(i)*n2(j)) + si*( (n2(i)*n1(j)-n2(j)*n1(i)) );
ht.Combine (tc, r);
Combine (ht, tcinv);
}
template <int D> template <int D>
Transformation<D> :: Transformation (const Point<D> * pp) Transformation<D> :: Transformation (const Point<D> * pp)
{ {

View File

@ -102,6 +102,8 @@ public:
m(i,i) = 1; m(i,i) = 1;
} }
Transformation (const Point<D> & c, const Vec<3> & axes, double angle);
// rotation with ... // rotation with ...
Transformation (const Point<D> & c, double alpha, double beta, double gamma) Transformation (const Point<D> & c, double alpha, double beta, double gamma)
{ {

View File

@ -184,7 +184,10 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
([] (double x, double y) { return Vec<2>(x,y); })); ([] (double x, double y) { return Vec<2>(x,y); }));
py::class_<Transformation<3>> (m, "Trafo") py::class_<Transformation<3>> (m, "Trafo")
.def(py::init<Vec<3>>()) .def(py::init<Vec<3>>(), "a translation")
.def(py::init<Point<3>,Vec<3>,double>(), "a rotation given by point on axes, direction of axes, angle")
.def("__mul__", [](Transformation<3> a, Transformation<3> b)->Transformation<3>
{ Transformation<3> res; res.Combine(a,b); return res; })
.def("__call__", [] (Transformation<3> trafo, Point<3> p) { return trafo(p); }) .def("__call__", [] (Transformation<3> trafo, Point<3> p) { return trafo(p); })
; ;