Main Page
Namespaces
Classes
Files
File List
File Members
src
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
24
#include "
robotis_math/bezier_curve.h
"
25
26
using namespace
robotis_framework
;
27
28
BezierCurve::BezierCurve
()
29
{
30
31
}
32
33
BezierCurve::~BezierCurve
()
34
{
35
36
}
37
38
void
BezierCurve::setBezierControlPoints
(
const
std::vector<Point2D>& points)
39
{
40
control_points_
.clear();
41
control_points_
= points;
42
}
43
44
Point2D
BezierCurve::getPoint
(
double
t)
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
robotis_framework::BezierCurve::control_points_
std::vector< Point2D > control_points_
Definition:
bezier_curve.h:46
robotis_framework::Point2D::y
double y
Definition:
robotis_math_base.h:50
robotis_framework::Point2D::x
double x
Definition:
robotis_math_base.h:50
robotis_framework::combination
int combination(int n, int r)
Definition:
robotis_math_base.cpp:32
robotis_framework::BezierCurve::BezierCurve
BezierCurve()
Definition:
bezier_curve.cpp:28
bezier_curve.h
robotis_framework::BezierCurve::getPoint
Point2D getPoint(double t)
Definition:
bezier_curve.cpp:44
robotis_framework::BezierCurve::~BezierCurve
~BezierCurve()
Definition:
bezier_curve.cpp:33
robotis_framework::powDI
double powDI(double a, int b)
Definition:
robotis_math_base.h:39
robotis_framework
Definition:
bezier_curve.h:32
robotis_framework::BezierCurve::setBezierControlPoints
void setBezierControlPoints(const std::vector< Point2D > &points)
Definition:
bezier_curve.cpp:38
robotis_framework::Point2D
Definition:
robotis_math_base.h:48
robotis_math
Author(s): SCH
, Kayman
, Jay Song
autogenerated on Fri Jul 17 2020 03:17:50