summaryrefslogtreecommitdiffstats
path: root/src/toys/conic-3.cpp
blob: 64b2c27e515e07a940a4d622b97b1f02ff8de176 (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
/**
 * elliptics via C-curves. (njh)
 * Limited to 180 degrees (by end point and tangent matching criteria)
 * Also represents cycloids
 */

#include <2geom/d2.h>
#include <2geom/sbasis.h>
#include <2geom/bezier-to-sbasis.h>
#include <2geom/sbasis-to-bezier.h>
#include <2geom/sbasis-math.h>

#include <toys/path-cairo.h>
#include <toys/toy-framework-2.h>

using std::vector;
using namespace Geom;

Linear z0(0.5,1.);

unsigned total_pieces;

double sinC(double t) { return t - sin(t);}
double cosC(double t) { return 1 - cos(t);}
double tanC(double t) { return sinC(t) / cosC(t);}

class Conic3: public Toy {
    PointSetHandle psh;
    public:
    Conic3 () {
        psh.push_back(100, 500);
        psh.push_back(100, 500 - 200*M_PI/2);
        psh.push_back(500, 500 - 200*M_PI/2);
        psh.push_back(500, 500);
        handles.push_back(&psh);
    }

    void draw(cairo_t *cr, std::ostringstream *notify, int width, int height, bool save, std::ostringstream *timer_stream) override {
        cairo_set_source_rgba (cr, 0., 0., 0, 0.8);
        cairo_set_line_width (cr, 0.5);
        cairo_stroke(cr);
        
        Geom::Point a[2] = {psh.pts[0] - psh.pts[1],
                        psh.pts[2] - psh.pts[1]};
        double angle = Geom::angle_between(a[0], a[1]);
        double len = std::max(Geom::L2(a[0]),
                                Geom::L2(a[1]));
        for(auto & i : a) 
        i = len*unit_vector(i);
        *notify << "angle = " << angle;
        *notify << " sinC = " << sinC(angle);
        *notify << " cosC = " << cosC(angle);
        *notify << " tanC = " << tanC(angle);
        vector<Geom::Point> e_a_h = psh.pts;
        
        double alpha = M_PI;
        Piecewise<SBasis> pw(Linear(0, alpha));
        Piecewise<SBasis> C = cos(pw);
        Piecewise<SBasis> S = sin(pw);
        Piecewise<SBasis> sinC = pw - S;
        Piecewise<SBasis> cosC = Piecewise<SBasis>(1) - C;
        Piecewise<SBasis> Z3 = sinC/sinC(1);
        Piecewise<SBasis> Z0 = reverse(Z3);
        Piecewise<SBasis> Z2 = cosC/cosC(1) - Z3;
        Piecewise<SBasis> Z1 = reverse(Z2);
        
        Piecewise<SBasis> Z[4] = {Z0, Z1, Z2, Z3};
        
        D2<Piecewise<SBasis> > B;
        for(unsigned dim  = 0; dim < 2; dim++) {
            B[dim] = Piecewise<SBasis>(0);
            for(unsigned i  = 0; i < 4; i++) {
                B[dim] += Z[i]*e_a_h[i][dim];
            }
        }
        cairo_d2_pw_sb(cr, B);
        Toy::draw(cr, notify, width, height, save,timer_stream);
    }
};

int main(int argc, char **argv) {
    init(argc, argv, new Conic3());

    return 0;
}

/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :