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
triangle_2d.h
Go to the documentation of this file.
1// -*-c++-*-
2
7
8/*
9 *Copyright:
10
11 Copyright (C) Hidehisa Akiyama, Hiroki Shimora
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_TRIANGLE2D_H
33#define RCSC_GEOM_TRIANGLE2D_H
34
35#include <geom/region_2d.h>
36#include <geom/vector_2d.h>
37#include <geom/segment_2d.h>
38
39namespace rcsc {
40
41class Line2D;
42class Ray2D;
43
48class Triangle2D
49 : public Region2D {
50private:
51 Vector2D M_a;
52 Vector2D M_b;
53 Vector2D M_c;
54
56 Triangle2D();
57public:
64 Triangle2D( const Vector2D & v1,
65 const Vector2D & v2,
66 const Vector2D & v3 )
67 : M_a( v1 )
68 , M_b( v2 )
69 , M_c( v3 )
70 { }
71
77 Triangle2D( const Segment2D & seg,
78 const Vector2D & v )
79 : M_a( seg.origin() )
80 , M_b( seg.terminal() )
81 , M_c( v )
82 { }
83
91 const
92 Triangle2D & assign( const Vector2D & v1,
93 const Vector2D & v2,
94 const Vector2D & v3 )
95 {
96 M_a = v1;
97 M_b = v2;
98 M_c = v3;
99 return *this;
100 }
101
106 bool isValid() const
107 {
108 return M_a.isValid()
109 && M_b.isValid()
110 && M_c.isValid()
111 && M_a != M_b
112 && M_b != M_c
113 && M_a != M_a;
114 }
115
122 const
123 Triangle2D & assign( const Segment2D & seg,
124 const Vector2D & v )
125 {
126 M_a = seg.origin();
127 M_b = seg.terminal();
128 M_c = v;
129 return *this;
130 }
131
136 const
137 Vector2D & a() const
138 {
139 return M_a;
140 }
141
146 const
147 Vector2D & b() const
148 {
149 return M_b;
150 }
151
156 const
157 Vector2D & c() const
158 {
159 return M_c;
160 }
161
166 virtual
167 double area() const
168 {
169 // outer product == area of parallelogram(Heikou Shihenkei)
170 // triangle area is a half of parallelogram area
171 return std::fabs( ( b() - a() ).outerProduct( c() - a() ) ) * 0.5;
172 }
173
181 double signedArea() const
182 {
183 //return doubleSignedArea() / 2.0;
184 return signed_area( a(), b(), c() );
185 }
186
194 double doubleSignedArea() const
195 {
196 //return ( ( a().x - c().x ) * ( b().y - c().y )
197 // + ( b().x - c().x ) * ( c().y - a().y ) );
198 return double_signed_area( a(), b(), c() );
199 }
200
205 bool ccw() const
206 {
207 return ccw( a(), b(), c() );
208 }
209
215 virtual
216 bool contains( const Vector2D & point ) const;
217
223 {
224 return centroid( a(), b(), c() );
225 }
226
232 {
233 return incenter( a(), b(), c() );
234 }
235
241 {
242 return circumcenter( a(), b(), c() );
243 }
244
250 {
251 return orthocenter( a(), b(), c() );
252 }
253
254 //brief get the excenter coordinates(BOU-SIN)
255 //return coordinates of excenter
256 //Vector2D excenter() const;
257
265 int intersection( const Line2D & line,
266 Vector2D * sol1,
267 Vector2D * sol2 ) const;
268
276 int intersection( const Ray2D & ray,
277 Vector2D * sol1,
278 Vector2D * sol2 ) const;
279
287 int intersection( const Segment2D & segment,
288 Vector2D * sol1,
289 Vector2D * sol2 ) const;
290
291
292 //
293 // static methods
294 //
295
306 static
308 const Vector2D & b,
309 const Vector2D & c )
310 {
311 return ( ( a.x - c.x ) * ( b.y - c.y )
312 + ( b.x - c.x ) * ( c.y - a.y ) );
313 }
314
325 static
326 double signed_area( const Vector2D & a,
327 const Vector2D & b,
328 const Vector2D & c )
329 {
330 return double_signed_area( a, b, c ) * 0.5;
331 }
332
340 static
341 bool ccw( const Vector2D & a,
342 const Vector2D & b,
343 const Vector2D & c )
344 {
345 return double_signed_area( a, b, c ) > 0.0;
346 }
347
357 static
359 const Vector2D & b,
360 const Vector2D & c )
361 {
362 //Vector2D g( a );
363 //g += b;
364 //g += c;
365 //g /= 3.0;
366 //return g;
367 return Vector2D( a ).add( b ).add( c ) /= 3.0;
368 }
369
377 static
378 Vector2D incenter( const Vector2D & a,
379 const Vector2D & b,
380 const Vector2D & c );
381
389 static
391 const Vector2D & b,
392 const Vector2D & c );
393
403 static
405 const Vector2D & b,
406 const Vector2D & c );
407
416 static
417 bool contains( const Vector2D & a,
418 const Vector2D & b,
419 const Vector2D & c,
420 const Vector2D & point );
421
422};
423
424}
425
426#endif
2d straight line class
Definition line_2d.h:47
2D ray line class
Definition ray_2d.h:44
Region2D()
accessible only from derived classes
Definition region_2d.h:49
2d segment line class
Definition segment_2d.h:46
const Vector2D & terminal() const
get 2nd point of segment edge
Definition segment_2d.h:176
const Vector2D & origin() const
get 1st point of segment edge
Definition segment_2d.h:166
Vector2D centroid() const
get the center of gravity(centroid, JUU-SIN)
Definition triangle_2d.h:222
Triangle2D(const Segment2D &seg, const Vector2D &v)
constructor with a segment and a point
Definition triangle_2d.h:77
static Vector2D centroid(const Vector2D &a, const Vector2D &b, const Vector2D &c)
get the center of gravity(JUU-SIN)
Definition triangle_2d.h:358
const Vector2D & b() const
get 2nd point
Definition triangle_2d.h:147
const Triangle2D & assign(const Segment2D &seg, const Vector2D &v)
assign new segment and vertex point
Definition triangle_2d.h:123
Vector2D orthocenter() const
get the orthocenter(SUI-SIN)
Definition triangle_2d.h:249
static double double_signed_area(const Vector2D &a, const Vector2D &b, const Vector2D &c)
get a double signed area value (== area of parallelogram)
Definition triangle_2d.h:307
static double signed_area(const Vector2D &a, const Vector2D &b, const Vector2D &c)
get a signed area value
Definition triangle_2d.h:326
double signedArea() const
get a signed area. this method is equivalent to signed_area().
Definition triangle_2d.h:181
virtual double area() const
get the area of this region
Definition triangle_2d.h:167
const Vector2D & c() const
get 3rd point
Definition triangle_2d.h:157
const Triangle2D & assign(const Vector2D &v1, const Vector2D &v2, const Vector2D &v3)
assign new vertex points
Definition triangle_2d.h:92
const Vector2D & a() const
get 1st point
Definition triangle_2d.h:137
bool ccw() const
check if this triangle's vertices are placed counterclockwise order.
Definition triangle_2d.h:205
bool isValid() const
check if this triangle is valid or not.
Definition triangle_2d.h:106
Triangle2D(const Vector2D &v1, const Vector2D &v2, const Vector2D &v3)
constructor with variables
Definition triangle_2d.h:64
static bool ccw(const Vector2D &a, const Vector2D &b, const Vector2D &c)
check if input vertices are placed counterclockwise order.
Definition triangle_2d.h:341
double doubleSignedArea() const
get a double of signed area value. this method is equivalent to double_signed_area().
Definition triangle_2d.h:194
Vector2D circumcenter() const
get the center of circumscribed circle(GAI-SIN)
Definition triangle_2d.h:240
Vector2D incenter() const
get the center of inscribed circle(NAI-SIN)
Definition triangle_2d.h:231
virtual bool contains(const Vector2D &point) const
check if this triangle contains 'point'.
Definition triangle_2d.cpp:51
int intersection(const Line2D &line, Vector2D *sol1, Vector2D *sol2) const
calculate intersection point with line.
Definition triangle_2d.cpp:75
2D point vector class
Definition vector_2d.h:47
Vector2D & add(const Vector2D &v)
add vector.
Definition vector_2d.h:240
2d vector class Header File.
abstract 2D region class Header File.
2D segment line Header File.