Hello, On Mon, Jul 11, 2011 at 12:56 PM, Chris Smith <[email protected]> wrote: > > > On Mon, Jul 11, 2011 at 9:40 AM, cathal coffey <[email protected]> > wrote: >> >> Hi guys, >> I want to test if a Segment contains a Point. I need to take into account >> round off error so i'm looking for something like the below where 1 means 1 >> meter. >> segment.contains(point, 1) > > It's not clear what you mean by the 1 meter. Is that the error? It would be > more helpful if you define segment and point. How are they being defined? Do > they involve floating point numbers? The general answer to your question is > that sympy can test whether a point is in a segment, but because of floating > point issues it likely won't be able to do so reliably with floating point > numbers. > >>> Segment((0,0), (2,2)) > Segment(Point(0, 0), Point(2, 2)) > >>> s=_; Point(1,1) in s > True
Taking into account roundoff problems, you can do something like this instead: >>> s = Segment((0,0), (2,2)) >>> tolerance = 1e-6 >>> s.distance(Point(1,1)) < tolerance True The tolerance, of course, depends on the magnitude of the errors from input (it should be exact if you use only integers, for instance). Renato -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
