LARS
LARS (Light Augmented Reality System) is an open-source framework for light-based interaction and real-time tracking in multi-robot experiments. Inspired by ARK, LARS extends the augmented reality paradigm to robotic collectives by projecting dynamic visual cues and environments onto the arena, enabling new experimental possibilities for collective robotics research, education, and outreach. LARS features integrated tracking, light projection, and modular experiment control with a user-friendly Qt GUI.
Loading...
Searching...
No Matches
line_2d.h
Go to the documentation of this file.
1// -*-c++-*-
2
7
8/*
9 *Copyright:
10
11 Copyright (C) Hidehisa Akiyama
12
13 This code is free software; you can redistribute it and/or
14 modify it under the terms of the GNU Lesser General Public
15 License as published by the Free Software Foundation; either
16 version 3 of the License, or (at your option) any later version.
17
18 This library is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Lesser General Public License for more details.
22
23 You should have received a copy of the GNU Lesser General Public
24 License along with this library; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
27 *EndCopyright:
28 */
29
31
32#ifndef RCSC_GEOM_LINE2D_H
33#define RCSC_GEOM_LINE2D_H
34
35#include <geom/vector_2d.h>
36
37#include <cmath>
38
39namespace rcsc {
40
47class Line2D {
48public:
49
50 static const double EPSILON;
51 static const double ERROR_VALUE;
52
53private:
54
55 double M_a;
56 double M_b;
57 double M_c;
58
59 // never used
60 Line2D();
61
62public:
69 Line2D( const double & a,
70 const double & b,
71 const double & c )
72 : M_a( a )
73 , M_b( b )
74 , M_c( c )
75 { }
76
82 Line2D( const Vector2D & p1,
83 const Vector2D & p2 )
84 {
85 assign( p1, p2 );
86 }
87
93 Line2D( const Vector2D & origin,
94 const AngleDeg & linedir )
95 {
96 assign( origin, linedir );
97 }
98
105 const
106 Line2D & assign( const Vector2D & p1,
107 const Vector2D & p2 )
108 {
109 M_a = -( p2.y - p1.y );
110 M_b = p2.x - p1.x;
111 M_c = -M_a * p1.x - M_b * p1.y;
112 return *this;
113 }
114
121 const
122 Line2D & assign( const Vector2D & origin,
123 const AngleDeg & linedir )
124 {
125 M_a = - linedir.sin();
126 M_b = linedir.cos();
127 M_c = -M_a * origin.x - M_b * origin.y;
128 return *this;
129 }
130
135 const
136 double & a() const
137 {
138 return M_a;
139 }
140
145 const
146 double & getA() const
147 {
148 return M_a;
149 }
150
155 const
156 double & b() const
157 {
158 return M_b;
159 }
160
169 const
170 double & getB() const
171 {
172 return M_b;
173 }
174
179 const
180 double & c() const
181 {
182 return M_c;
183 }
184
189 const
190 double & getC() const
191 {
192 return M_c;
193 }
194
200 double getX( const double & y ) const
201 {
202 if ( std::fabs( M_a ) < EPSILON )
203 {
204 return ERROR_VALUE;
205 }
206 return -( M_b * y + M_c ) / M_a;
207 }
208
214 double getY( const double & x ) const
215 {
216 if ( std::fabs( M_b ) < EPSILON )
217 {
218 return ERROR_VALUE;
219 }
220
221 return -( M_a * x + M_c ) / M_b;
222 }
223
229 double dist( const Vector2D & p ) const
230 {
231 return std::fabs( ( M_a * p.x + M_b * p.y + M_c )
232 / std::sqrt( M_a * M_a + M_b * M_b ) );
233 }
234
239 double dist2( const Vector2D & p ) const
240 {
241 double d = M_a * p.x + M_b * p.y + M_c;
242 return (d * d) / (M_a * M_a + M_b * M_b);
243 }
244
251 bool isParallel( const Line2D & line ) const
252 {
253 return std::fabs( a() * line.b() - line.a() * b() ) < EPSILON;
254 }
255
262 Vector2D intersection( const Line2D & line ) const
263 {
264 return intersection( *this, line );
265 }
266
272 Line2D perpendicular( const Vector2D & p ) const
273 {
274 return Line2D( b(), -a(), a() * p.y - b() * p.x );
275 }
276
282 Vector2D projection( const Vector2D & p ) const
283 {
284 return intersection( perpendicular( p ) );
285 }
286
287 // static utility
288
296 static
297 Vector2D intersection( const Line2D & line1,
298 const Line2D & line2 );
299
307 static
308 Line2D angle_bisector( const Vector2D & origin,
309 const AngleDeg & left,
310 const AngleDeg & right )
311 {
312 return Line2D( origin, AngleDeg::bisect( left, right ) );
313 }
314
321 static
323 const Vector2D & p2 );
324
325};
326
327}
328
329#endif
degree wrapper class
Definition angle_deg.h:45
double cos() const
calculate cosine
Definition angle_deg.h:301
static AngleDeg bisect(const AngleDeg &left, const AngleDeg &right)
static utility that returns bisect angle of [left, right].
Definition angle_deg.cpp:177
double sin() const
calculate sine
Definition angle_deg.h:310
2d straight line class
Definition line_2d.h:47
static const double ERROR_VALUE
error value
Definition line_2d.h:51
Line2D(const Vector2D &origin, const AngleDeg &linedir)
construct from origin point + direction
Definition line_2d.h:93
static const double EPSILON
tolerance threshold
Definition line_2d.h:50
const double & getA() const
accessor
Definition line_2d.h:146
const Line2D & assign(const Vector2D &p1, const Vector2D &p2)
construct from 2 points
Definition line_2d.h:106
const Line2D & assign(const Vector2D &origin, const AngleDeg &linedir)
construct from origin point + direction
Definition line_2d.h:122
double dist2(const Vector2D &p) const
get squared distance from this line to point
Definition line_2d.h:239
const double & getC() const
accessor
Definition line_2d.h:190
static Line2D angle_bisector(const Vector2D &origin, const AngleDeg &left, const AngleDeg &right)
make angle bisector line from two angles
Definition line_2d.h:308
Line2D(const double &a, const double &b, const double &c)
construct directly
Definition line_2d.h:69
double dist(const Vector2D &p) const
calculate distance from point to this line
Definition line_2d.h:229
static Line2D perpendicular_bisector(const Vector2D &p1, const Vector2D &p2)
make perpendicular bisector line from twt points
Definition line_2d.cpp:69
bool isParallel(const Line2D &line) const
check if the slope of this line is same to the slope of 'line'
Definition line_2d.h:251
Vector2D projection(const Vector2D &p) const
calc projection point from p
Definition line_2d.h:282
const double & getB() const
accessor
Definition line_2d.h:170
Line2D(const Vector2D &p1, const Vector2D &p2)
construct from 2 points
Definition line_2d.h:82
double getY(const double &x) const
get Y-coordinate correspond to 'x'
Definition line_2d.h:214
double getX(const double &y) const
get X-coordinate correspond to 'y'
Definition line_2d.h:200
const double & a() const
accessor
Definition line_2d.h:136
const double & b() const
accessor
Definition line_2d.h:156
Line2D perpendicular(const Vector2D &p) const
calc perpendicular line (SUI-SEN)
Definition line_2d.h:272
Vector2D intersection(const Line2D &line) const
get the intersection point with 'line'
Definition line_2d.h:262
const double & c() const
accessor
Definition line_2d.h:180
2D point vector class
Definition vector_2d.h:47
double y
Y coordinate.
Definition vector_2d.h:65
double x
X coordinate.
Definition vector_2d.h:64
2d vector class Header File.