TEllipse DistancetoPrimitive()

Please provide a snippet that I can run in the root prompt that proves this DistancetoPrimitive(x,y) returns 0 when point (x,y) is inside of ellipse. I believe the below snippet should return 0, but segfaults instead.

TEllipse* el = new TEllipse(0,0,4,1,0,360,0)
el->DistancetoPrimitive(0,0)

Hi,

DistancetoPrimitive(x,y) only works when the ellipse has been drawn first:

root [0] TEllipse el(0.25,0.25,.1,.2); root [1] el.Draw(); Info in <TCanvas::MakeDefCanvas>: created default TCanvas with name c1 root [2] el.DistancetoPrimitive(0,0) (Int_t)9999
But then, DistancetoPrimitive returns 0 only when the given coordinates are on the line (and not inside the ellipse)

root [6] el1.DistancetoPrimitive(234,402)
(Int_t)0

So you will have to compute yourself if a given point is inside the ellipse…

Cheers, Bertrand.

Root provides a general tool to check if a point is inside a polygon or not:

TMath::IsInside(…)

I guess you need something like that for an ellipse. You can write a simple function doing it which we might include in the TEllipse class afterward.