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>
20 #include <2geom/circle.h>
22 namespace Inkscape {
23 namespace LivePathEffect {
25 LPECircle3Pts::LPECircle3Pts(LivePathEffectObject *lpeobject) :
26 Effect(lpeobject)
27 {
28 }
30 LPECircle3Pts::~LPECircle3Pts()
31 {
32 }
34 static void _circle3(Geom::Point const &A, Geom::Point const &B, Geom::Point const &C, std::vector<Geom::Path> &path_out) {
35 using namespace Geom;
37 Point D = (A + B)/2;
38 Point E = (B + C)/2;
40 Point v = (B - A).ccw();
41 Point w = (C - B).ccw();
42 double det = -v[0] * w[1] + v[1] * w[0];
44 Point F = E - D;
45 double lambda = 1/det * (-w[1] * F[0] + w[0] * F[1]);
47 Point M = D + v * lambda;
48 double radius = L2(M - A);
50 Geom::Circle c(M, radius);
51 c.getPath(path_out);
52 }
54 std::vector<Geom::Path>
55 LPECircle3Pts::doEffect_path (std::vector<Geom::Path> const & path_in)
56 {
57 std::vector<Geom::Path> path_out = std::vector<Geom::Path>();
59 // we assume that the path has >= 3 nodes
60 Geom::Point A = path_in[0].initialPoint();
61 Geom::Point B = path_in[0].pointAt(1);
62 Geom::Point C = path_in[0].pointAt(2);
64 _circle3(A, B, C, path_out);
66 return path_out;
67 }
69 /* ######################## */
71 } //namespace LivePathEffect
72 } /* namespace Inkscape */
74 /*
75 Local Variables:
76 mode:c++
77 c-file-style:"stroustrup"
78 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
79 indent-tabs-mode:nil
80 fill-column:99
81 End:
82 */
83 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :