tags:

views:

169

answers:

3

I have a polygon which can be regular as well as irregular one. I have to do offsetting/buffering of polygon. I need to stretch the polygon by some amount of offset. The shape should be maintained.

A: 
ralu
This will only scale the polygon. It works for a regular polygon (box, pentagon, hexagon etc) with the origin in the center.
Peter Olsson
A: 

As I dust off my geometry brain cells, I remember that you need a line for perpendicular and that two points determine a line. In your question and title line, you mention only one point.

However, you should look up Linear Algebra, especially matrices. By using matrices, you can easily scale (multiply) points in a polygon.

For example, find the center of the polygon.

for each vertex:
  determine the line equation for the vertex to the center of the polygon.
  calculate a new point on the line that is a scaled distance from the center.
  store the point in a new container of vertices.
end-for
redraw polygon using new container of vertices.

All comments gladly accepted as the dust was a bit thick on those Geometry brain cells.

Thomas Matthews
It will not work for irregular polygons. The center may not even be inside the polygon and the new vertex may have to move in any angle. You need to offset each edge and find the intersection between them to calculate the new vertex.
Peter Olsson
A: 

The problem has several different solutions depending on your requirements.

A good place to start is to read the related section in the right column of this page.
Two good ones are:

  1. An algorithm for inflating/deflating (offsetting, buffering) polygons
  2. How do you find a point a given perpendicular distance from a line?

Will these two questions (with good answers) help you?
If not, please edit your question with more information about your specific problem.

Peter Olsson