aboutsummaryrefslogtreecommitdiff
path: root/src/curve.h
blob: 5f113511d04cfe594afe9c8b30020141efdd9c4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#ifndef CURVE_H
#define CURVE_H

#include <cmath>
#include <iostream>
#include "vec3.h"
#include "quat.h"

/* All curves inherit this class */
class Curve {
public:
    virtual vec3 integrate(vec3 (*integrand)(vec3 s, vec3 ds), scalar delta) const = 0;
    virtual const char *name() const = 0;
};

class LineSegment : 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 : 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 : 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 : 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