Main Page · Modules · All Classes · Class Hierarchy
MEDefs.cpp
1 /*
2  * This file is part of the AiBO+ project
3  *
4  * Copyright (C) 2005-2016 Csaba Kertész (csaba.kertesz@gmail.com)
5  *
6  * AiBO+ is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * AiBO+ is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
19  *
20  */
21 
22 #include "MEDefs.hpp"
23 
24 #include <boost/math/constants/constants.hpp>
25 
26 #include <math.h>
27 
28 MEColor::MEColor(unsigned char red, unsigned char green, unsigned char blue) :
29  Red(red), Green(green), Blue(blue)
30 {
31 }
32 
33 
34 MEPoint::MEPoint(int x, int y) : X(x), Y(y)
35 {
36 }
37 
38 
39 bool MEPoint::IsValid() const
40 {
41  return X >= 0 && Y >= 0;
42 }
43 
44 
45 float MEGetInteriorAngle(const MEPoint& point1, const MEPoint& point2, const MEPoint& point3)
46 {
47  float p12 = sqrt((float)((point1.X-point3.X)*(point1.X-point3.X)+(point1.Y-point3.Y)*(point1.Y-point3.Y)));
48  float p13 = sqrt((float)((point1.X-point2.X)*(point1.X-point2.X)+(point1.Y-point2.Y)*(point1.Y-point2.Y)));
49  float p23 = sqrt((float)((point3.X-point2.X)*(point3.X-point2.X)+(point3.Y-point2.Y)*(point3.Y-point2.Y)));
50 
51  return (float)acos((p12*p12+p13*p13-p23*p23) / (2*p12*p13))*180 / boost::math::constants::pi<float>();
52 }
53 
54 
55 MEPoint MEComputeLineIntersection(const MEPoint& line1_point1, const MEPoint& line1_point2,
56  const MEPoint& line2_point1, const MEPoint& line2_point2)
57 {
58  int x1 = line1_point1.X;
59  int y1 = line1_point1.Y;
60  int x2 = line1_point2.X;
61  int y2 = line1_point2.Y;
62  int x3 = line2_point1.X;
63  int y3 = line2_point1.Y;
64  int x4 = line2_point2.X;
65  int y4 = line2_point2.Y;
66  int Distance = (x1-x2)*(y3-y4)-(y1-y2)*(x3-x4);
67 
68  if (Distance)
69  {
70  MEPoint Point;
71 
72  Point.X = (int)((float)((x1*y2-y1*x2)*(x3-x4)-(x1-x2)*(x3*y4-y3*x4)) / Distance);
73  Point.Y = (int)((float)((x1*y2-y1*x2)*(y3-y4)-(y1-y2)*(x3*y4-y3*x4)) / Distance);
74  return Point;
75  }
76  return MEPoint(-1, -1);
77 }
int X
X position.
Definition: MEDefs.hpp:63
float MEGetInteriorAngle(const MEPoint &point1, const MEPoint &point2, const MEPoint &point3)
Get the interior angle between three points.
Definition: MEDefs.cpp:45
int Y
Y position.
Definition: MEDefs.hpp:65
Point.
Definition: MEDefs.hpp:56
MEPoint MEComputeLineIntersection(const MEPoint &line1_point1, const MEPoint &line1_point2, const MEPoint &line2_point1, const MEPoint &line2_point2)
Compute intersection point between two lines.
Definition: MEDefs.cpp:55