7
$\begingroup$
$Version

"10.4.1 for Microsoft Windows (64-bit) (April 11, 2016)"

I want to match the based point of VoronoiMesh(pts in code) with its polygon(poly in code).This is my code

SeedRandom[2016526]
pts = RandomReal[{-1, 1}, {15, 2}];
mesh = VoronoiMesh[pts];
Show[%, Graphics[{Orange, Point[pts]}]]
poly = MeshPrimitives[mesh, 2];

enter image description here

When using the documentation of RelationGraph's first method:

RelationGraph[RegionMember[#2, #1] &, Join[pts, poly]]

We get a wrong result and a error information like

enter image description here

In this case,I can understand its error information but its wrong result.Then we try its second method in documentation.

RelationGraph[RegionMember[#2, #1] &, pts, poly]

We get some error information and the right result.Confuse me about it error informations like following

enter image description here

But I think I'm using this function in a right way.How to understand these phenomena?And when I use Echo to look this code's process

enter image description here

But as the documentation

enter image description here

I think shouldn't appear the elements of pts to be the parameter of RegionMember at the same time.This is a bug or I miss something?And how to adjust this code?

$\endgroup$
  • 1
    $\begingroup$ Have you seen this? $\endgroup$ – J. M. will be back soon May 26 '16 at 4:12
  • $\begingroup$ @J.M. Thanks for your link.But this post is that I suspect a bug in RelationGraph :) $\endgroup$ – yode May 26 '16 at 11:29
  • $\begingroup$ Yes, I only linked to it because there are easier ways to match points to their corresponding Voronoi cells. $\endgroup$ – J. M. will be back soon May 26 '16 at 11:33
3
$\begingroup$

Two argument form:

RelationGraph[f, {v1, v2, ...}] gives the graph with vertices vi and edges from vi to vj whenever f[vi, vj] is True.

What's not stated is that there is a check that f[v1, v1] returns explicitly True or False. You can use TrueQ to ensure this, so for example this gives the correct result:

RelationGraph[TrueQ @ RegionMember[#2, #1] &, Join[pts, poly]]

Of course there are still warnings when RegionMember[point, polygon] is called.

Three argument form:

RelationGraph[f, {v1, v2, ...}, {w1, w2, ...}] gives the graph with vertices vi, wj and edges from vi to wj whenever f[vi, wj] is True.

If you check the internal code (for example with GeneralUtilities`PrintDefinitions[RelationGraph]) it is clear that the criterion is tested in both directions, f[vi, wj] and f[wj, vi]. So again there are warnings when RegionMember[point, polygon] is called. It's not clear if this is a bug or incomplete documentation.

Workaround:

In either case you can get the correct result without warnings by using a function that only calls RegionMember if the arguments are the right way round, and returns False otherwise.

rm[q_List, p_Polygon] := RegionMember[p, q]
rm[__] = False;

RelationGraph[rm, pts, poly]

enter image description here

$\endgroup$
  • $\begingroup$ Do you agree this is a bug?If you think so,I will add a bug title for the question. $\endgroup$ – yode Apr 2 '17 at 11:41
  • $\begingroup$ @yode, I think it's more likely the intended behaviour, but not properly documented. $\endgroup$ – Simon Woods Apr 2 '17 at 11:44
  • $\begingroup$ But I think this sentence portray the behavior completely $\endgroup$ – yode Apr 2 '17 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.