Path: blob/devel/ElmerGUI/netgen/libsrc/csg/gencyl.cpp
3206 views
#include <linalg.hpp>1#include <csg.hpp>234namespace netgen5{67GeneralizedCylinder :: GeneralizedCylinder (ExplicitCurve2d & acrosssection,8Point<3> ap, Vec<3> ae1, Vec<3> ae2)9: crosssection(acrosssection)10{11planep = ap;12planee1 = ae1;13planee2 = ae2;14planee3 = Cross (planee1, planee2);15(*testout) << "Vecs = " << planee1 << " " << planee2 << " " << planee3 << endl;16};171819void GeneralizedCylinder :: Project (Point<3> & p) const20{21Point<2> p2d;22double z;2324p2d = Point<2> (planee1 * (p - planep), planee2 * (p - planep));25z = planee3 * (p - planep);2627crosssection.Project (p2d);2829p = planep + p2d(0) * planee1 + p2d(1) * planee2 + z * planee3;30}3132int GeneralizedCylinder ::BoxInSolid (const BoxSphere<3> & box) const33{34Point<3> p3d;35Point<2> p2d, projp;36double t;37Vec<2> tan, n;3839p3d = box.Center();4041p2d = Point<2> (planee1 * (p3d - planep), planee2 * (p3d - planep));42t = crosssection.ProjectParam (p2d);4344projp = crosssection.Eval (t);45tan = crosssection.EvalPrime (t);46n(0) = tan(1);47n(1) = -tan(0);4849if (Dist (p2d, projp) < box.Diam()/2)50return 2;5152if (n * (p2d - projp) > 0)53{54return 0;55}5657return 1;58}5960double GeneralizedCylinder :: CalcFunctionValue (const Point<3> & point) const61{62Point<2> p2d, projp;63double t;64Vec<2> tan, n;656667p2d = Point<2> (planee1 * (point - planep), planee2 * (point - planep));68t = crosssection.ProjectParam (p2d);6970projp = crosssection.Eval (t);71tan = crosssection.EvalPrime (t);72n(0) = tan(1);73n(1) = -tan(0);7475n /= n.Length();76return n * (p2d - projp);77}7879void GeneralizedCylinder :: CalcGradient (const Point<3> & point, Vec<3> & grad) const80{81Point<2> p2d, projp;82double t;83Vec<2> tan, n;848586p2d = Point<2> (planee1 * (point - planep), planee2 * (point - planep));87t = crosssection.ProjectParam (p2d);8889projp = crosssection.Eval (t);90tan = crosssection.EvalPrime (t);91n(0) = tan(1);92n(1) = -tan(0);9394n /= n.Length();95grad = n(0) * planee1 + n(1) * planee2;96}979899void GeneralizedCylinder :: CalcHesse (const Point<3> & point, Mat<3> & hesse) const100{101Point<2> p2d, projp;102double t, dist, val;103Point<2> curvp;104Vec<2> curvpp;105Mat<2> h2d;106Mat<3,2> vmat;107int i, j, k, l;108109p2d = Point<2> (planee1 * (point - planep), planee2 * (point - planep));110t = crosssection.ProjectParam (p2d);111112curvp = crosssection.CurvCircle (t);113curvpp = p2d-curvp;114dist = curvpp.Length();115curvpp /= dist;116117h2d(1, 1) = (1 - curvpp(0) * curvpp(0) ) / dist;118h2d(1, 2) = h2d(2, 1) = (- curvpp(0) * curvpp(1) ) / dist;119h2d(2, 2) = (1 - curvpp(1) * curvpp(1) ) / dist;120121vmat(0,0) = planee1(0);122vmat(1,0) = planee1(1);123vmat(2,0) = planee1(2);124vmat(0,1) = planee2(0);125vmat(1,1) = planee2(1);126vmat(2,1) = planee2(2);127128for (i = 0; i < 3; i++)129for (j = 0; j < 3; j++)130{131val = 0;132for (k = 0; k < 2; k++)133for (l = 0; l < 2; l++)134val += vmat(i,k) * h2d(k,l) * vmat(j,l);135hesse(i,j) = val;136}137}138139140double GeneralizedCylinder :: HesseNorm () const141{142return crosssection.MaxCurvature();143}144145double GeneralizedCylinder :: MaxCurvatureLoc (const Point<3> & c, double rad) const146{147Point<2> c2d = Point<2> (planee1 * (c - planep), planee2 * (c - planep));148return crosssection.MaxCurvatureLoc(c2d, rad);149}150151152153Point<3> GeneralizedCylinder :: GetSurfacePoint () const154{155Point<2> p2d;156p2d = crosssection.Eval(0);157return planep + p2d(0) * planee1 + p2d(1) * planee2;158}159160void GeneralizedCylinder :: Reduce (const BoxSphere<3> & box)161{162Point<2> c2d = Point<2> (planee1 * (box.Center() - planep),163planee2 * (box.Center() - planep));164crosssection.Reduce (c2d, box.Diam()/2);165}166167void GeneralizedCylinder :: UnReduce ()168{169crosssection.UnReduce ();170}171172void GeneralizedCylinder :: Print (ostream & str) const173{174str << "Generalized Cylinder" << endl;175crosssection.Print (str);176}177178#ifdef MYGRAPH179void GeneralizedCylinder :: Plot (const class ROT3D & rot) const180{181Point<2> p2d;182Point<3> p, oldp;183double t, tmin, tmax, dt;184185tmin = crosssection.MinParam();186tmax = crosssection.MaxParam();187dt = (tmax - tmin)/ 500;188189p2d = crosssection.Eval(tmin);190p = planep + p2d(0) * planee1 + p2d(1) * planee2;191192for (t = tmin; t <= tmax+dt; t += dt)193{194if (crosssection.SectionUsed (t))195MySetColor (RED);196else197MySetColor (BLUE);198199oldp = p;200p2d = crosssection.Eval(t);201p = planep + p2d(0) * planee1 + p2d(1) * planee2;202MyLine3D (p, oldp, rot);203}204205}206207#endif208}209210211