-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-Perpendicular distance -First Rameur-Douglas-Peucker algorithm
- Loading branch information
1 parent
49b46d5
commit d2b6668
Showing
7 changed files
with
156 additions
and
6,251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from .algorithms import * | ||
from .distance import * | ||
from .projections import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import logging | ||
|
||
from .distance import perpendicular_distance | ||
|
||
def ramer_douglas_peucker(points: list, epsilon: float = 1): | ||
""" | ||
Simplify a curve using the Ramer-Douglas-Peucker algorithm. | ||
Source: https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm | ||
Args: | ||
points (list[TrackPoint]): List of points defining the curve. | ||
epsilon (float, optional): _description_. Defaults to 1. | ||
Returns: | ||
list[TrackPoint]: List of points defining the simplified curve. | ||
""" | ||
# Find the point with the maximum distance | ||
d_max = 0 | ||
i_max = 0 | ||
|
||
start_point = points[0] | ||
end_point = points[len(points)-1] | ||
|
||
for i in range(1, len(points)-1): | ||
d = perpendicular_distance(start_point, end_point, points[i]) | ||
if d > d_max: | ||
d_max = d | ||
i_max = i | ||
|
||
logging.info(f"d_max = {d_max}") | ||
|
||
result = [] | ||
|
||
# If max distance is greater than epsilon, recursively simplify | ||
if d_max > epsilon: | ||
# Recursive call | ||
logging.info("rec") | ||
result_1 = ramer_douglas_peucker(points[0:i_max+1], epsilon) | ||
result_2 = ramer_douglas_peucker(points[i_max: len(points)], epsilon) | ||
|
||
# Build result list | ||
result = result_1 + result_2[1:] | ||
else: | ||
result = [start_point, end_point] | ||
|
||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.