• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdeedu
  • Sitemap
  • Contact Us
 

step/stepcore

particle.h

Go to the documentation of this file.
00001 /* This file is part of StepCore library.
00002    Copyright (C) 2007 Vladimir Kuznetsov <ks.vladimir@gmail.com>
00003 
00004    StepCore library is free software; you can redistribute it and/or modify
00005    it under the terms of the GNU General Public License as published by
00006    the Free Software Foundation; either version 2 of the License, or
00007    (at your option) any later version.
00008 
00009    StepCore library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012    GNU General Public License for more details.
00013 
00014    You should have received a copy of the GNU General Public License
00015    along with StepCore; if not, write to the Free Software
00016    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017 */
00018 
00023 #ifndef STEPCORE_PARTICLE_H
00024 #define STEPCORE_PARTICLE_H
00025 
00026 #include "world.h"
00027 #include "vector.h"
00028 #include "object.h"
00029 
00030 namespace StepCore {
00031 
00032 class Particle;
00033 class ChargedParticle;
00034 
00038 class ParticleErrors: public ObjectErrors
00039 {
00040     STEPCORE_OBJECT(ParticleErrors)
00041 
00042 public:
00044     ParticleErrors(Item* owner = 0)
00045         : ObjectErrors(owner), _positionVariance(0), _velocityVariance(0),
00046           _forceVariance(0), _massVariance(0) {}
00047 
00049     Particle* particle() const;
00050 
00052     const Vector2d& positionVariance() const { return _positionVariance; }
00054     void setPositionVariance(const Vector2d& positionVariance) {
00055         _positionVariance = positionVariance; }
00056 
00058     const Vector2d& velocityVariance() const { return _velocityVariance; }
00060     void setVelocityVariance(const Vector2d& velocityVariance) {
00061         _velocityVariance = velocityVariance; }
00062 
00064     Vector2d accelerationVariance() const;
00065 
00067     const Vector2d& forceVariance() const { return _forceVariance; }
00069     void setForceVariance(const Vector2d& forceVariance) {
00070         _forceVariance = forceVariance; }
00071 
00073     void applyForceVariance(const Vector2d& forceVariance) {
00074         _forceVariance += forceVariance; }
00075 
00077     double massVariance() const { return _massVariance; }
00079     void   setMassVariance(double massVariance) {
00080         _massVariance = massVariance; }
00081 
00083     Vector2d momentumVariance() const;
00085     void setMomentumVariance(const Vector2d& momentumVariance);
00086 
00088     double kineticEnergyVariance() const;
00090     void setKineticEnergyVariance(double kineticEnergyVariance);
00091 
00092 protected:
00093     Vector2d _positionVariance;
00094     Vector2d _velocityVariance;
00095     Vector2d _forceVariance;
00096     double _massVariance;
00097     friend class Particle;
00098 };
00099 
00103 class Particle: public Item, public Body
00104 {
00105     STEPCORE_OBJECT(Particle)
00106 
00107 public:
00108     enum {
00109         PositionOffset = 0 
00110     };
00111 
00113     explicit Particle(Vector2d position = Vector2d(0),
00114             Vector2d velocity = Vector2d(0), double mass = 1);
00115 
00117     const Vector2d& position() const { return _position; }
00119     void setPosition(const Vector2d& position) { _position = position; }
00120 
00122     const Vector2d& velocity() const { return _velocity; }
00124     void setVelocity(const Vector2d& velocity) { _velocity = velocity; }
00125 
00127     Vector2d acceleration() const { return _force/_mass; }
00128 
00130     const Vector2d& force() const { return _force; }
00132     void setForce(const Vector2d& force) { _force = force; }
00133 
00135     void applyForce(const Vector2d& force) { _force += force; }
00136 
00138     double mass() const { return _mass; }
00140     void   setMass(double mass) { _mass = mass; }
00141 
00143     Vector2d momentum() const { return _velocity * _mass; }
00145     void setMomentum(const Vector2d& momentum) { _velocity = momentum / _mass; }
00146 
00148     double kineticEnergy() const { return _mass * _velocity.norm2()/2; }
00150     void setKineticEnergy(double kineticEnergy);
00151 
00152     int  variablesCount() { return 2; }
00153     void getVariables(double* position, double* velocity,
00154                           double* positionVariance, double* velocityVariance);
00155     void setVariables(const double* position, const double* velocity,
00156               const double* positionVariance, const double* velocityVariance);
00157     void addForce(const double* force, const double* forceVariance);
00158     void resetForce(bool resetVariance);
00159     void getAccelerations(double* acceleration, double* accelerationVariance);
00160     void getInverseMass(GmmSparseRowMatrix* inverseMass,
00161                             GmmSparseRowMatrix* variance, int offset);
00162 
00164     ParticleErrors* particleErrors() {
00165         return static_cast<ParticleErrors*>(objectErrors()); }
00166 
00167 protected:
00168     ObjectErrors* createObjectErrors() { return new ParticleErrors(this); }
00169 
00170     Vector2d _position;
00171     Vector2d _velocity;
00172     Vector2d _force;
00173     double _mass;
00174 };
00175 
00179 class ChargedParticleErrors: public ParticleErrors
00180 {
00181     STEPCORE_OBJECT(ChargedParticleErrors)
00182 
00183 public:
00185     ChargedParticleErrors(Item* owner = 0)
00186         : ParticleErrors(owner), _chargeVariance(0) {}
00187 
00189     ChargedParticle* chargedParticle() const;
00190 
00192     double chargeVariance() const { return _chargeVariance; }
00194     void   setChargeVariance(double chargeVariance) {
00195         _chargeVariance = chargeVariance; }
00196 
00197 protected:
00198     double _chargeVariance;
00199     friend class ChargedParticle;
00200 };
00201 
00202 
00206 class ChargedParticle: public Particle
00207 {
00208     STEPCORE_OBJECT(ChargedParticle)
00209 
00210 public:
00212     explicit ChargedParticle(Vector2d position = Vector2d(0),
00213             Vector2d velocity = Vector2d(0), double mass = 1, double charge = 0)
00214                 : Particle(position, velocity, mass), _charge(charge) {}
00215 
00217     double charge() const { return _charge; }
00219     void setCharge(double charge) { _charge = charge; }
00220 
00222     ChargedParticleErrors* chargedParticleErrors() {
00223         return static_cast<ChargedParticleErrors*>(objectErrors()); }
00224 
00225 protected:
00226     ObjectErrors* createObjectErrors() { return new ChargedParticleErrors(this); }
00227 
00228     double _charge;
00229 };
00230 
00231 } // namespace StepCore
00232 
00233 #endif
00234 

step/stepcore

Skip menu "step/stepcore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdeedu

Skip menu "kdeedu"
  • kalzium
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  •   docs
  •   src
  • parley
  •   stepcore
Generated for kdeedu by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal