Take the 2-minute tour ×

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.

share|improve this question
+1 for a cool question! –  Warren P May 7 '12 at 12:41
add comment

2 Answers

up vote 14 down vote accepted

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.

share|improve this answer
+1: I strongly recommend the Clipper library. –  menjaraz May 7 '12 at 5:47
Sweet. I never heard of this and now I have just gotta try it! –  Warren P May 7 '12 at 12:41
add comment

The "classic" way to deal with this is a "transform matrix":

Since you appear to be using Delphi XE2, have you looked at Firemonkey? I believe that 2-D transforms are a standard part of the library:

share|improve this answer
That's nice to know, but a Delphi example would be better. There's also an issue that a TPoint is with Integers, no Decimals (meaning it's difficult to make calculations precise). Also, using Firemonkey means everything I do is Firemonkey, and that's not feasible in this case. –  Jerry Dodge May 7 '12 at 1:20
You mean a VCL example? (Firemonkey is still delphi!) –  Warren P May 7 '12 at 12:41
@WarrenP Yes, true, I didn't word that properly, actually this unit clipper.pas in the accepted answer doesn't rely on VCL, therefore can be used in FMX too :D –  Jerry Dodge May 7 '12 at 17:07
add comment

Your Answer


