bezier_curve.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright 2018 ROBOTIS CO., LTD.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *******************************************************************************/
16 
17 /*
18  * bezier_curve.cpp
19  *
20  * Created on: 2016. 8. 12.
21  * Author: Jay Song
22  */
23 
25 
26 using namespace robotis_framework;
27 
29 {
30 
31 }
32 
34 {
35 
36 }
37 
38 void BezierCurve::setBezierControlPoints(const std::vector<Point2D>& points)
39 {
40  control_points_.clear();
41  control_points_ = points;
42 }
43 
45 {
46  if(t > 1)
47  t = 1;
48  else if(t < 0)
49  t = 0;
50 
51  int points_num = control_points_.size();
52  Point2D point_at_t;
53  point_at_t.x = 0;
54  point_at_t.y = 0;
55 
56  if(points_num < 2)
57  return point_at_t;
58 
59  point_at_t.x = control_points_[0].x * powDI(1-t, points_num - 1);
60  point_at_t.y = control_points_[0].y * powDI(1-t, points_num - 1);
61 
62  for(unsigned int i = 1; i < (points_num - 1); i++)
63  {
64  point_at_t.x += control_points_[i].x * combination(points_num - 1, i)* powDI(1-t, points_num - 1 - i)*powDI(t, i);
65  point_at_t.y += control_points_[i].y * combination(points_num - 1, i)* powDI(1-t, points_num - 1 - i)*powDI(t, i);
66  }
67 
68  point_at_t.x += control_points_[points_num - 1].x * powDI(t, points_num - 1);
69  point_at_t.y += control_points_[points_num - 1].y * powDI(t, points_num - 1);
70 
71  return point_at_t;
72 }
73 
std::vector< Point2D > control_points_
Definition: bezier_curve.h:46
int combination(int n, int r)
double powDI(double a, int b)
void setBezierControlPoints(const std::vector< Point2D > &points)


robotis_math
Author(s): SCH , Kayman , Jay Song
autogenerated on Fri Jul 17 2020 03:17:50