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