Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shrink a Polygon as an Array of TPoint?

I'm utilizing TCanvas.Polygon() and would like to know how I can go about shrinking the size of the polygon, either if there is already a function for this, or how to write one. I have a type declared TPoints: Array of TPoint; and using it when calling TCanvas.Polygon().

The trouble is, if I have to write this function, how does it recognize which direction each point needs to move (based on proportion to the rest of the polygon)?

For example, if I made an array of points (TPoints) to represent a 5 pointed star, and I needed to shrink it by 2 pixels, how would it know the direction to move the points?

The end intention is to implement a gradient for a polygon. There will be a loop to perform this, in which a) color is slightly adjusted, b) polygon points need to shrink by a few pixels, and c) polygon gets drawn (smaller than the previously drawn one); thus, creating a gradient.

like image 557
Jerry Dodge Avatar asked Dec 04 '22 16:12

Jerry Dodge


1 Answers

It seems to me you're looking for a way to do polygon offsetting - shrinking or expanding polygons by a specified number of units (pixels). My Clipper Library (written in Delphi, C++ and C#) does polygon offsetting. The 'direction the points move' (ie shrinking or expanding) will depend on the sign (positive vs negative) of the supplied 'delta' parameter to the OffsetPolygons function.

like image 67
Angus Johnson Avatar answered Dec 27 '22 06:12

Angus Johnson