我有 100 个相似的形状(简单矢量图形)。如何找到所有 100 个实例的“平均/合并”形状?
谢谢
Compute the area of each shape {A}.
Find the shape {S} with most points {N} (you're going to end up with a N side polygon)
Merge {S} with another shape and create the first merged {M} shape. Then merge {M} with each other shape remaining. {M} will be dynamic/rewritten/will change every time it's merged with another shape.
Merge function: pseudocode
Call Merge({S}, {S2})
first, then call Merge({M}, {S2})
for the rest of the shapes.
Parameters:
{S1}=the shape with most points;
{S2}=shape 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 polygon {S}=green
merged green with rectangle {M}=blue
merged blue with triangle {M}=yellow <-final result
Notice: merged shapes not on scale! didn't account for areas!