Find the "middle" vector shape?
Algorithm proposal
-
Calculate the area of each shape {A}.
-
Find shape {S} with most points {N} (you will have a polygon with N sides)
-
Merge {S} with another form and create the first merged form {M}. Then merge {M} with each other. {M} will dynamically / overwrite / change every time it merges with another shape.
Merge function : pseudocode
First call Merge({S}, {S2})
, then call Merge({M}, {S2})
for the rest of the shapes.
Parameters:
{S1} = shape with most dots;
{S2} = form to merge with;
function Merge({S1}, {S2}):
FOR EACH {point} of {S1} DO
{near}=find nearest {S2}{point}
{size}=( SQRT({S1}{A}) + SQRT({S2}{A}) )/2
{line}=create line starting at {near}, going to/over {point} of length {size}
add point in {M} with position at half the {line}
END FOR
RETURN {M}
;
3 initial shapes: rectangle, triangle, 7 side polygons {S} = green
combined green with rectangle {M} = blue
fused blue with triangle {M} = yellow <-final result
Please note: the combined shapes are not on the scale! left out areas!
source to share