diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2020-12-03 17:11:43 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2020-12-08 10:21:07 +0100 |
| commit | 0c39051ba80f04b1177833a006f2d442a7170b56 (patch) | |
| tree | 9e657946a061b5b305f9cf75634db7b37e979eb3 /labb8/lib/StanfordCPPLib/gmath.cpp | |
| parent | 7b7f6808a7b2db2ed21103767434c1445f7815c2 (diff) | |
| download | tddd86-0c39051ba80f04b1177833a006f2d442a7170b56.tar.gz | |
add initial files l8
Diffstat (limited to 'labb8/lib/StanfordCPPLib/gmath.cpp')
| -rwxr-xr-x | labb8/lib/StanfordCPPLib/gmath.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/labb8/lib/StanfordCPPLib/gmath.cpp b/labb8/lib/StanfordCPPLib/gmath.cpp new file mode 100755 index 0000000..a5ff934 --- /dev/null +++ b/labb8/lib/StanfordCPPLib/gmath.cpp @@ -0,0 +1,50 @@ +/* + * File: gmath.cpp + * --------------- + * This file implements the gmath.h interface. In all cases, the + * implementation for each function requires only one line of code, + * which makes detailed documentation unnecessary. + */ + +#include <cmath> +#include "gmath.h" +#include "gtypes.h" + +extern const double PI = 3.14159265358979323846; +extern const double E = 2.71828182845904523536; + +double sinDegrees(double angle) { + return sin(toRadians(angle)); +} + +double cosDegrees(double angle) { + return cos(toRadians(angle)); +} + +double tanDegrees(double angle) { + return tan(toRadians(angle)); +} + +double toDegrees(double radians) { + return radians * 180 / PI; +} + +double toRadians(double degrees) { + return degrees * PI / 180; +} + +double vectorDistance(const GPoint & pt) { + return vectorDistance(pt.getX(), pt.getY()); +} + +double vectorDistance(double x, double y) { + return sqrt(x * x + y * y); +} + +double vectorAngle(const GPoint & pt) { + return vectorAngle(pt.getX(), pt.getY()); +} + +double vectorAngle(double x, double y) { + return (x == 0 && y == 0) ? 0 : toDegrees(atan2(-y, x)); +} |
