just a test

Dependencies:   mbed

Fork of scoreLight_Advanced by Alvaro Cassinelli

Committer:
mbedalvaro
Date:
Sat Mar 31 08:19:31 2012 +0000
Revision:
1:a4050fee11f7
Parent:
0:345b3bc7a0ea
Child:
2:34157ebbf56b
new scorelight methods added. VERY STRANGE problem with oldPos and pos in Verlet method, that have strange behaviour depending on the value of damp factor...

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedalvaro 0:345b3bc7a0ea 1 /*
mbedalvaro 0:345b3bc7a0ea 2 * pointMass.h
mbedalvaro 0:345b3bc7a0ea 3 * laserBlob
mbedalvaro 0:345b3bc7a0ea 4 *
mbedalvaro 0:345b3bc7a0ea 5 * Created by CASSINELLI ALVARO on 5/19/11.
mbedalvaro 0:345b3bc7a0ea 6 * Copyright 2011 TOKYO UNIVERSITY. All rights reserved.
mbedalvaro 0:345b3bc7a0ea 7 *
mbedalvaro 0:345b3bc7a0ea 8 */
mbedalvaro 0:345b3bc7a0ea 9
mbedalvaro 0:345b3bc7a0ea 10 #ifndef POINTMASS_H
mbedalvaro 0:345b3bc7a0ea 11 #define POINTMASS_H
mbedalvaro 0:345b3bc7a0ea 12
mbedalvaro 0:345b3bc7a0ea 13 #include "myVectorClass.h"
mbedalvaro 0:345b3bc7a0ea 14
mbedalvaro 1:a4050fee11f7 15 //#define VERLET_METHOD // comment this to have EULER method
mbedalvaro 0:345b3bc7a0ea 16
mbedalvaro 0:345b3bc7a0ea 17 class pointMass
mbedalvaro 0:345b3bc7a0ea 18 {
mbedalvaro 0:345b3bc7a0ea 19 public:
mbedalvaro 0:345b3bc7a0ea 20
mbedalvaro 0:345b3bc7a0ea 21 // ==================================== METHODS ====================================
mbedalvaro 0:345b3bc7a0ea 22 pointMass();
mbedalvaro 0:345b3bc7a0ea 23 virtual ~pointMass(){};
mbedalvaro 0:345b3bc7a0ea 24
mbedalvaro 0:345b3bc7a0ea 25 // Adding forces to total force:
mbedalvaro 0:345b3bc7a0ea 26 void resetForce();
mbedalvaro 0:345b3bc7a0ea 27 void addForce(float x, float y);
mbedalvaro 0:345b3bc7a0ea 28 void addForce(vector2D force);
mbedalvaro 0:345b3bc7a0ea 29 void addDampingForce();
mbedalvaro 0:345b3bc7a0ea 30 void addInvSquareForce(float x, float y, float radiusMax, float radiusMin, float scale);
mbedalvaro 0:345b3bc7a0ea 31 void addInterInvSquareForce(pointMass &p, float radiusMin, float radiusMax, float scale);
mbedalvaro 0:345b3bc7a0ea 32
mbedalvaro 0:345b3bc7a0ea 33 // (a blob object could be defined by a "cord" of chained particles, plus a center)
mbedalvaro 0:345b3bc7a0ea 34 void addSpringForce(float x, float y, float radius, float scale);
mbedalvaro 0:345b3bc7a0ea 35 void addInterSpringForce(pointMass &p, float radius, float scale);
mbedalvaro 0:345b3bc7a0ea 36 //void addClockwiseForce(particle &p, float radius, float scale);
mbedalvaro 0:345b3bc7a0ea 37 //void addCounterClockwiseForce(particle &p, float radius, float scale);
mbedalvaro 0:345b3bc7a0ea 38
mbedalvaro 0:345b3bc7a0ea 39 //void addDampingForce(); // this work in the case of the euler integration; in case of Verlet, we need to do pseudo-damping while calculating
mbedalvaro 0:345b3bc7a0ea 40 // the acceleration...
mbedalvaro 0:345b3bc7a0ea 41
mbedalvaro 0:345b3bc7a0ea 42 // Set parameters:
mbedalvaro 0:345b3bc7a0ea 43 void setInitialCondition(float px, float py, float vx, float vy);
mbedalvaro 0:345b3bc7a0ea 44 void setIntegrationStep(float _dt);
mbedalvaro 0:345b3bc7a0ea 45
mbedalvaro 0:345b3bc7a0ea 46 void setPos(float px, float py); // assuming the speed is unchanged (must do some tweaking in case of Verlet integration)
mbedalvaro 0:345b3bc7a0ea 47
mbedalvaro 0:345b3bc7a0ea 48 // dynamic update:
mbedalvaro 0:345b3bc7a0ea 49 void update();
mbedalvaro 0:345b3bc7a0ea 50
mbedalvaro 0:345b3bc7a0ea 51 // kinematic constraints (could be based on a force too...)
mbedalvaro 0:345b3bc7a0ea 52 void setWallLimits(float mminx, float mminy, float mmaxx, float mmaxy);
mbedalvaro 0:345b3bc7a0ea 53 void bounceOffWalls();
mbedalvaro 0:345b3bc7a0ea 54
mbedalvaro 0:345b3bc7a0ea 55 vector2D getSpeed(); // get an estimation of the speed (also update speed variable - this variable is not needed in case of VERLET)
mbedalvaro 0:345b3bc7a0ea 56 void setSpeed(const vector2D& vel);
mbedalvaro 0:345b3bc7a0ea 57 void setSpeed(float vx, float vy);
mbedalvaro 0:345b3bc7a0ea 58
mbedalvaro 0:345b3bc7a0ea 59 // ==================================== VARIABLES ====================================
mbedalvaro 0:345b3bc7a0ea 60
mbedalvaro 0:345b3bc7a0ea 61 int identifier; // this may be needed in particular in case we don't use vector<> (case of poor C Arduino compiler)
mbedalvaro 0:345b3bc7a0ea 62
mbedalvaro 0:345b3bc7a0ea 63 // kinematic variables:
mbedalvaro 0:345b3bc7a0ea 64 vector2D pos, posOld; // I will use verlet integration (perhaps we could have a switch to choose the integration method?)
mbedalvaro 0:345b3bc7a0ea 65 //vector2D speed; // speed at time t (this is not explicitly calculated in case of verlet method, HENCE PRIVATE)
mbedalvaro 0:345b3bc7a0ea 66 vector2D acc; // Acceleration at time t (equal to the total force divided by the mass). No real need to have it here, but convenient to check.
mbedalvaro 0:345b3bc7a0ea 67 vector2D totalForce; // this is just for convenience and speeding up calculation when adding forces, before computing acc.
mbedalvaro 0:345b3bc7a0ea 68
mbedalvaro 0:345b3bc7a0ea 69 // integration step:
mbedalvaro 0:345b3bc7a0ea 70 float dt;
mbedalvaro 0:345b3bc7a0ea 71
mbedalvaro 0:345b3bc7a0ea 72 // physical parameters:
mbedalvaro 0:345b3bc7a0ea 73 float dampMotion;
mbedalvaro 0:345b3bc7a0ea 74 float dampBorder;
mbedalvaro 0:345b3bc7a0ea 75 vector2D maxWall, minWall;
mbedalvaro 0:345b3bc7a0ea 76 float mass;
mbedalvaro 0:345b3bc7a0ea 77 bool bFixed; // these could act as control points that could be loaded (letters...). In fact, we could use mass to set this (like mass=-1)
mbedalvaro 0:345b3bc7a0ea 78
mbedalvaro 0:345b3bc7a0ea 79 // other things:
mbedalvaro 0:345b3bc7a0ea 80 vector2D innerCollitionDirection; // this is smarter than a boolean, because I can detect which side was touched
mbedalvaro 0:345b3bc7a0ea 81 bool bWallCollision; // this is generic (detect any collision with a side)
mbedalvaro 0:345b3bc7a0ea 82
mbedalvaro 0:345b3bc7a0ea 83 protected:
mbedalvaro 0:345b3bc7a0ea 84
mbedalvaro 0:345b3bc7a0ea 85 private:
mbedalvaro 0:345b3bc7a0ea 86 vector2D speed; // speed at time t (this is not explicitly calculated in case of verlet method, HENCE PRIVATE)
mbedalvaro 0:345b3bc7a0ea 87
mbedalvaro 0:345b3bc7a0ea 88 };
mbedalvaro 0:345b3bc7a0ea 89
mbedalvaro 0:345b3bc7a0ea 90
mbedalvaro 0:345b3bc7a0ea 91
mbedalvaro 0:345b3bc7a0ea 92 #endif //POINTMASS_H