source: branches/FACT++_lidctrl_new_eth/drive/Ring.cc@ 20051

Last change on this file since 20051 was 18620, checked in by tbretz, 8 years ago
Removed references to root.
File size: 1.7 KB
Line 
1#include "Ring.h"
2
3#include <iostream>
4
5#include <math.h>
6
7#include "Led.h"
8
9using namespace std;
10
11Ring::Ring(double x, double y) :
12 fX(x), fY(y), fR(0), fPhi(0)
13{
14}
15
16bool Ring::CalcCenter(Led i, Led j, Led k)
17{
18 double h1 = i.GetY() - j.GetY();
19
20 if (h1==0)
21 {
22 std::swap(j, k);
23 h1 = i.GetY() - j.GetY();
24 if (h1==0)
25 {
26 cout << "Ring::CalcCenter: h1==0" <<endl;
27 return false;
28 }
29 }
30
31 double h2 = j.GetY() - k.GetY();
32
33 if (h2==0)
34 {
35 std::swap(i, j);
36 h2 = j.GetY() - k.GetY();
37 if (h2==0)
38 {
39 cout << "Ring::CalcCenter: h2==0" << endl;
40 return false;
41 }
42 }
43
44 const double w1 = i.GetX() - j.GetX();
45 const double w2 = j.GetX() - k.GetX();
46
47 const double m1 = -w1/h1;
48 const double m2 = -w2/h2;
49
50 if (m2 - m1==0)
51 {
52 cout << "Ring::CalcCenter: All three points in a row! (m2-m1==0)" << endl;
53 return false;
54 }
55
56 fX = ((m2*(j.GetX() + k.GetX()) + i.GetY() - k.GetY() -m1*(i.GetX() + j.GetX()))/(m2-m1)/2);
57 fY = ((m2*(i.GetY() + j.GetY()) + m1*m2*(k.GetX() - i.GetX())-m1*(j.GetY() + k.GetY()))/(m2-m1)/2);
58
59 fR = hypot(fX - i.GetX(), fY - i.GetY());
60
61 fMag = (i.GetMag() + j.GetMag() + k.GetMag())/3;
62
63 return true;
64}
65
66void Ring::InterpolCenters(const vector<Ring> &rings)
67{
68 fX = 0;
69 fY = 0;
70 fR = 0;
71
72 fMag=0;
73
74 const int n=rings.size();
75 if (n==0)
76 return;
77
78 for (auto it=rings.begin(); it!=rings.end(); it++)
79 {
80 fX += it->GetX();
81 fY += it->GetY();
82 fR += it->GetR();
83 fMag += it->GetMag();
84 }
85
86 fX /= n;
87 fY /= n;
88 fR /= n;
89 fMag /= n;
90}
Note: See TracBrowser for help on using the repository browser.