VPTissue Reference Manual
Geom.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Universiteit Antwerpen
3  *
4  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
5  * the European Commission - subsequent versions of the EUPL (the "Licence");
6  * You may not use this work except in compliance with the Licence.
7  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the Licence is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the Licence for the specific language governing
13  * permissions and limitations under the Licence.
14  */
20 #include "Geom.h"
21 
22 #include "math/math.h"
23 #include <cmath>
24 
25 namespace {
26 
27 inline constexpr double tiny() { return 1.0e-5; }
28 
29 }
30 
31 using namespace std;
32 
33 namespace SimPT_Sim {
34 
35 tuple<double, double, double> Geom::CircumCircle(double x1, double y1, double x2, double y2, double x3, double y3)
36 {
37  double xc;
38  double yc;
39 
40  if (abs(y2 - y1) < tiny()) {
41  const double m2 = -(x3 - x2) / (y3 - y2);
42  const double mx2 = (x2 + x3) / 2.0;
43  const double my2 = (y2 + y3) / 2.0;
44  xc = (x2 + x1) / 2.0;
45  yc = m2 * (xc - mx2) + my2;
46  } else if (abs(y3 - y2) < tiny()) {
47  const double m1 = -(x2 - x1) / (y2 - y1);
48  const double mx1 = (x1 + x2) / 2.0;
49  const double my1 = (y1 + y2) / 2.0;
50  xc = (x3 + x2) / 2.0;
51  yc = m1 * (xc - mx1) + my1;
52  } else {
53  const double m1 = -(x2 - x1) / (y2 - y1);
54  const double m2 = -(x3 - x2) / (y3 - y2);
55  const double mx1 = (x1 + x2) / 2.0;
56  const double mx2 = (x2 + x3) / 2.0;
57  const double my1 = (y1 + y2) / 2.0;
58  const double my2 = (y2 + y3) / 2.0;
59  xc = (m1 * mx1 - m2 * mx2 + my2 - my1) / (m1 - m2);
60  yc = m1 * (xc - mx1) + my1;
61  }
62 
63  const double dx = x2 - xc;
64  const double dy = y2 - yc;
65  const double r = sqrt(dx * dx + dy * dy);
66 
67  return make_tuple(xc, yc, r);
68 }
69 
70 }
STL namespace.
Namespace for the core simulator.
Interface for Geom.
Math constants and functions header combo.