Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
32652774
Commit
32652774
authored
Feb 27, 2012
by
Davis King
Browse files
Added dcenter(), point_transform_affine, and rotation_matrix()
parent
1940012f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
109 additions
and
0 deletions
+109
-0
dlib/geometry/rectangle.h
dlib/geometry/rectangle.h
+12
-0
dlib/geometry/rectangle_abstract.h
dlib/geometry/rectangle_abstract.h
+10
-0
dlib/geometry/vector.h
dlib/geometry/vector.h
+39
-0
dlib/geometry/vector_abstract.h
dlib/geometry/vector_abstract.h
+48
-0
No files found.
dlib/geometry/rectangle.h
View file @
32652774
...
...
@@ -379,6 +379,18 @@ namespace dlib
return
temp
/
2
;
}
// ----------------------------------------------------------------------------------------
inline
dlib
::
vector
<
double
,
2
>
dcenter
(
const
dlib
::
rectangle
&
rect
)
{
dlib
::
vector
<
double
,
2
>
temp
(
rect
.
left
()
+
rect
.
right
(),
rect
.
top
()
+
rect
.
bottom
());
return
temp
/
2.0
;
}
// ----------------------------------------------------------------------------------------
inline
long
distance_to_rect_edge
(
...
...
dlib/geometry/rectangle_abstract.h
View file @
32652774
...
...
@@ -412,6 +412,16 @@ namespace dlib
- returns the center of the given rectangle
!*/
// ----------------------------------------------------------------------------------------
dlib
::
vector
<
double
,
2
>
dcenter
(
const
dlib
::
rectangle
&
rect
);
/*!
ensures
- returns the center of the given rectangle using a real valued vector.
!*/
// ----------------------------------------------------------------------------------------
inline
const
rectangle
centered_rect
(
...
...
dlib/geometry/vector.h
View file @
32652774
...
...
@@ -1319,6 +1319,30 @@ namespace dlib
dlib
::
vector
<
double
,
2
>
translate
;
};
// ----------------------------------------------------------------------------------------
class
point_transform_affine
{
public:
point_transform_affine
(
const
matrix
<
double
,
2
,
2
>&
m_
,
const
dlib
::
vector
<
double
,
2
>&
b_
)
:
m
(
m_
),
b
(
b_
)
{
}
const
dlib
::
vector
<
double
,
2
>
operator
()
(
const
dlib
::
vector
<
double
,
2
>&
p
)
const
{
return
m
*
p
+
b
;
}
private:
matrix
<
double
,
2
,
2
>
m
;
dlib
::
vector
<
double
,
2
>
b
;
};
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
...
...
@@ -1332,6 +1356,21 @@ namespace dlib
return
rot
(
p
-
center
)
+
center
;
}
// ----------------------------------------------------------------------------------------
inline
matrix
<
double
,
2
,
2
>
rotation_matrix
(
double
angle
)
{
const
double
ca
=
cos
(
angle
);
const
double
sa
=
sin
(
angle
);
matrix
<
double
,
2
,
2
>
m
;
m
=
ca
,
-
sa
,
sa
,
ca
;
return
m
;
}
// ----------------------------------------------------------------------------------------
}
...
...
dlib/geometry/vector_abstract.h
View file @
32652774
...
...
@@ -431,6 +431,37 @@ namespace dlib
typedef
vector
<
long
,
2
>
point
;
// ----------------------------------------------------------------------------------------
class
point_transform_affine
{
/*!
WHAT THIS OBJECT REPRESENTS
This is an object that takes 2D points or vectors and
applies an affine transformation to them.
!*/
public:
point_transform_affine
(
const
matrix
<
double
,
2
,
2
>&
m
,
const
dlib
::
vector
<
double
,
2
>&
b
);
/*!
ensures
- When (*this)(p) is invoked it will return a point P such that:
- P == m*p + b
!*/
const
dlib
::
vector
<
double
,
2
>
operator
()
(
const
dlib
::
vector
<
double
,
2
>&
p
)
const
;
/*!
ensures
- applies the affine transformation defined by this object's constructor
to p and returns the result.
!*/
};
// ----------------------------------------------------------------------------------------
class
point_transform
...
...
@@ -517,6 +548,23 @@ namespace dlib
to the right)
!*/
// ----------------------------------------------------------------------------------------
matrix
<
double
,
2
,
2
>
rotation_matrix
(
double
angle
);
/*!
ensures
- returns a rotation matrix which rotates points around the origin in a
counter-clockwise direction 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)
Or in other words, this function returns a matrix M such that, given a
point P, M*P gives a point which is P rotated by angle radians around
the origin in a counter-clockwise direction.
!*/
// ----------------------------------------------------------------------------------------
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment