gravitation.h 5.12 KB
 Vladimir Kuznetsov committed Feb 03, 2007 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 /* This file is part of StepCore library. Copyright (C) 2007 Vladimir Kuznetsov StepCore library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. StepCore library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with StepCore; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /** \file gravitation.h * \brief GravitationForce and WeightForce classes */ #ifndef STEPCORE_GRAVITATION_H #define STEPCORE_GRAVITATION_H #include "world.h"  Vladimir Kuznetsov committed Feb 13, 2007 27 #include "object.h"  Vladimir Kuznetsov committed Feb 03, 2007 28 29 30 31 32 #include "constants.h" namespace StepCore {  Vladimir Kuznetsov committed Aug 24, 2007 33 34 35 36 37 38 class GravitationForce; class WeightForce; /** \ingroup errors * \brief Errors object for GravitationForce */  Vladimir Kuznetsov committed Aug 24, 2007 39 class GravitationForceErrors: public ObjectErrors  Vladimir Kuznetsov committed Aug 24, 2007 40 41 42 43 44 45 { STEPCORE_OBJECT(GravitationForceErrors) public: /** Constructs GravitationForceErrors */ GravitationForceErrors(Item* owner = NULL)  Vladimir Kuznetsov committed Aug 24, 2007 46  : ObjectErrors(owner), _gravitationConstVariance(0) {}  Vladimir Kuznetsov committed Aug 24, 2007 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61  /** Get owner as GravitationForce */ GravitationForce* gravitationForce() const; /** Get gravitationConst variance */ double gravitationConstVariance() const { return _gravitationConstVariance; } /** Set gravitationConst variance */ void setGravitationConstVariance(double gravitationConstVariance) { _gravitationConstVariance = gravitationConstVariance; } protected: double _gravitationConstVariance; friend class GravitationForce; };  Vladimir Kuznetsov committed Feb 03, 2007 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 /** \ingroup forces * \brief Newton gravitational force. * * The force acts between pairs of massive bodies (currently only Particle) * and equals: * \f[ * \overrightarrow{f} = G \frac{m_1 m_2 \overrightarrow{r}} * {|\overrightarrow{r}|^3} * \f] * where:\n * \f$G\f$ is GravitationForce::gravitationConst\n * \f$m_1\f$ and \f$m_2\f$ is Particle::mass of first and second body\n * \f$\overrightarrow{r}\f$ is difference of Particle::position * of the first and second body * * \todo Add interface for massive bodies, support bodies with * distributed mass */  Inge Wallin committed Dec 20, 2014 80 class GravitationForce : public Force  Vladimir Kuznetsov committed Feb 03, 2007 81 {  Vladimir Kuznetsov committed Feb 13, 2007 82  STEPCORE_OBJECT(GravitationForce)  Vladimir Kuznetsov committed Feb 03, 2007 83 84 85 86 87  public: /** Constructs GravitationForce */ GravitationForce(double gravitationConst = Constants::Gravitational);  Vladimir Kuznetsov committed Aug 24, 2007 88  void calcForce(bool calcVariances);  Vladimir Kuznetsov committed Feb 03, 2007 89 90  /** Get gravitational constant */  Vladimir Kuznetsov committed Feb 13, 2007 91  double gravitationConst() const { return _gravitationConst; }  Vladimir Kuznetsov committed Feb 03, 2007 92 93 94  /** Set gravitational constant */ void setGravitationConst(double gravitationConst) { _gravitationConst = gravitationConst; }  Vladimir Kuznetsov committed Aug 24, 2007 95 96  /** Get (and possibly create) GravitationForceErrors object */ GravitationForceErrors* gravitationForceErrors() {  Vladimir Kuznetsov committed Aug 24, 2007 97  return static_cast(objectErrors()); }  Vladimir Kuznetsov committed Aug 24, 2007 98   Vladimir Kuznetsov committed Feb 03, 2007 99 protected:  Vladimir Kuznetsov committed Aug 24, 2007 100  ObjectErrors* createObjectErrors() { return new GravitationForceErrors(this); }  Vladimir Kuznetsov committed Aug 24, 2007 101   Vladimir Kuznetsov committed Feb 03, 2007 102 103 104  double _gravitationConst; };  Vladimir Kuznetsov committed Aug 24, 2007 105 106 107 /** \ingroup errors * \brief Errors object for WeightForce */  Vladimir Kuznetsov committed Aug 24, 2007 108 class WeightForceErrors: public ObjectErrors  Vladimir Kuznetsov committed Aug 24, 2007 109 110 111 112 113 114 { STEPCORE_OBJECT(WeightForceErrors) public: /** Constructs WeightForceErrors */ WeightForceErrors(Item* owner = NULL)  Vladimir Kuznetsov committed Aug 24, 2007 115  : ObjectErrors(owner), _weightConstVariance(0) {}  Vladimir Kuznetsov committed Aug 24, 2007 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130  /** Get owner as WeightForce */ WeightForce* weightForce() const; /** Get weightConst variance */ double weightConstVariance() const { return _weightConstVariance; } /** Set weightConst variance */ void setWeightConstVariance(double weightConstVariance) { _weightConstVariance = weightConstVariance; } protected: double _weightConstVariance; friend class WeightForce; };  Vladimir Kuznetsov committed Feb 03, 2007 131 132 133 134 135 136 137 138 139 140 141 142 143 144 /** \ingroup forces * \brief Weight force (constant gravitational force). * * The force acts between on massive bodies (currently only Particle) * and equals: * \f[ * \overrightarrow{f} = \left( \begin{array}{c} 0 \\ mg \end{array} \right) * \f] * where:\n * \f$m\f$ is Particle::mass\n * \f$g\f$ is WeightForce::weightConst * * \todo Add interface for massive bodies, support bodies with distributed mass */  Inge Wallin committed Dec 20, 2014 145 class WeightForce : public Force  Vladimir Kuznetsov committed Feb 03, 2007 146 {  Vladimir Kuznetsov committed Feb 13, 2007 147  STEPCORE_OBJECT(WeightForce)  Vladimir Kuznetsov committed Feb 03, 2007 148 149 150 151  public: /** Constructs WeightForce */ WeightForce(double weightConst = Constants::WeightAccel);  Vladimir Kuznetsov committed Feb 13, 2007 152   Vladimir Kuznetsov committed Aug 24, 2007 153  void calcForce(bool calcVariances);  Vladimir Kuznetsov committed Feb 03, 2007 154 155  /** Get weight constant */  Vladimir Kuznetsov committed Feb 13, 2007 156  double weightConst() const { return _weightConst; }  Vladimir Kuznetsov committed Feb 03, 2007 157 158 159  /** Set weight constant */ void setWeightConst(double weightConst) { _weightConst = weightConst; }  Vladimir Kuznetsov committed Aug 24, 2007 160 161  /** Get (and possibly create) WeightForceErrors object */ WeightForceErrors* weightForceErrors() {  Vladimir Kuznetsov committed Aug 24, 2007 162  return static_cast(objectErrors()); }  Vladimir Kuznetsov committed Aug 24, 2007 163   Vladimir Kuznetsov committed Feb 03, 2007 164 protected:  Vladimir Kuznetsov committed Aug 24, 2007 165  ObjectErrors* createObjectErrors() { return new WeightForceErrors(this); }  Vladimir Kuznetsov committed Feb 03, 2007 166   Vladimir Kuznetsov committed Aug 24, 2007 167  double _weightConst;  Vladimir Kuznetsov committed Feb 03, 2007 168 169 170 171 172 173 }; } // namespace StepCore #endif