gravitation.h 5.12 KB
Newer Older
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 <ks.vladimir@gmail.com>

   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"
27
#include "object.h"
28 29 30 31 32
#include "constants.h"

namespace StepCore
{

33 34 35 36 37 38
class GravitationForce;
class WeightForce;

/** \ingroup errors
 *  \brief Errors object for GravitationForce
 */
39
class GravitationForceErrors: public ObjectErrors
40 41 42 43 44 45
{
    STEPCORE_OBJECT(GravitationForceErrors)

public:
    /** Constructs GravitationForceErrors */
    GravitationForceErrors(Item* owner = NULL)
46
        : ObjectErrors(owner), _gravitationConstVariance(0) {}
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;
};

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
 */
80
class GravitationForce : public Force
81
{
82
    STEPCORE_OBJECT(GravitationForce)
83 84 85 86 87

public:
    /** Constructs GravitationForce */
    GravitationForce(double gravitationConst = Constants::Gravitational);

88
    void calcForce(bool calcVariances);
89 90

    /** Get gravitational constant */
91
    double gravitationConst() const { return _gravitationConst; }
92 93 94
    /** Set gravitational constant */
    void   setGravitationConst(double gravitationConst) { _gravitationConst = gravitationConst; }

95 96
    /** Get (and possibly create) GravitationForceErrors object */
    GravitationForceErrors* gravitationForceErrors() {
97
        return static_cast<GravitationForceErrors*>(objectErrors()); }
98

99
protected:
100
    ObjectErrors* createObjectErrors() { return new GravitationForceErrors(this); }
101

102 103 104
    double _gravitationConst;
};

105 106 107
/** \ingroup errors
 *  \brief Errors object for WeightForce
 */
108
class WeightForceErrors: public ObjectErrors
109 110 111 112 113 114
{
    STEPCORE_OBJECT(WeightForceErrors)

public:
    /** Constructs WeightForceErrors */
    WeightForceErrors(Item* owner = NULL)
115
        : ObjectErrors(owner), _weightConstVariance(0) {}
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;
};

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
 */
145
class WeightForce : public Force
146
{
147
    STEPCORE_OBJECT(WeightForce)
148 149 150 151

public:
    /** Constructs WeightForce */
    WeightForce(double weightConst = Constants::WeightAccel);
152

153
    void calcForce(bool calcVariances);
154 155

    /** Get weight constant */
156
    double weightConst() const { return _weightConst; }
157 158 159
    /** Set weight constant */
    void   setWeightConst(double weightConst) { _weightConst = weightConst; }

160 161
    /** Get (and possibly create) WeightForceErrors object */
    WeightForceErrors* weightForceErrors() {
162
        return static_cast<WeightForceErrors*>(objectErrors()); }
163

164
protected:
165
    ObjectErrors* createObjectErrors() { return new WeightForceErrors(this); }
166

167
    double _weightConst;
168 169 170 171 172 173
};

} // namespace StepCore

#endif