# RegionMember with some tolerance?

Can I specify some tolerance for the new geometric-computation function?

RegionMember[Line[{{0, 0}, {1, 0}}], {.5, 0}]
(* True *)


While:

RegionMember[Line[{{0, 0}, {1, 10^-100}}], {.5, 0}]
(* False *)

RegionMember[Line[{{0, 0}, {1, 10.^-100}}], {.5, 0}]
(* True *)

RegionMember[Line[{{0, 0}, {1, 10.^-7}}], {.5, 0}]
(* False *)


There's Internal$EqualTolerance. See How to make the computer consider two numbers equal up to a certain precision and its reference. Block[{Internal$EqualTolerance = 9.},
RegionMember[Line[{{0, 0}, {1, 10.^-7}}], {.5, 0}]
]
(* True *)


It's a relative tolerance, whereas gpap's & kguler's answers give absolute ones. The setting above, which is roughly equivalent to Internal$EqualTolerance =$MachinePrecision - 7, says approximate numbers that agree to seven digits (or differ in at most the last nine) are to be considered equal.

Block[{Internal$EqualTolerance =$MachinePrecision - 7},
{1. + 1.0000001*^-7 == 1, 1. + 1*^-7 == 1}
]
(* {False, True} *)

• Yes, this, temporarily overriding the equality criteria, if I understand it correctly. – BoLe Oct 17 '14 at 11:18
• Upvote for trick.. – yode Apr 5 '17 at 10:33

This (or an appropriately written variant) works:

myRegionMember[a_, b_] := With[{threshold = 10^-6},
If[
RegionDistance[a, b] < threshold,
True,
False
]
]

f1 = RegionDistance[#, #2] < #3]&

f1[Line[{{0, 0}, {1, 10.^-7}}], {.5, 0}, 10^-6]
(* True *)

f2 = Chop[RegionDistance[#, #2] ,#3] == 0&

f2[Line[{{0, 0}, {1, 10.^-7}}], {.5, 0}, 10^-6]
(* True *)


Options[regionMember] = {Tolerance -> 0};

regionMember[reg_Line, p : {_?NumberQ, _?NumberQ},
OptionsPattern[]] :=
With[{e = OptionValue[Tolerance]},
If[e == 0, RegionMember[reg, p], RegionDistance[reg, p] < e]]

line = Line[{{0, 0}, {1, 0}}];
ps = {.5, #} & /@ {0, 10^-100, 10.^-16, 10.^-5};

regionMember[line, #] & /@ ps
(* {True, False, False, False} *)

regionMember[line, #, Tolerance -> 10.^-6] & /@ ps
(* {True, True, True, False} *)