Message Boards Message Boards

0
|
6710 Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Difference in behavior between RegionNearest for a polygon's centroid in 2D

Posted 10 years ago

Difference in behavior between RegionNearest for a polygon's centroid in 2D vs 3D

Consider a simple 2-d polygon whose centroid is outside of the polygon:

Here is the polygon:

region = Polygon[{{0, 0}, {1, 1}, {2, 0}, {1, 3/4}}];
Graphics[region, Axes -> True]

giving

enter image description here

Now plot the centroid along with the point in the region closest to the centroid (yes there are technically two that are closest =because of teh symmetry, but RegionNearest chooses one--that's fine):

Graphics[{AbsolutePointSize[10], LightBlue, region, Red, 
  Point[RegionCentroid[region]], Darker@Green, 
  Point[RegionNearest[region, RegionCentroid[region]]]}, 
 ImageSize -> 400]

giving (red point for the centroid and green point for the nearest in the region):

enter image description here

Now let's do this in 3D:

region3d = Polygon[{{0, 0, 0}, {1, 1, 0}, {2, 0, 0}, {1, 3/4, 0}}];
Graphics3D[region3d, Axes -> True]

giving

enter image description here

and

Graphics3D[{AbsolutePointSize[10], LightBlue, region3d, Red, 
  Point[RegionCentroid[region3d]], Darker@Green, 
  Point[RegionNearest[region3d, RegionCentroid[region3d]]]}, 
 ImageSize -> 400]

giving

enter image description here

So the obvious question here is why the nearest point to the centroid is now at the centroid.

POSTED BY: David Reiss
4 Replies

For some (approximate) idea of what is going wrong in the 3D case, take a look at

 Map[DiscretizeGraphics, {region, region3d}]
POSTED BY: Ilian Gachevski

So would this be considered a bug primarily in DiscretizeGraphics? I assume that the RegionCentroid and the RegionNearest are being computed by making use of the triangulations shown in DiscretizeGraphics.

POSTED BY: David Reiss

Also , strangely, if I close the polygon explicitly as in this

Polygon[{{0, 0, 0}, {1, 1, 0}, {2, 0, 0}, {1, 3/4, 0}, {0, 0, 0}}] 

then

RegionCentroid[
 Polygon[{{0, 0, 0}, {1, 1, 0}, {2, 0, 0}, {1, 3/4, 0}, {0, 0, 0}}]] 

fails with the error message

RegionCentroid::nmet: Unable to compute the centroid of region Polygon[{{0,0,0},{1,1,0},{2,0,0},{1,3/4,0},{0,0,0}}]. >>

POSTED BY: David Reiss

So would this be considered a bug primarily in DiscretizeGraphics?

Not exactly, it was only an illustration. The problem happens in an internal polygon triangulation routine.

The polygon is already closed, so repeating the vertex will just introduce a degeneracy, which is not supported. The 2D case would also fail.

POSTED BY: Ilian Gachevski
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract