Discussion:
Polygon Offset
(too old to reply)
BTIS Jeff
2016-09-04 21:50:07 UTC
Permalink
I'm looking for a way to get the coordinates of vertices of a polygon offset x pixels within a known polygon. This seems to be a non-trivial problem, but I thought of a trick - What if I have the original polygon drawn by Windows with a thick line, the inside edges of that thick line will then describe a new polygon. Does anyone know a way to get the coordinates of the inside edges of this thickly drawn polygon. I usually work in VB, VB.NET, or C#, but solution in any language would be welcome.

- Jeff
Noskosteve
2016-09-05 21:44:55 UTC
Permalink
You say offset, but from your proposal appear to mean scaled smaller.
Depending on the type of polygon, can you define a center of 'mass' from the verticies,then simply scale it to a smaller size?
--
Cheers, Steve
BTIS Jeff
2016-09-06 20:33:06 UTC
Permalink
Post by Noskosteve
You say offset, but from your proposal appear to mean scaled smaller.
Depending on the type of polygon, can you define a center of 'mass' from the verticies,then simply scale it to a smaller size?
--
Cheers, Steve
Not really scaled smaller - if there are concave sections of the polygon, then some of the lines of the internally offset polygon will in fact be longer than the original polygon.

Here is a sample drawing showing inner and outer polygons

+---------------+
| |
| +--------+ |
| | | |
| | | |
| | | |
| +----+ | |
| | | |
+---+ | | |
| | | |
| | | |
+---+ | | |
| | | |
| +----+ | |
| | | |
| | | |
| +--------+ |
| |
+---------------+

You can see the desired inner polygon is not just a reduced scale of the outer original polygon.

- Jeff
Dr J R Stockton
2016-09-05 19:02:59 UTC
Permalink
In comp.graphics.algorithms message <f5d7ded9-97d6-449c-8dc2-d52cf54722f
Post by BTIS Jeff
I'm looking for a way to get the coordinates of vertices of a polygon
offset x pixels within a known polygon. This seems to be a non-
trivial problem, but I thought of a trick - What if I have the original
polygon drawn by Windows with a thick line, the inside edges of that
thick line will then describe a new polygon. Does anyone know a way
to get the coordinates of the inside edges of this thickly drawn
polygon. I usually work in VB, VB.NET, or C#, but solution in any
language would be welcome.
Firstly, you need to think what "x pixels from a line" means if the line
is not parallel to an axis.

Secondly, there are at least four types of polygon :
self-crossing,
concave in places,
ordinary,
nearly round.

I guess that yours will not be the first case, probably not the second,
and that the third and fourth are not significantly different.

I assume, them, that you have an ordered set of coordinates for the
original vertices, and an offset in the same units.

I would, for each original side, find its middle, find a parallel line
at distance x inside, and calculate the intersections of each adjacent
pair of inner lines. QED.

If any corner has an internal angle very near 180 degrees, the solution
will be ill-conditioned.

For a sanity check, verify that the distances between each pair of inner
and outer vertices are near enough as expected.
--
(c) John Stockton, Surrey, UK. ¬@merlyn.demon.co.uk Turnpike v6.05 MIME.
Merlyn Web Site < > - FAQish topics, acronyms, & links.
Nobody
2016-09-06 22:17:01 UTC
Permalink
Post by BTIS Jeff
I'm looking for a way to get the coordinates of vertices of a polygon
offset x pixels within a known polygon. This seems to be a non-trivial
problem,
It's not that hard, provided that the insetting doesn't cause
self-intersection.

For each vertex, offset the lines corresponding to the adjacent edges by
the desired amount then find their intersection.
Post by BTIS Jeff
but I thought of a trick - What if I have the original polygon
drawn by Windows with a thick line, the inside edges of that thick line
will then describe a new polygon. Does anyone know a way to get the
coordinates of the inside edges of this thickly drawn polygon. I usually
work in VB, VB.NET, or C#, but solution in any language would be welcome.
Rasterising the polygon and then tracing it? This isn't what I'd consider
a credible solution, given how much more inefficient and error-prone it is
than the geometry approach.

Loading...