Objective
Creating a simple skeleton line from 2D polygon (CAD-Based) for CAD purpose. Small lines shall be avoided.
State of work
- Created Voronoi Diagram for polygon
- Used DFS for identifying branches of voronoi vertices/edges
- Used Shapely Line String (Ramer-Douglas-Peucker) to simplify the lines
Problem
Ramer-Douglas-Peucker is not able to simplify the line as desired. If increasing the RDP tolerance, results are not satisfactory. The target should be to represent the polygon as good as possible with least lines possible. Horizontal segments should be represented by horizontal lines instead of small-angled ones. RDP tries to consider only the points given in the data. The desired result should contain points which are not part of the branch before (see images).
Example image (Starting point: Medial axis) Starting point: Medial axis
Example image (Desired result) Desired result
I packed the point data to : Link To Data
Example code for Shapely simplification
import numpy as np
import matplotlib.pyplot as plt
from shapely.geometry import LineString
##########################
pathToFile = ""
RDP_Tolerance= 2
##########################
data = np.genfromtxt(pathToFile )
plt.figure()
plt.plot(data[:,0],data[:,1])
plt.scatter(data[:,0],data[:,1])
plt.axis('equal')
plt.show()
linestring = LineString(data)
lineStringSimplified = linestring.simplify(RDP_Tolerance)
simplifiedData = np.asarray(lineStringSimplified.coords)
plt.figure()
plt.plot(simplifiedData [:,0],simplifiedData [:,1])
plt.scatter(simplifiedData [:,0],simplifiedData [:,1])
plt.axis('equal')
plt.show()