summaryrefslogtreecommitdiffstats
path: root/labb8/lib/StanfordCPPLib/gmath.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'labb8/lib/StanfordCPPLib/gmath.cpp')
-rwxr-xr-xlabb8/lib/StanfordCPPLib/gmath.cpp50
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));
+}