3

我有 100 个相似的形状(简单矢量图形)。如何找到所有 100 个实例的“平均/合并”形状?

谢谢

4

1 回答 1

2

Algorithm Proposal

  1. Compute the area of each shape {A}.

  2. Find the shape {S} with most points {N} (you're going to end up with a N side polygon)

  3. 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
3shapes

merged green with rectangle {M}=blue
merge1

merged blue with triangle {M}=yellow <-final result final

Notice: merged shapes not on scale! didn't account for areas!

于 2013-02-06T18:08:48.603 回答