-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Uploaded C++ classes to implement TerrestrialGravitation
- Loading branch information
1 parent
33246a5
commit 41bb12d
Showing
9 changed files
with
1,339 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
#include "Cartesian.h" | ||
|
||
Cartesian::Cartesian() { | ||
atOrigin(); } | ||
|
||
Cartesian::Cartesian(int a, int b) { | ||
x = a; | ||
y = b; | ||
xx = (double) a; | ||
yy = (double) b; } | ||
|
||
Cartesian::Cartesian(const Cartesian &cartecopy) { | ||
xx = cartecopy.xx; | ||
yy = cartecopy.yy; | ||
x = (int) xx; | ||
y = (int) yy; } | ||
|
||
Cartesian Cartesian::operator=(const Cartesian &carteassignment) { | ||
if (cartesianassignment != this) { | ||
xx = cartesianassignment.xx; | ||
yy = cartesianassignment.yy; | ||
x = (int) xx; | ||
y = (int) yy; | ||
} | ||
return *this; } | ||
|
||
Cartesian Cartesian::operator+(const Cartesian &carte1, const Cartesian &carte2) { | ||
xx = carte1.xx + carte2.xx; | ||
yy = carte1.yy + carte2.yy; | ||
concordanceDouble(); | ||
return *this; } | ||
|
||
Cartesian Cartesian::operator-(const Cartesian &carte1, const Cartesian &carte2) { | ||
xx = carte1.xx - carte2.xx; | ||
yy = carte1.yy - carte2.yy; | ||
concordanceDouble(); | ||
return *this; } | ||
|
||
Cartesian::~Cartesian() { | ||
} | ||
|
||
int Cartesian::X(void) { return x; } | ||
|
||
int Cartesian::Y(void) { return y; } | ||
|
||
Cartesian Cartesian::Position(void) { | ||
if !(concordance(*this)) concordanceDouble(); | ||
return *this; } | ||
|
||
void Cartesian::X(int a) { | ||
x = a; | ||
concordanceInt(); | ||
return; } | ||
|
||
void Cartesian::Y(int b) { | ||
y = b; | ||
concordanceInt(); | ||
return; } | ||
|
||
void Cartesian::XX(double aa) { | ||
xx = aa; | ||
concordanceDouble(); | ||
return; } | ||
|
||
void Cartesian::YY(double bb) { | ||
yy = bb; | ||
concordanceDouble(); | ||
return; } | ||
|
||
void Cartesian::Position(Cartesian pos) { | ||
xx = pos.xx; | ||
yy = pos.yy; | ||
concordanceDouble(); | ||
return; } | ||
|
||
double Cartesian::distanceDouble(void) { | ||
double dd = sqrt((xx * xx) + (yy * yy)); | ||
return dd; } | ||
|
||
int Cartesian::distanceInt(void) { | ||
double dd = distanceDouble(); | ||
int d = (int) dd; | ||
return d; } | ||
|
||
double Cartesian::distance(void) { | ||
double dd = distanceDouble(void); | ||
return dd; } | ||
|
||
double Castesian::distance(double aa, double bb) { | ||
double ee = aa - xx; | ||
double ff = bb - yy; | ||
double dd = sqrt((ee * ee) + (ff * ff)); | ||
return dd; } | ||
|
||
int Cartesian::distance(int a, int b) { | ||
double aa = (double) a; | ||
double bb = (double) b; | ||
double dd = distance(aa, bb); | ||
int d = (int) dd; | ||
return d; } | ||
|
||
double Cartesian::distanceDouble(Cartesian carte) { | ||
double ee = catre.xx - xx; | ||
double ff = carte.yy - yy; | ||
double dd = sqrt((ee * ee) + (ff * ff)); | ||
return dd; } | ||
|
||
int Cartesian::distanceInt(Cartesian carte) { | ||
double dd = distanceDouble(carte); | ||
int d = (int) d; | ||
return d; } | ||
|
||
double Cartesian::distance(Catesian carte) { | ||
double dd = distanceDouble(carte); | ||
return dd; } | ||
|
||
double Cartesian::angleDouble(void) { | ||
double aa = arctan(yy / xx)); | ||
return aa; } | ||
|
||
int Cartesian::angleInt(void) { | ||
double aa = angleDouble(); | ||
int a = (int) aa; | ||
return a; } | ||
|
||
double Cartesian::angle(void) { | ||
double aa = angleDouble(void); | ||
return aa; } | ||
|
||
double Castesian::angle(double ww, double zz) { | ||
double ee = ww - xx; | ||
double ff = zz - yy; | ||
double aa = actan(ff / ee); | ||
return aa; } | ||
|
||
int Cartesian::angle(int w, int z) { | ||
double ww = (double) w; | ||
double zz = (double) z; | ||
double aa = angle(ww, zz); | ||
int a = (int) aa; | ||
return a; } | ||
|
||
double Cartesian::angleDouble(Cartesian carte) { | ||
double ee = catre.xx - xx; | ||
double ff = carte.yy - yy; | ||
double aa = arctan(ff / ee); | ||
return aa; } | ||
|
||
int Cartesian::angleInt(Cartesian carte) { | ||
double aa = angleDouble(carte); | ||
int a = (int) aa; | ||
return a; } | ||
|
||
double Cartesian::angle(Catesian carte) { | ||
double aa = angleDouble(carte); | ||
return aa; } | ||
|
||
bool Cartesian::concordance(void) { | ||
int a = (int) xx; | ||
int b = (int) yy; | ||
double aa = (double) x; | ||
double bb = (double) y; | ||
bool pass = ((a == x) && (b == y)); | ||
if (pass) pass = ((aa == xx) && (bb == yy)); | ||
return pass; } | ||
|
||
void Cartesian::concordanceDouble(void) { | ||
x = (int) xx; | ||
y = (int) yy; | ||
return; } | ||
|
||
void Cartesian::concordanceInt(void) { | ||
xx = (double) x; | ||
yy = (double) y; | ||
return; } | ||
|
||
Cartesian Cartesian::atOrigin(void) { | ||
xx = yy = 0.0F; | ||
x = y = 0; | ||
return *this; } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#ifndef CARTESIAN_H | ||
#define CARTESIAN_H | ||
|
||
#include <cmath> | ||
|
||
class Cartesian | ||
{ | ||
public: | ||
int x, y; | ||
double xx, yy; | ||
Cartesian(); | ||
Cartesian(int a, b); | ||
Cartesian(double aa, bb); | ||
Cartesian(const Cartesian &cartecopy); | ||
operator=(const Cartesian &carteassignment); | ||
operator+(const Cartesian &carte1, const Cartesian &carte2); | ||
operator-(const Cartesian &carte1, const Cartesian &carte2); | ||
~Cartesian(); | ||
|
||
// Read current position | ||
int X(void); | ||
int Y(void); | ||
double XX(void); | ||
double YY(void); | ||
Cartesian Position(void); | ||
|
||
//Set current position | ||
void X(int a); | ||
void Y(int b); | ||
void XY(int a, int b); | ||
void XXYY(double aa, double bb); | ||
void XX(double aa); | ||
void YY(double bb); | ||
void Position(Cartesian pos); | ||
|
||
// Calculate distance from current position to... | ||
int distanceInt(void); // origin | ||
double distanceDouble(void); | ||
double distance (void); // same as distanceDouble(void) | ||
int distance(int a, int b); // point given by (a, b) | ||
double distance(double aa, double bb); | ||
int distanceInt(Cartesian carte); // point given by carte | ||
double distanceDouble(Cartesian carte); | ||
double distance(Cartesian carte); | ||
|
||
// Calculate the degree angle from current position to... | ||
int angleInt(void); // origin | ||
double angleDouble(void); | ||
double angle(void); // same as angleDouble(void) | ||
int angle(int w, int z); // point given by (w, z) | ||
double angle(double ww, double zz); | ||
int angleInt(Cartesian carte); // point given by carte | ||
double angleDouble(Cartesian carte); | ||
double angle(Cartesian carte); | ||
|
||
// Check or force concordance between int coordinates and double coorindates | ||
bool concordance(void); // Check concordance, return TRUE if concordant | ||
void concordanceInt(void); // Force concordance, doubles must agree w/ ints | ||
void concordanceDouble(void); // Force concordance, ints must agree w/ doubles | ||
|
||
Cartesian atOrigin(void); // Assign to be at origin (0, 0) and return | ||
}; | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "GravitationalBody.h" | ||
|
||
|
||
Cartesian initialPosition, Cartesian initialVelocity; | ||
GravitationalBody(void); | ||
GravitationalBody(int a, int b); | ||
GravitationalBody(double aa, double bb); | ||
GravitationalBody(Cartesian pos); | ||
GravitationalBody(int a, int b, int vx, int vy); | ||
GravitationalBody(double aa, double bb, double vxx, double vyy); | ||
GravitationalBody(Cartesian pos, Cartesian vel); | ||
GravitationalBody(int a, int b, int vx, int vy, int ix, int iy); | ||
GravitationalBody(double aa, double bb, double vxx, double vyy, | ||
double ixx, double iyy); | ||
GravitationalBody(Cartesian pos, Cartesian vel, Cartesian ipos); | ||
GravitationalBody(int a, int b, int vx, int vy, int ix, int iy, int ivx, int ivy); | ||
GravitationalBody(double aa, double bb, double vxx, double vyy, | ||
double ixx, double iyy, double ivxx, double ivyy); | ||
GravitationalBody(Cartesian pos, Cartesian vel, Cartesian ipos, Cartesian ivel); | ||
GravitationalBody(const &gravbodCopy); | ||
operator=(const &gravbodAssignment); | ||
~GravitationalBody(void); | ||
|
||
Cartesian bodyPos(void); | ||
Cartesian bodyVel(void); | ||
|
||
void placeBody(int a, int b); | ||
void placeBody(double aa, double bb); | ||
void placeBody(Cartesian pos); | ||
|
||
void giveVelocity(int vx, int vy); | ||
void giveVelocity(double vxx, double vyy); | ||
void giveVelocity(Cartesian vel); | ||
|
||
void initPosition(int ix, int iy); | ||
void initPosition(double ixx, double iyy); | ||
void initPosition(Cartesian ipos); | ||
|
||
void initVelocity(int ivx, int ivy); | ||
void initVelocity(double ivxx, double ivyy); | ||
void initVelocity(Cartesian ivel); | ||
|
||
void initPosition(void); // assign current position to initialPosition | ||
void initVelocity(void); // assign current velocity to initialVelocity | ||
void beginMotion(void); // same as initVelocity() | ||
void haltMotion(void); // call veloity.atOrigin() and halt motion of body | ||
|
||
|
||
GravitationalBody::GravitationalBody(Cartesian position, Cartesian velocity, bool at_rest) | ||
{ | ||
} | ||
|
||
GravitationalBody::~GravitationalBody() | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#ifndef GRAVITATIONALBODY_H | ||
#define GRAVITATIONALBODY_H | ||
|
||
#include "InertBody.hpp" | ||
|
||
class GravitationalBody : public InertBody | ||
{ | ||
public: | ||
Cartesian initialPosition, Cartesian initialVelocity; | ||
GravitationalBody(void); | ||
GravitationalBody(int a, int b); | ||
GravitationalBody(double aa, double bb); | ||
GravitationalBody(Cartesian pos); | ||
GravitationalBody(int a, int b, int vx, int vy); | ||
GravitationalBody(double aa, double bb, double vxx, double vyy); | ||
GravitationalBody(Cartesian pos, Cartesian vel); | ||
GravitationalBody(int a, int b, int vx, int vy, int ix, int iy); | ||
GravitationalBody(double aa, double bb, double vxx, double vyy, | ||
double ixx, double iyy); | ||
GravitationalBody(Cartesian pos, Cartesian vel, Cartesian ipos); | ||
GravitationalBody(int a, int b, int vx, int vy, int ix, int iy, int ivx, int ivy); | ||
GravitationalBody(double aa, double bb, double vxx, double vyy, | ||
double ixx, double iyy, double ivxx, double ivyy); | ||
GravitationalBody(Cartesian pos, Cartesian vel, Cartesian ipos, Cartesian ivel); | ||
GravitationalBody(const &gravbodCopy); | ||
operator=(const &gravbodAssignment); | ||
~GravitationalBody(void); | ||
|
||
Cartesian bodyPos(void); | ||
Cartesian bodyVel(void); | ||
|
||
void placeBody(int a, int b); | ||
void placeBody(double aa, double bb); | ||
void placeBody(Cartesian pos); | ||
|
||
void giveVelocity(int vx, int vy); | ||
void giveVelocity(double vxx, double vyy); | ||
void giveVelocity(Cartesian vel); | ||
|
||
void initPosition(int ix, int iy); | ||
void initPosition(double ixx, double iyy); | ||
void initPosition(Cartesian ipos); | ||
|
||
void initVelocity(int ivx, int ivy); | ||
void initVelocity(double ivxx, double ivyy); | ||
void initVelocity(Cartesian ivel); | ||
|
||
void initPosition(void); // assign current position to initialPosition | ||
void initVelocity(void); // assign current velocity to initialVelocity | ||
void beginMotion(void); // same as initVelocity() | ||
void haltMotion(void); // call veloity.atOrigin() and halt motion of body | ||
}; | ||
|
||
#endif |
Oops, something went wrong.