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.
views:
169answers:
3As 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.
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:
- An algorithm for inflating/deflating (offsetting, buffering) polygons
- 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.