1 #include <libnr/nr-matrix-fns.h>
2 #include <cstdio>
4 namespace NR {
6 Matrix elliptic_quadratic_form(Matrix const &m) {
7 double const od = m[0] * m[1] + m[2] * m[3];
8 return Matrix((m[0]*m[0] + m[1]*m[1]), od,
9 od, (m[2]*m[2] + m[3]*m[3]),
10 0, 0);
11 /* def quadratic_form((a, b), (c, d)):
12 return ((a*a + c*c), a*c+b*d),(a*c+b*d, (b*b + d*d)) */
13 }
15 Eigen::Eigen(Matrix const &m) {
16 double const B = -m[0] - m[3];
17 double const C = m[0]*m[3] - m[1]*m[2];
18 double const center = -B/2.0;
19 double const delta = sqrt(B*B-4*C)/2.0;
20 values = Point(center + delta, center - delta);
21 for (int i = 0; i < 2; i++) {
22 vectors[i] = unit_vector(rot90(Point(m[0]-values[i], m[1])));
23 }
24 }
26 /** Returns just the scale/rotate/skew part of the matrix without the translation part. */
27 Matrix transform(Matrix const &m) {
28 Matrix const ret(m[0], m[1],
29 m[2], m[3],
30 0, 0);
31 return ret;
32 }
34 translate get_translation(Matrix const &m) {
35 return translate(m[4], m[5]);
36 }
38 void matrix_print(const gchar *say, Matrix const &m)
39 {
40 printf ("%s %g %g %g %g %g %g\n", say, m[0], m[1], m[2], m[3], m[4], m[5]);
41 }
43 } // namespace NR
46 /*
47 Local Variables:
48 mode:c++
49 c-file-style:"stroustrup"
50 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
51 indent-tabs-mode:nil
52 fill-column:99
53 End:
54 */
55 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :