there's the rub Don: picking the "center" of a poly is key, else the
poly will translate, and not just shrink. The "centroid" (ie virtual
center of gravity) is no good for concave polys (like a banana)
because this point may lie outside the poly, so the poly will move.
I really don't know how to do this correctly. Seems so obvious!
P.
On 8/31/07, Don Jungk <rb at flippingdades dot com> wrote:
> On Friday 31 August 2007 6:17 pm, Peter K. Stys wrote:
> > Can anyone point me to an algorithm (with source preferably, C is
> > fine) that "insets" a polygon (defined by a set of vertices as x,y
> > coordinates). By inset I mean "shrink" towards its "center" (or
> > expand if the dx,dy params are negative).
>
> > Thanks,
> > Peter.
>
> Would something like this work?
> f is your scale factor
> Pick any new point, Px, Py
> new x1 = Px + (Px - x1)*f
> new y1 = Py + (Py - y1)*f
> etc.
>
> If you can define the "center" of your polygon and choose that point as your
> new point, the polygon should appear to shrink in on itself. If the point is
> somewhere else, the polygon will move, but shrink. I think the visual center
> will be a point half way between the points (smallest x value, smallest y
> value) and (largest x value, largest y value) from your list of vertices.
>
> This is off the top of my head and entirely untested.
>
> Don
> _______________________________________________
> Unsubscribe or switch delivery mode:
> <http://www.realsoftware.com/support/listmanager/>
>
> Search the archives:
> <http://support.realsoftware.com/listarchives/lists.html>
>
--
---------------------------------------------
Peter K. Stys, MD
Dept. of Clinical Neurosciences
Hotchkiss Brain Institute
University of Calgary
tel (403) 210-8646
---------------------------------------------
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>
|