aboutsummaryrefslogtreecommitdiff
path: root/curve.cpp
diff options
context:
space:
mode:
authorFranklin Wei <me@fwei.tk>2019-02-02 23:02:12 -0500
committerFranklin Wei <me@fwei.tk>2019-02-02 23:02:12 -0500
commit79a83c2cbee5adca798b8976b2a39ecd6ffd39af (patch)
tree379523f81d3e7dc02c62ca1505376b8d0bc6b30e /curve.cpp
downloadfieldviz-79a83c2cbee5adca798b8976b2a39ecd6ffd39af.zip
fieldviz-79a83c2cbee5adca798b8976b2a39ecd6ffd39af.tar.gz
fieldviz-79a83c2cbee5adca798b8976b2a39ecd6ffd39af.tar.bz2
fieldviz-79a83c2cbee5adca798b8976b2a39ecd6ffd39af.tar.xz
initial commit
basic B field integrator
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;
+}