[SciPy-User] Points with given distance to a polygon

eat e.antero.tammi@gmail....
Mon Jul 26 13:11:44 CDT 2010


Thøger Emil Juul Thorsen <thoeger <at> fys.ku.dk> writes:

> 
> I am working on a project where I am defining some regions of interest.
> I have a 2200x2200 px 2D Array in which my ROI is defined by a polygon.
> However, my data are smoothed by a gaussian kernel of width 300px, and I
> would like to draw some lines indicating this inner 150px distance to
> the borders of the ROI. I cannot come up with any way to do this, does
> anyone have an idea?
> 
> Best regards; 
> 
> Emil
> 
Hi,

Assuming you are looking for shrinking the polygon and your polygons
remains simple (nonselfintersecting) after shrinkage, I'll suggest
following rough procedure (in pseudo python).

def translate(segment, dist):
    normal= calculate inward normal of line segment
    normal= normal/ norm(normal)
    return segment+ dist* mormal

def shrink_polygon(polygon, dist):
    shrinked= translate(polygon(first segment), dist)
    for segment in second to last- 1 segment of polygon:
        x= intersect(shrinked, translate(segment, dist))
        shrinked[-1]= x
        shrinked.append(end point of segment)
    x= intersect(shrinked, translate(polygon(last segment), dist))
    shrinked[0]= x
    shrinked[-1]= x
    return shrinked

Does this fulfill your requirements? If so, I can work out more details if 
needed.


My 2 cents,
eat




More information about the SciPy-User mailing list