Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

algorithm - Trace a shape into a polygon of max n sides

I'm looking for an algorithm that will find an irregular shape, maybe not too irregular, like a squashed circle, on a surface, and trace a polygon of a maximum of n sides around the shape. The 'n' maximimum might be based on the area of the shape.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I would do it like this:

  1. compute tangent angles ang and its change dang for all curve segments

    you can use atanxy or atan2 for that

    ang[i] = atanxy(x[i]-x[i-1],y[i]-y[i-1]);
    dang[i] = ang[i]-ang[i-1];
    
  2. find inflex points (Black)

    at these points the sign of dang is changing so

    dang[i-1]*dang[i+1]<0.0
    

    but you need to handle the dang=0.0 elements properly (need to scan before and after them). These points will be the fundamental skeleton for your output polygon

  3. add the bumps max points (green)

    at these points the tangent angle is between nearest inflex points so to find max point between two inflex points i0 and i1 find the closest angle to

    angavg=0.5*(ang[i0]+ang[i1])
    

    do not forget that

    |ang[i]-angavg|<=PI
    

    so +/- 2.0*PI if this is not true

  4. now you should have all significant points of your closed polycurve ...

    it should look like this:

    img

    CW/CCW or Red/Blue just represents the sign of dang[i] ...

[Notes]

The output point type should be preserved (inflex/maxpoint) because it can be later used for comparison and detection of shapes ...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...