f

#### Polygon Offset

```I'm looking for a way to get the coordinates of vertices of a polygon offse=
t x pixels within a known polygon.    This seems to be a non-trivial proble=
m, 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 de=
scribe a new polygon.   Does anyone know a way to get the coordinates of th=
e inside edges of this thickly drawn polygon.   I usually work in VB, VB.NE=
T, or C#, but solution in any language would be welcome.

- Jeff
```
 0
BTIS
9/4/2016 9:50:07 PM
comp.graphics.algorithms 6674 articles. 1 followers.

4 Replies
417 Views

Similar Articles

[PageSpeed] 26

```In comp.graphics.algorithms message <f5d7ded9-97d6-449c-8dc2-d52cf54722f
b@googlegroups.com>, Sun, 4 Sep 2016 14:50:07, BTIS Jeff
<btisjb@gmail.com> posted:

>
>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.

```
 0
Dr
9/5/2016 7:02:59 PM
```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

```
 0
Noskosteve
9/5/2016 9:44:55 PM
```On Sun, 04 Sep 2016 14:50:07 -0700, BTIS Jeff wrote:

> 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.

> 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.

```
 0
Nobody
9/6/2016 1:01:01 AM
```
On Monday, September 5, 2016 at 5:44:58 PM UTC-4, Noskosteve wrote:
> 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
```
 0
BTIS
9/6/2016 8:33:06 PM