mbsim  4.0.0
MBSim Kernel
polynomial_frustum.h
1 /* Copyright (C) 2004-2012 MBSim Development Team
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16  *
17  * Contact: martin.o.foerg@googlemail.com
18  */
19 
20 #ifndef POLYNOMIAL_FRUSTUM_H_
21 #define POLYNOMIAL_FRUSTUM_H_
22 #include <iostream>
23 #include <mbsim/contours/contour.h>
24 #include <mbsim/contours/plate.h>
25 #include <mbsim/utils/colors.h>
26 #include <fmatvec/fmatvec.h>
27 #include <mbsim/functions/function.h>
28 #include <mbsim/utils/boost_parameters.h>
29 
30 namespace MBSim {
31 
39  public:
45  PolynomialFrustum(const std::string & name, const fmatvec::Vec & param_);
46 
50  ~PolynomialFrustum() override = default;
51 
52  /* INHERITED INTERFACE OF ELEMENT */
53  void init(InitStage stage, const InitConfigSet &config) override;
54  /***************************************************/
55 
56  /* INHERITED INTERFACE OF CONTOUR*/
62  fmatvec::Vec2 evalZeta(const fmatvec::Vec3 &WrPoint) override;
63  /*********************************/
64 
69  void setHeight(const double & height_) { height = height_; }
70 
74  double getHeight() { return height; }
75 
79  double getHeight() const { return height; }
80 
87  BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBV, tag, (optional (polynomialPoints,(int),0)(circularPoints,(int),25)(diffuseColor,(const fmatvec::Vec3&),fmatvec::Vec3(std::vector<double>{-1,1,1}))(transparency,(double),0)(pointSize,(double),0)(lineWidth,(double),0))) { enableOpenMBV_(diffuseColor,transparency,polynomialPoints,circularPoints); }
88 
92  void setColor(const MBSim::RGBColor & color_);
93 
97  void setTransparency(const double & transparency_);
98 
102  double evalValue(const double & x);
103 
107  double evalValue(const double & x) const;
108 
112  double evalValueD1(const double & x);
113 
117  double evalValueD1(const double & x) const;
118 
122  double evalValueD2(const double & x);
123 
127  double evalValueD2(const double & x) const;
128 
132  double getXPolyMax();
133 
138  double getEnclosingSphereRadius();
139 
143  fmatvec::Vec3 getEnclosingSphereCenter();
144 
149 
153  fmatvec::Vec3 evalKrPS(const fmatvec::Vec2 &zeta) override;
154 
158  fmatvec::Vec3 evalKn(const fmatvec::Vec2 &zeta) override;
159 
163  fmatvec::Vec3 evalKu(const fmatvec::Vec2 &zeta) override;
164 
168  fmatvec::Vec3 evalKv(const fmatvec::Vec2 &zeta) override;
169 
170 // /*!
171 // * \brief in 2D plane, given a point outside a polynomial curve, search for the closest point on the curve to the point
172 // * \param x_0: starting point of the polynomial domain
173 // * \param x_end: end point of the polynomial domain
174 // * \param P: the given point
175 // * \return: a dimension 3 vector, vec[0] storing the dis, vec[1] and vec[2] for the 2D position of the closest point on the curve
176 // */
177 // fmatvec::Vec3 CP_toP_onPolycurve2D(double x_0, double x_end, fmatvec::Vec2 P);
178 
179  fmatvec::Vec3 evalWn(const fmatvec::Vec2 &zeta) override;
180  fmatvec::Vec3 evalWu(const fmatvec::Vec2 &zeta) override;
181  fmatvec::Vec3 evalWv(const fmatvec::Vec2 &zeta) override;
182 
183  protected:
187  void updateEnclosingSphere();
188 
194 
198  double height;
199 
203  double sphereRadius;
204 
209 
213  double transparency;
214 
219 
224 
228  void createInventorFile();
229 
230  void enableOpenMBV_(const fmatvec::Vec3 &dc, double tp, int polynomialPoints_, int circularPoints_);
231  };
232 
238  class ContactPolyfun : public Function<double(double)> {
239  public:
243  ContactPolyfun(const double & rhs, const PolynomialFrustum * frustum);
244  ~ContactPolyfun() override = default;
245 
246  double operator()(const double &x) override;
247  void initializeUsingXML() {
248  }
249 
250  protected:
251  double rhs;
252  const PolynomialFrustum * frustum;
253 
254  };
255 
256 }
257 
258 #endif /* POLYNOMIAL_FRUSTUM_H_ */
fmatvec::Vec3 evalKn(const fmatvec::Vec2 &zeta) override
returns the normal in local coordinates of the frustum at the position (x, phi)
Definition: polynomial_frustum.cc:176
fmatvec::Vec3 evalWv(const fmatvec::Vec2 &zeta) override
Definition: polynomial_frustum.cc:234
basic class for rigid contours
Definition: rigid_contour.h:37
MBSim::RGBColor color
color values for the iv-body
Definition: polynomial_frustum.h:208
double getHeight() const
return height of frustum
Definition: polynomial_frustum.h:79
double transparency
transparency value for the body
Definition: polynomial_frustum.h:213
fmatvec::Vec3 getEnclosingSphereCenter()
return the center of the enclosing sphere
Definition: polynomial_frustum.cc:156
PolynomialFrustum(const std::string &name, const fmatvec::Vec &param_)
Constructor.
Definition: polynomial_frustum.cc:34
void updateEnclosingSphere()
Definition: polynomial_frustum.cc:209
double evalValueD2(const double &x)
get value at position of second derivative
Definition: polynomial_frustum.cc:126
void setHeight(const double &height_)
set height of frustum
Definition: polynomial_frustum.h:69
double height
height of the frustum
Definition: polynomial_frustum.h:198
fmatvec::Vec3 evalKu(const fmatvec::Vec2 &zeta) override
returns the tangent in radial direction in local coordinates of the frustum at the position (x,...
Definition: polynomial_frustum.cc:187
double sphereRadius
radius of the enclosing sphere
Definition: polynomial_frustum.h:203
double getEnclosingSphereRadius()
take the largest one among the distance from ((a+b)/2,0) to (a,f(a)),(b,f(b)) and (x,...
Definition: polynomial_frustum.cc:152
double getXPolyMax()
get inner peak value of the polynomial
Definition: polynomial_frustum.cc:142
Frustum contour with a polynomial radius over height course.
Definition: polynomial_frustum.h:38
void setColor(const MBSim::RGBColor &color_)
set color of body
Definition: polynomial_frustum.cc:86
fmatvec::Vec3 evalKv(const fmatvec::Vec2 &zeta) override
returns the tangent in azimuthal direction in local coordinates of the frustum at the point x,...
Definition: polynomial_frustum.cc:198
fmatvec::Vec3 evalWu(const fmatvec::Vec2 &zeta) override
Definition: polynomial_frustum.cc:230
InitStage
The stages of the initialization.
Definition: element.h:62
const fmatvec::Vec & getPolynomialParameters()
get coefficient vector of the polynomial
Definition: polynomial_frustum.cc:162
~PolynomialFrustum() override=default
Destructor.
Definition: contact_kinematics.h:32
BOOST_PARAMETER_MEMBER_FUNCTION((void), enableOpenMBV, tag,(optional(polynomialPoints,(int), 0)(circularPoints,(int), 25)(diffuseColor,(const fmatvec::Vec3 &), fmatvec::Vec3(std::vector< double >{-1, 1, 1}))(transparency,(double), 0)(pointSize,(double), 0)(lineWidth,(double), 0)))
enable visualisation
Definition: polynomial_frustum.h:87
std::string name
name of element
Definition: element.h:249
double evalValueD1(const double &x)
get value at position of first derivative
Definition: polynomial_frustum.cc:110
fmatvec::Vec parameters
vector holding our parameters of the polynom describing the frustum (radius over height) parameters=[...
Definition: polynomial_frustum.h:193
void init(InitStage stage, const InitConfigSet &config) override
plots time series header
Definition: polynomial_frustum.cc:41
void createInventorFile()
create inventor file for visualisation
Definition: polynomial_frustum.cc:238
fmatvec::Vec3 evalKrPS(const fmatvec::Vec2 &zeta) override
returns the point in local coordinates of the frustum at the position (x, phi)
Definition: polynomial_frustum.cc:166
this class denotes polynomial equation like this:a0+a1*x+a2*x^2+...+an*x^n=rhs
Definition: polynomial_frustum.h:238
fmatvec::Vec2 evalZeta(const fmatvec::Vec3 &WrPoint) override
returns the two lagrange parameters index 0: x, height coordinate of frustum index 1: phi,...
Definition: polynomial_frustum.cc:58
defines additive color using values for each color between [0,1]
Definition: colors.h:33
double evalValue(const double &x)
get value at position of 0 derivative
Definition: polynomial_frustum.cc:94
int polynomialPoints
grid points in polynomial direction
Definition: polynomial_frustum.h:218
ContactPolyfun(const double &rhs, const PolynomialFrustum *frustum)
Constructor.
Definition: polynomial_frustum.cc:361
void setTransparency(const double &transparency_)
set transparency of body
Definition: polynomial_frustum.cc:90
int circularPoints
grid points in polynomial direction
Definition: polynomial_frustum.h:223
double getHeight()
return height of frustum
Definition: polynomial_frustum.h:74
fmatvec::Vec3 evalWn(const fmatvec::Vec2 &zeta) override
in 2D plane, given a point outside a polynomial curve, search for the closest point on the curve to t...
Definition: polynomial_frustum.cc:226
namespace MBSim
Definition: bilateral_constraint.cc:29