aboutsummaryrefslogtreecommitdiff
path: root/curve.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'curve.cpp')
-rw-r--r--curve.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/curve.cpp b/curve.cpp
new file mode 100644
index 0000000..9b63e8d
--- /dev/null
+++ b/curve.cpp
@@ -0,0 +1,23 @@
+#include <cmath>
+#include "curve.h"
+
+using namespace std;
+
+vec3 LineSegment::integrate(vec3 (*integrand)(vec3 s, vec3 ds), double dl)
+{
+ vec3 diff = this->b - this->a, sum = 0;
+
+ double len = diff.magnitude();
+
+ vec3 diffnorm = diff / len, s = this->a, ds = diffnorm * dl;
+
+ double l;
+
+ for(l = 0; l < len; l += dl, s += ds)
+ sum += integrand(s, ds);
+
+ if(l < len)
+ sum += integrand(s, diffnorm * (len - l));
+
+ return sum;
+}