1 #define INKSCAPE_LPE_CIRCLE_3PTS_CPP
2 /** \file
3 * LPE "Circle through 3 points" implementation
4 */
6 /*
7 * Authors:
8 * Maximilian Albert
9 *
10 * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
11 * Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com>
12 *
13 * Released under GNU GPL, read the file 'COPYING' for more information
14 */
16 #include "live_effects/lpe-circle_3pts.h"
18 // You might need to include other 2geom files. You can add them here:
19 #include <2geom/path.h>
21 namespace Inkscape {
22 namespace LivePathEffect {
24 LPECircle3Pts::LPECircle3Pts(LivePathEffectObject *lpeobject) :
25 Effect(lpeobject)
26 {
27 }
29 LPECircle3Pts::~LPECircle3Pts()
30 {
31 }
33 static void _circle(Geom::Point center, double radius, std::vector<Geom::Path> &path_out) {
34 using namespace Geom;
36 Geom::Path pb;
38 D2<SBasis> B;
39 Linear bo = Linear(0, 2 * M_PI);
41 B[0] = cos(bo,4);
42 B[1] = sin(bo,4);
44 B = B * radius + center;
46 pb.append(SBasisCurve(B));
48 path_out.push_back(pb);
49 }
51 static void _circle3(Geom::Point const &A, Geom::Point const &B, Geom::Point const &C, std::vector<Geom::Path> &path_out) {
52 using namespace Geom;
54 Point D = (A + B)/2;
55 Point E = (B + C)/2;
57 Point v = (B - A).ccw();
58 Point w = (C - B).ccw();
59 double det = -v[0] * w[1] + v[1] * w[0];
61 Point F = E - D;
62 double lambda = 1/det * (-w[1] * F[0] + w[0] * F[1]);
64 Point M = D + v * lambda;
65 double radius = L2(M - A);
67 _circle(M, radius, path_out);
68 }
70 std::vector<Geom::Path>
71 LPECircle3Pts::doEffect_path (std::vector<Geom::Path> const & path_in)
72 {
73 std::vector<Geom::Path> path_out = std::vector<Geom::Path>();
75 // we assume that the path has >= 3 nodes
76 Geom::Point A = path_in[0].initialPoint();
77 Geom::Point B = path_in[0].pointAt(1);
78 Geom::Point C = path_in[0].pointAt(2);
80 _circle3(A, B, C, path_out);
82 return path_out;
83 }
85 /* ######################## */
87 } //namespace LivePathEffect
88 } /* namespace Inkscape */
90 /*
91 Local Variables:
92 mode:c++
93 c-file-style:"stroustrup"
94 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
95 indent-tabs-mode:nil
96 fill-column:99
97 End:
98 */
99 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :