Commit f16b4da1 authored by Davis King's avatar Davis King

Added the rotate_point() function.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402978
parent 47514d18
......@@ -1244,6 +1244,25 @@ namespace dlib
typedef vector<long,2> point;
// ----------------------------------------------------------------------------------------
template <typename T>
const dlib::vector<T,2> rotate_point (
const dlib::vector<T,2>& center,
dlib::vector<T,2> p,
double angle
)
{
p -= center;
dlib::vector<double,2> temp;
const double cos_angle = cos(angle);
const double sin_angle = sin(angle);
temp.x() = cos_angle*p.x() - sin_angle*p.y();
temp.y() = sin_angle*p.x() + cos_angle*p.y();
return temp + center;
}
// ----------------------------------------------------------------------------------------
}
......
......@@ -431,6 +431,24 @@ namespace dlib
typedef vector<long,2> point;
// ----------------------------------------------------------------------------------------
template <typename T>
const dlib::vector<T,2> rotate_point (
const dlib::vector<T,2> center,
const dlib::vector<T,2> p,
double angle
);
/*!
ensures
- returns a point P such that:
- P is the point p rotated counter-clockwise around the given
center point by angle radians.
(Note that this is counter clockwise with respect to the normal
coordinate system with positive y going up and positive x going
to the right)
!*/
// ----------------------------------------------------------------------------------------
}
......
......@@ -269,6 +269,22 @@ namespace
}
{
const double pi = 3.1415926535898;
point p1, center;
center = point(3,4);
p1 = point(10,4);
DLIB_TEST(rotate_point(center, p1, pi/2) == point(3,7+4));
center = point(3,3);
p1 = point(10,3);
DLIB_TEST(rotate_point(center, p1, pi/4) == point(8,8));
DLIB_TEST(rotate_point(center, p1, -pi/4) == point(8,-2));
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment