Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

unexpected/wrong output of Polygon::offsetInward function #514

Open
@Arjan-TNO

Description

When using the Polygon::offsetInward function I get an unexpected result for the following input:

Polygon polygon(
	{Position(0.0, 0.0),
	Position(1.0, 1.0),
	Position(2.0, 1.0),
	Position(3.0, 0.0),
	Position(3.0, 1.0),
	Position(3.0, 2.0),
	Position(2.0, 3.0),
	Position(1.0, 3.0),
	Position(0.0, 2.0),
	Position(0.0, 1.0)});
polygon.offsetInward(0.1);

The problem here is two-fold, the function does not seem to work well :

  1. for non-convex polygons (see sequence of points: 0, 1, 2, 3 in picture below),
  2. with points in the polygon that are positioned exactly (on a straight line) between their neighbors (see points 4 & 9, in picture below).

I have noticed the statement on non-convex polygons here, but that same statement is in a TODO, so this might be the moment to address convex part of the TODO... :-)

A picture of the result is below (red dashed line is output of the offsetInward function):

Image

A small analysis (in Matlab which for me is a tool I'm most familiar with) shows some intermediate steps in the process:

Image

Here, the purple and green vectors at each point, are oriented towards their respective previous and next neighbor. Theses correspond with the v1 (purple) and the v2 (green) vectors of the function.
The black vectors is the summation of the green and purple vectors and is the direction over which the offset is applied.

Especially for the case of the 2nd problem I mention (points 4 & 9) it is obvious: the summation of these (v1+v2) equals zero, and therefore any offset value will be placed exactly on the point itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /