claw 1.9.0
 
Loading...
Searching...
No Matches
curve.hpp
Go to the documentation of this file.
1/*
2 CLAW - a C++ Library Absolutely Wonderful
3
4 CLAW is a free library without any particular aim but being useful to
5 anyone.
6
7 Copyright (C) 2005-2011 Julien Jorge
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 contact: julien.jorge@stuff-o-matic.com
23*/
29#ifndef __CLAW_MATH_CURVE_HPP__
30#define __CLAW_MATH_CURVE_HPP__
31
33#include <list>
34#include <vector>
35
36namespace claw
37{
38 namespace math
39 {
48 template <typename C, typename Traits = coordinate_traits<C> >
49 class curve
50 {
51 public:
53 typedef C coordinate_type;
54
57 typedef Traits traits_type;
58
60 typedef typename traits_type::value_type value_type;
61
67 class control_point
68 {
69 public:
71 typedef C coordinate_type;
72
73 public:
74 control_point();
75 explicit control_point(const coordinate_type& p);
76 control_point(const coordinate_type& p,
77 const coordinate_type& input_direction,
78 const coordinate_type& output_direction);
79
80 const coordinate_type& get_position() const;
81 const coordinate_type& get_input_direction() const;
82 const coordinate_type& get_output_direction() const;
83
84 private:
86 coordinate_type m_position;
87
90 coordinate_type m_input_direction;
91
94 coordinate_type m_output_direction;
95
96 }; // class control_point
97
98 private:
101 typedef std::list<control_point> control_point_list;
102
103 public:
106 typedef typename control_point_list::iterator iterator;
107
110 typedef typename control_point_list::const_iterator const_iterator;
111
116 class section
117 {
118 public:
121
124 typedef Traits traits_type;
125
127 typedef typename traits_type::value_type value_type;
128
131
136 class resolved_point
137 {
138 public:
141
142 public:
143 resolved_point(const coordinate_type& position, const section& s,
144 const double t);
145
146 const coordinate_type& get_position() const;
147 const section& get_section() const;
148 double get_date() const;
149
150 private:
152 coordinate_type m_position;
153
155 section m_section;
156
158 double m_date;
159
160 }; // class resolved_point
161
162 public:
163 section(const iterator_type& origin, const iterator_type& end);
164
165 coordinate_type get_point_at(double t) const;
166 coordinate_type get_tangent_at(double t) const;
167 std::vector<resolved_point>
168 get_point_at_x(value_type x, bool off_domain = false) const;
169
170 const iterator_type& get_origin() const;
171
172 bool empty() const;
173
174 private:
175 value_type evaluate(double t, value_type origin,
176 value_type output_direction,
177 value_type input_direction, value_type end) const;
178 value_type evaluate_derived(double t, value_type origin,
179 value_type output_direction,
180 value_type input_direction,
181 value_type end) const;
182
183 void ensure_ends_in_points(std::vector<resolved_point>& p,
184 bool ensure_origin, bool ensure_end) const;
185
186 std::vector<resolved_point>
187 extract_domain_points(const std::vector<resolved_point>& p) const;
188
189 std::vector<double> get_roots(value_type x, value_type origin,
190 value_type output_direction,
191 value_type input_direction,
192 value_type end) const;
193
194 std::vector<double> get_roots_degree_2(value_type a, value_type b,
195 value_type c) const;
196 std::vector<double> get_roots_degree_3(value_type a, value_type b,
197 value_type c,
198 value_type d) const;
199
200 private:
202 iterator_type m_origin;
203
205 iterator_type m_end;
206
207 }; // class section
208
209 public:
210 void push_back(const control_point& p);
211 void push_front(const control_point& p);
212 void insert(const iterator& pos, const control_point& p);
213
214 section get_section(const const_iterator& pos) const;
215
216 std::vector<typename section::resolved_point>
217 get_point_at_x(value_type x, bool off_domain = false) const;
218
219 iterator begin();
220 iterator end();
221 const_iterator begin() const;
222 const_iterator end() const;
223
224 private:
225 std::vector<typename section::resolved_point>
226 get_point_at_x_before_origin(value_type x) const;
227 std::vector<typename section::resolved_point>
228 get_point_at_x_after_end(value_type x) const;
229
230 private:
232 control_point_list m_points;
233
234 }; // class curve
235
236 }
237}
238
239#include "claw/curve.tpp"
240
241#endif // __CLAW_MATH_CURVE_HPP__
The control_point class describes a control point of the curve, with the direction of the curve befor...
Definition curve.hpp:68
C coordinate_type
The type of the coordinates of the curve.
Definition curve.hpp:71
C coordinate_type
The type of the coordinates of the curve.
Definition curve.hpp:140
A section is a part of the curve between two control points.
Definition curve.hpp:117
const_iterator iterator_type
The type of the iterators on the ends of the section.
Definition curve.hpp:130
C coordinate_type
The type of the coordinates of the curve.
Definition curve.hpp:120
Traits traits_type
The traits provide an access to the properties of the coordinates.
Definition curve.hpp:124
traits_type::value_type value_type
The type of the components of the coordinates.
Definition curve.hpp:127
Implementation of the Bézier curve.
Definition curve.hpp:50
control_point_list::iterator iterator
The type of the iterator on the control points of the curve.
Definition curve.hpp:106
traits_type::value_type value_type
The type of the components of the coordinates.
Definition curve.hpp:60
Traits traits_type
The traits provide an access to the properties of the coordinates.
Definition curve.hpp:57
C coordinate_type
The type of the coordinates of the curve.
Definition curve.hpp:53
control_point_list::const_iterator const_iterator
The type of the iterator on the control points of the curve.
Definition curve.hpp:110
The coordinate traits provide an access to the members of the structures representing a coordinate in...
Manipulation of mathematic, geometric, etc. items.
Definition box_2d.hpp:38
This is the main namespace.