Skip to main content
Add some code
Source Link
Carl Woll
  • 132.7k
  • 6
  • 253
  • 366

I have a polygon given by

poly = Polygon[ {{2437.21, 166.705}, {2437.38,166.856}, {2440.37,163.438}, {2435.84,159.581}, {2442.18,152.113}, {2431.45,142.989}, {2420.63,153.885}, {2428.72,160.067}, {2418.95,168.237}, {2435.2,183.216}, {2446.11,174.504}, {2437.21,166.705}}] 

which visually looks good in the sense of shapewhen rendered:

enter image description here

Graphics[poly] 

enter image description here

However, this shape cannot be used for Region-related operations as it is "ill-defined" with an interior line:

enter image description here

Graphics[ { FaceForm[None], EdgeForm[Black], poly, Red, PointSize[Medium], Point@@poly }, Frame->True ] 

enter image description here

whose zoomed-in view is like this:

enter image description here

Graphics[ { FaceForm[None], EdgeForm[Black], poly, Red, PointSize[Medium], Point@@poly }, Frame->True, PlotRange->{{2437, 2438}, {166, 168}}, PlotRangeClipping->True ] 

enter image description here

My question is: How can I detect such "ill-defined" polygons and fix them?

Edit:

As more people are concerning about the definition of a valid polygon, I just cite that used by the python package shapely here:

Rings of a valid Polygon may not cross each other, but may touch at a single point only.

Also, I have very little expertise in computational geometry; my intention was to use Region-related functions (e.g., RegionMeasure) with these polygons, where I came across the kernel crash and then discovered such "ill-defined" polygons.

I have a polygon given by

Polygon[ {{2437.21, 166.705}, {2437.38,166.856}, {2440.37,163.438}, {2435.84,159.581}, {2442.18,152.113}, {2431.45,142.989}, {2420.63,153.885}, {2428.72,160.067}, {2418.95,168.237}, {2435.2,183.216}, {2446.11,174.504}, {2437.21,166.705}}] 

which visually looks good in the sense of shape:

enter image description here

However, this shape cannot be used for Region-related operations as it is "ill-defined" with an interior line:

enter image description here

whose zoomed-in view is like this:

enter image description here

My question is: How can I detect such "ill-defined" polygons and fix them?

Edit:

As more people are concerning about the definition of a valid polygon, I just cite that used by the python package shapely here:

Rings of a valid Polygon may not cross each other, but may touch at a single point only.

Also, I have very little expertise in computational geometry; my intention was to use Region-related functions (e.g., RegionMeasure) with these polygons, where I came across the kernel crash and then discovered such "ill-defined" polygons.

I have a polygon given by

poly = Polygon[ {{2437.21, 166.705}, {2437.38,166.856}, {2440.37,163.438}, {2435.84,159.581}, {2442.18,152.113}, {2431.45,142.989}, {2420.63,153.885}, {2428.72,160.067}, {2418.95,168.237}, {2435.2,183.216}, {2446.11,174.504}, {2437.21,166.705}}] 

which looks good when rendered:

Graphics[poly] 

enter image description here

However, this shape cannot be used for Region-related operations as it is "ill-defined" with an interior line:

Graphics[ { FaceForm[None], EdgeForm[Black], poly, Red, PointSize[Medium], Point@@poly }, Frame->True ] 

enter image description here

whose zoomed-in view is like this:

Graphics[ { FaceForm[None], EdgeForm[Black], poly, Red, PointSize[Medium], Point@@poly }, Frame->True, PlotRange->{{2437, 2438}, {166, 168}}, PlotRangeClipping->True ] 

enter image description here

My question is: How can I detect such "ill-defined" polygons and fix them?

Edit:

As more people are concerning about the definition of a valid polygon, I just cite that used by the python package shapely here:

Rings of a valid Polygon may not cross each other, but may touch at a single point only.

Also, I have very little expertise in computational geometry; my intention was to use Region-related functions (e.g., RegionMeasure) with these polygons, where I came across the kernel crash and then discovered such "ill-defined" polygons.

added definition of a valid polygon.
Source Link
sunt05
  • 4.5k
  • 24
  • 36

I have a polygon givegiven by

Polygon[ {{2437.21, 166.705}, {2437.38,166.856}, {2440.37,163.438}, {2435.84,159.581}, {2442.18,152.113}, {2431.45,142.989}, {2420.63,153.885}, {2428.72,160.067}, {2418.95,168.237}, {2435.2,183.216}, {2446.11,174.504}, {2437.21,166.705}}] 

which visually looks good in the sense of shape:

enter image description here

However, this shape cannot be used for Region-related operations as it is "ill-defined" with an interior line:

enter image description here

whose zoomed-in view is like this:

enter image description here

My question is: How can I detect such "ill-defined" polygons and fix them?

Edit:

As more people are concerning about the definition of a valid polygon, I just cite that used by the python package shapely here:

Rings of a valid Polygon may not cross each other, but may touch at a single point only.

Also, I have very little expertise in computational geometry; my intention was to use Region-related functions (e.g., RegionMeasure) with these polygons, where I came across the kernel crash and then discovered such "ill-defined" polygons.

I have a polygon give by

Polygon[ {{2437.21, 166.705}, {2437.38,166.856}, {2440.37,163.438}, {2435.84,159.581}, {2442.18,152.113}, {2431.45,142.989}, {2420.63,153.885}, {2428.72,160.067}, {2418.95,168.237}, {2435.2,183.216}, {2446.11,174.504}, {2437.21,166.705}}] 

which visually looks good in the sense of shape:

enter image description here

However, this shape cannot be used for Region-related operations as it is "ill-defined" with an interior line:

enter image description here

whose zoomed-in view is like this:

enter image description here

My question is: How can I detect such "ill-defined" polygons and fix them?

I have a polygon given by

Polygon[ {{2437.21, 166.705}, {2437.38,166.856}, {2440.37,163.438}, {2435.84,159.581}, {2442.18,152.113}, {2431.45,142.989}, {2420.63,153.885}, {2428.72,160.067}, {2418.95,168.237}, {2435.2,183.216}, {2446.11,174.504}, {2437.21,166.705}}] 

which visually looks good in the sense of shape:

enter image description here

However, this shape cannot be used for Region-related operations as it is "ill-defined" with an interior line:

enter image description here

whose zoomed-in view is like this:

enter image description here

My question is: How can I detect such "ill-defined" polygons and fix them?

Edit:

As more people are concerning about the definition of a valid polygon, I just cite that used by the python package shapely here:

Rings of a valid Polygon may not cross each other, but may touch at a single point only.

Also, I have very little expertise in computational geometry; my intention was to use Region-related functions (e.g., RegionMeasure) with these polygons, where I came across the kernel crash and then discovered such "ill-defined" polygons.

Routine clean-up
Source Link
m_goldberg
  • 108.6k
  • 16
  • 107
  • 263

detect Detect and fix invalid `Polygon`polygon

I have a Polygon belowpolygon give by

Polygon[ {{2437.21, 166.705}, {2437.38,166.856}, {2440.37,163.438}, {2435.84,159.581}, {2442.18,152.113}, {2431.45,142.989}, {2420.63,153.885}, {2428.72,160.067}, {2418.95,168.237}, {2435.2,183.216}, {2446.11,174.504}, {2437.21,166.705}}] 

which visually looks good in the sense of shape:

enter image description here

However, this shape cannot be used for Region-related operations as it is "ill-defined" with an interior line:

enter image description here

whose zoomzoomed-in view is like this:

enter image description here

My question is:

How can I detect such "ill-defined" polygons and fix them? How can I detect such "ill-defined" polygons and fix them?

detect and fix invalid `Polygon`

I have a Polygon below

Polygon[{{2437.21,166.705},{2437.38,166.856},{2440.37,163.438},{2435.84,159.581},{2442.18,152.113},{2431.45,142.989},{2420.63,153.885},{2428.72,160.067},{2418.95,168.237},{2435.2,183.216},{2446.11,174.504},{2437.21,166.705}}] 

which visually looks good in the sense of shape:

enter image description here

However, this shape cannot be used for Region-related operations as it is "ill-defined" with an interior line:

enter image description here

whose zoom-in view is like this:

enter image description here

My question is:

How can I detect such "ill-defined" polygons and fix them?

Detect and fix invalid polygon

I have a polygon give by

Polygon[ {{2437.21, 166.705}, {2437.38,166.856}, {2440.37,163.438}, {2435.84,159.581}, {2442.18,152.113}, {2431.45,142.989}, {2420.63,153.885}, {2428.72,160.067}, {2418.95,168.237}, {2435.2,183.216}, {2446.11,174.504}, {2437.21,166.705}}] 

which visually looks good in the sense of shape:

enter image description here

However, this shape cannot be used for Region-related operations as it is "ill-defined" with an interior line:

enter image description here

whose zoomed-in view is like this:

enter image description here

My question is: How can I detect such "ill-defined" polygons and fix them?

Tweeted twitter.com/StackMma/status/1037355117668904965
Source Link
sunt05
  • 4.5k
  • 24
  • 36
Loading