• Polygon Offset

    From BTIS Jeff@21:1/5 to All on Sun Sep 4 14:50:07 2016
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Noskosteve@21:1/5 to All on Mon Sep 5 14:44:55 2016
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dr J R Stockton@21:1/5 to All on Mon Sep 5 20:02:59 2016
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From BTIS Jeff@21:1/5 to Noskosteve on Tue Sep 6 13:33:06 2016
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Nobody@21:1/5 to BTIS Jeff on Tue Sep 6 23:17:01 2016
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)