source: rrlib_geometry/tLine.h @ 74:933f1acf1484

14.08
Last change on this file since 74:933f1acf1484 was 74:933f1acf1484, checked in by Tobias Föhst <foehst@…>, 4 years ago

Adds detection of infinite intersection points for lines

File size: 5.7 KB
Line 
1//
2// You received this file as part of RRLib
3// Robotics Research Library
4//
5// Copyright (C) Finroc GbR (finroc.org)
6//
7// This program is free software; you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation; either version 2 of the License, or
10// (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License along
18// with this program; if not, write to the Free Software Foundation, Inc.,
19// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20//
21//----------------------------------------------------------------------
22/*!\file    tLine.h
23 *
24 * \author  Tobias Foehst
25 *
26 * \date    2010-12-27
27 *
28 * \brief   Contains tLine
29 *
30 * \b tLine
31 *
32 * A few words for tLine
33 *
34 */
35//----------------------------------------------------------------------
36#ifndef __rrlib__geometry__tLine_h__
37#define __rrlib__geometry__tLine_h__
38
39#include "rrlib/geometry/tShape.h"
40//----------------------------------------------------------------------
41// External includes (system with <>, local with "")
42//----------------------------------------------------------------------
43#ifdef _LIB_RRLIB_CANVAS_PRESENT_
44#include "rrlib/canvas/tCanvas2D.h"
45#endif
46
47//----------------------------------------------------------------------
48// Internal includes with ""
49//----------------------------------------------------------------------
50
51//----------------------------------------------------------------------
52// Debugging
53//----------------------------------------------------------------------
54
55//----------------------------------------------------------------------
56// Namespace declaration
57//----------------------------------------------------------------------
58namespace rrlib
59{
60namespace geometry
61{
62
63//----------------------------------------------------------------------
64// Forward declarations / typedefs / enums
65//----------------------------------------------------------------------
66enum tIntersectionType
67{
68  NONE,
69  SINGLE,
70  INFINITE
71};
72
73//----------------------------------------------------------------------
74// Class declaration
75//----------------------------------------------------------------------
76//! Short description of tLine
77/*! A more detailed description of tLine, which
78    Tobias Foehst hasn't done yet !!
79*/
80template <size_t Tdimension, typename TElement = double>
81class tLine : public tShape<Tdimension, TElement>
82{
83
84  typedef geometry::tShape<Tdimension, TElement> tShape;
85
86//----------------------------------------------------------------------
87// Public methods and typedefs
88//----------------------------------------------------------------------
89public:
90
91  typedef typename tShape::tPoint::tElement tParameter;
92
93  tLine();
94  tLine(const typename tShape::tPoint &support, const math::tVector<Tdimension, TElement> &direction);
95  tLine(const typename tShape::tPoint &support, const typename tShape::tPoint &second_support);
96
97  inline const typename tShape::tPoint &Support() const
98  {
99    return this->support;
100  }
101
102  inline const math::tVector<Tdimension, TElement> &Direction() const
103  {
104    return this->direction;
105  }
106
107  void Set(const typename tShape::tPoint &support, const math::tVector<Tdimension, TElement> &direction);
108
109  const typename tShape::tPoint operator()(tParameter t) const;
110
111  const TElement GetDistanceToPoint(const typename tShape::tPoint &point) const;
112
113  virtual const typename tShape::tPoint GetClosestPoint(const typename tShape::tPoint &reference_point) const;
114
115  tIntersectionType GetIntersection(typename tShape::tPoint &intersection_point, const tLine &line) const;
116
117  virtual tLine &Translate(const math::tVector<Tdimension, TElement> &translation);
118  virtual tLine &Rotate(const math::tMatrix<Tdimension, Tdimension, TElement> &rotation);
119  virtual tLine &Transform(const math::tMatrix < Tdimension + 1, Tdimension + 1, TElement > &transformation);
120
121//----------------------------------------------------------------------
122// Private fields and methods
123//----------------------------------------------------------------------
124private:
125
126  typename tShape::tPoint support;
127  typename math::tVector<Tdimension, TElement> direction;
128
129  virtual void UpdateBoundingBox(typename tShape::tBoundingBox &bounding_box) const;
130  virtual void UpdateCenterOfGravity(typename tShape::tPoint &center_of_gravity) const;
131
132};
133
134typedef tLine<2, double> tLine2D;
135typedef tLine<3, double> tLine3D;
136
137//----------------------------------------------------------------------
138// Explicit template instantiation
139//----------------------------------------------------------------------
140
141extern template class tLine<2, float>;
142extern template class tLine<3, float>;
143
144extern template class tLine<2, double>;
145extern template class tLine<3, double>;
146
147extern template class tLine<2, int>;
148extern template class tLine<3, int>;
149
150extern template class tLine<2, unsigned int>;
151extern template class tLine<3, unsigned int>;
152
153//----------------------------------------------------------------------
154// Operators for rrlib_canvas
155//----------------------------------------------------------------------
156#ifdef _LIB_RRLIB_CANVAS_PRESENT_
157
158template <typename TElement>
159canvas::tCanvas2D &operator << (canvas::tCanvas2D &canvas, const tLine<2, TElement> &line);
160
161#endif
162
163//----------------------------------------------------------------------
164// End of namespace declaration
165//----------------------------------------------------------------------
166}
167}
168
169
170#include "rrlib/geometry/tLine.hpp"
171
172#endif
Note: See TracBrowser for help on using the repository browser.