Page MenuHomec4science

body.h
No OneTemporary

File Metadata

Created
Fri, Jan 3, 06:21
#ifndef __BODY_H__
#define __BODY_H__
#include <iosfwd>
#include "symbasic/dvector.h"
#include "symbasic/svector.h"
typedef SVector<double, 2> Vec2D;
typedef SVector<Vec2D, 2> BodyCoords;
typedef DVector<BodyCoords> SysCoords;
/* SysCoords structure
*
* Body 1:
* Speed: (Vx, Vy)
* Position: (x, y)
* Body 2:
* Speed: (Vx, Vy)
* Position: (x, y)
* ...
* Body n:
* Speed: (Vx, Vy)
* Position: (x, y)
*/
struct Body {
double m;
Vec2D v;
Vec2D x;
bool fixed;
const Vec2D& position() const
{
return x;
}
const Vec2D& velocity() const
{
return v;
}
const BodyCoords coordinates() const
{
return BodyCoords({v, x});
}
void update(const BodyCoords &entry)
{
v = entry[0];
x = entry[1];
}
bool isFixed() const
{
return fixed;
}
};
std::istream& operator>>(std::istream& is, Vec2D& v);
std::istream& operator>>(std::istream& is, Body &body);
std::ostream& operator<<(std::ostream& os, const Body &body);
#endif

Event Timeline