~jaspervdg/+junk/aem-diffusion-curves

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
#include <2geom/sbasis-poly.h>

namespace Geom{

/** Changes the basis of p to be sbasis.
 \param p the Monomial basis polynomial
 \returns the Symmetric basis polynomial

This algorithm is horribly slow and numerically terrible.  Only for testing.
*/
SBasis poly_to_sbasis(Poly const & p) {
    SBasis x = Linear(0, 1);
    SBasis r;
    
    for(int i = p.size()-1; i >= 0; i--) {
        r = SBasis(Linear(p[i], p[i])) + multiply(x, r);
    }
    r.normalize();
    return r;
	
}

/** Changes the basis of p to be monomial.
 \param p the Symmetric basis polynomial
 \returns the Monomial basis polynomial

This algorithm is horribly slow and numerically terrible.  Only for testing.
*/
Poly sbasis_to_poly(SBasis const & sb) {
    if(sb.isZero())
        return Poly();
    Poly S; // (1-x)x = -1*x^2 + 1*x + 0
    Poly A, B;
    B.push_back(0);
    B.push_back(1);
    A.push_back(1);
    A.push_back(-1);
    S = A*B;
    Poly r;
    
    for(int i = sb.size()-1; i >= 0; i--) {
        r = S*r + sb[i][0]*A + sb[i][1]*B;
    }
    r.normalize();
    return r;
}

};

/*
  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:encoding=utf-8:textwidth=99 :