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
263e64dd
Commit
263e64dd
authored
May 28, 2018
by
Davis King
Browse files
Added polygon_area()
parent
a40614e5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
0 deletions
+38
-0
dlib/geometry/vector.h
dlib/geometry/vector.h
+23
-0
dlib/geometry/vector_abstract.h
dlib/geometry/vector_abstract.h
+15
-0
No files found.
dlib/geometry/vector.h
View file @
263e64dd
...
...
@@ -1306,6 +1306,29 @@ namespace dlib
return
(
s0
>
0
&&
s1
>
0
&&
s2
>
0
&&
s3
>
0
)
||
(
s0
<
0
&&
s1
<
0
&&
s2
<
0
&&
s3
<
0
);
}
// ----------------------------------------------------------------------------------------
template
<
typename
array_of_dpoints
>
inline
double
polygon_area
(
const
array_of_dpoints
&
pts
)
{
if
(
pts
.
size
()
<=
2
)
return
0
;
double
val
=
0
;
for
(
size_t
i
=
1
;
i
<
pts
.
size
();
++
i
)
val
+=
(
double
)
pts
[
i
].
x
()
*
pts
[
i
-
1
].
y
()
-
pts
[
i
].
y
()
*
pts
[
i
-
1
].
x
();
const
size_t
end
=
pts
.
size
()
-
1
;
val
+=
(
double
)
pts
[
0
].
x
()
*
pts
[
end
].
y
()
-
pts
[
0
].
y
()
*
pts
[
end
].
x
();
return
std
::
abs
(
val
)
/
2.0
;
}
// ----------------------------------------------------------------------------------------
...
...
dlib/geometry/vector_abstract.h
View file @
263e64dd
...
...
@@ -456,6 +456,21 @@ namespace dlib
false if not.
!*/
// ----------------------------------------------------------------------------------------
template
<
typename
array_of_dpoints
>
double
polygon_area
(
const
array_of_dpoints
&
pts
);
/*!
ensures
- If you walk the points pts in order to make a closed polygon, what is its
area? This function returns that area. It uses the shoelace formula to
compute the result and so works for general non-self-intersecting polygons.
!*/
// ----------------------------------------------------------------------------------------
}
...
...
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