Checking Point in Circle

Hi guys,

i have a small question. The cheapest way to check if a point is in the circle is checking the distance from its center to point but when i try to check this straightforward like:

if (cCenter.DistanceTo(pt) < radius)

I get unpredictable results so i assume i have to deal with some doc tolerance or sth? I’d like to maintain points which are on the edge.

@dale @RIL

@DavidRutten i see you’re around now would you mind give a tip on this?

Hi D-W,

Can you provide an example file and/or code so we can reproduce the unpredictable results.

-Willem

I thought it will be sth like radius - double.Epsilon but while inspecting list i found this what i thought will be Epsilon is ~0.0005

I don’t know from where this value comes in this case. Any ideas?

@Willem In example files you should get 6 true values - i get only one

cir_cont.gh (5.8 KB)
cir_cont.3dm (86.8 KB)

I do get 6 True values:
image

I have no clue why it would be different at your system

What version are you running?
I run: Rhino 6 SR3 2018-3-19 (Rhino 6, 6.3.18078.21401

@Willem thats interesting i found that out that in different file i get also 6 values… but one moment - take a look in the different file where i got few objects around. I’m running this on v5 sr14.

white line is constructed if point is not in circle and i had to do if (cCenter.DistanceTo(pt) < radius - 0.0005)

red circles are indicating the original case where if (cCenter.DistanceTo(pt) < radius) so as you see I’m missing quite a few circles here…

@Willem now for some reason (wtf???) i get only 5 true values on list

@Willem and to be clear v6 have the same issue here

@Willem also in v6 i have now only 5 bool values

@dale how on the earth if statement of this kind can be file dependant?

Here is example of contains method with high cost so the if looks like:
if ( circle.Contains(pt) == PointContainment.Inside)

Case when using cheap if looks like that:
if (cCenter.DistanceTo(pt) < radius)

wondering if it should not be a smaller or equal to radius? now you just have smaller

-Willem

@Willem

Less or equal should be if i would like to test if a point is in and on a circle i want only check if it is in.

I tried:

A.DistanceTo(B)
(B-A).Length
2D standard Euclidean distance

with

clean: radius or radius - double.Epsilon

All things are giving the same unpredictable result. @pascal @dale @DavidEranen

1 Like

Hi @D-W,

Can you provided source code, along with a model, that does not work correctly?

– Dale

@dale Check inbox :wink:

@dale solved my issue - as i thought i was missing tolerance value:

RhinoMath.ZeroTolerance

1 Like