diff options
| author | Franklin Wei <me@fwei.tk> | 2019-05-31 19:08:41 -0400 |
|---|---|---|
| committer | Franklin Wei <me@fwei.tk> | 2019-05-31 19:08:41 -0400 |
| commit | a99daf4a49dfbe9f4ec9bd16da8c2ad274b592a4 (patch) | |
| tree | 22da4193266a9091dbcaf86344289af0de2e6102 /include/fml/curve.h | |
| parent | f9be2ace4ca871d7ad68c1a4dbdcff87511d838b (diff) | |
| download | libfml-a99daf4a49dfbe9f4ec9bd16da8c2ad274b592a4.zip libfml-a99daf4a49dfbe9f4ec9bd16da8c2ad274b592a4.tar.gz libfml-a99daf4a49dfbe9f4ec9bd16da8c2ad274b592a4.tar.bz2 libfml-a99daf4a49dfbe9f4ec9bd16da8c2ad274b592a4.tar.xz | |
Import manifold code from fieldviz
Diffstat (limited to 'include/fml/curve.h')
| -rw-r--r-- | include/fml/curve.h | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/include/fml/curve.h b/include/fml/curve.h new file mode 100644 index 0000000..8a705cd --- /dev/null +++ b/include/fml/curve.h @@ -0,0 +1,113 @@ +#ifndef CURVE_H +#define CURVE_H + +#include <cmath> +#include <iostream> + +#include "fml.h" + +#include "manifold.h" + +namespace fml { + +/* All curves inherit this class (which is empty because Manifold has + * everything we need). */ + class Curve : public Manifold { + public: + const int dimension() const { return 1; } + }; + + class LineSegment : public Curve { + private: + vec3 a, b; + public: + LineSegment(vec3 a_, vec3 b_) : a(a_), b(b_) {}; + + vec3 integrate(vec3 (*integrand)(vec3 s, vec3 ds), scalar delta) const; + + const char *name() const { return "LineSegment"; } + + friend std::istream operator>>(std::istream &is, LineSegment &ls); + }; + + std::istream operator>>(std::istream &is, LineSegment &ls); + + class Arc : public Curve { + private: + vec3 center; + + /* these are relative to the center (direction will be determined + * by RHR of normal), and should be orthonormal */ + vec3 radius, normal; + + /* how many radians the arc extends for (can be greater than 2pi) */ + scalar angle; + public: + Arc(vec3 c_, vec3 r_, vec3 n_, scalar th) : center(c_), radius(r_), normal(n_), angle(th) {}; + + vec3 integrate(vec3 (*integrand)(vec3 s, vec3 ds), scalar delta) const; + + const char *name() const { return "Arc"; } + + friend std::istream operator>>(std::istream &is, LineSegment &ls); + }; + + std::istream operator>>(std::istream &is, LineSegment &ls); + + class Spiral : public Curve { + private: + vec3 origin; + + /* these are relative to the center (direction will be determined + * by RHR of normal), and should be orthonormal */ + vec3 radius, normal; + + /* how many radians the arc extends for (can be greater than 2pi) */ + scalar angle; + + /* linear distance between turns (2pi) */ + scalar pitch; + public: + Spiral(vec3 c_, vec3 r_, vec3 n_, scalar th, scalar p) : origin(c_), radius(r_), normal(n_), angle(th), pitch(p) {}; + + vec3 integrate(vec3 (*integrand)(vec3 s, vec3 ds), scalar delta) const; + + const char *name() const { return "Solenoid"; } + + friend std::istream operator>>(std::istream &is, LineSegment &ls); + }; + + std::istream operator>>(std::istream &is, LineSegment &ls); + + class Toroid : public Curve { + private: + vec3 origin; + + /* these are relative to the center (direction will be determined + * by RHR of normal), and should be orthonormal */ + vec3 major_radius, major_normal; + + /* "thickness" of toroid */ + scalar minor_r; + + /* how many radians (about the center) the toroid extends for + * (can be greater than 2pi) */ + scalar major_angle; + + /* central angle between successive turns (2pi rotation of small + * radius vector) */ + scalar pitch; + public: + Toroid() {}; + Toroid(vec3 o, vec3 maj_r, vec3 maj_n, scalar ang, scalar min_r, scalar p) : origin(o), major_radius(maj_r), major_normal(maj_n), major_angle(ang), minor_r(min_r), pitch(p) {}; + + vec3 integrate(vec3 (*integrand)(vec3 s, vec3 ds), scalar delta) const; + + const char *name() const { return "Toroid"; }; + + friend std::istream operator>>(std::istream &is, LineSegment &ls); + }; + + std::istream operator>>(std::istream &is, LineSegment &ls); +} +#endif |