6

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 *)
J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
BoLe
  • 5,819
  • 15
  • 33

4 Answers4

7

This (or an appropriately written variant) works:

myRegionMember[a_, b_] := With[{threshold = 10^-6},
  If[
   RegionDistance[a, b] < threshold,
   True,
   False
   ]
  ]
gpap
  • 9,707
  • 3
  • 24
  • 66
4

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} *)
Michael E2
  • 235,386
  • 17
  • 334
  • 747
3
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 *)
kglr
  • 394,356
  • 18
  • 477
  • 896
1

Following gpap's answer:

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} *)
BoLe
  • 5,819
  • 15
  • 33