On Sat, Jun 29, 2013 at 7:34 PM, Amit Saha <[email protected]> wrote:
> Hello,
>
> This is more of a note of my findings and also just implicitly
> verifying whether I am doing the right thing.
>
> Problem: I want to find whether a point lies on a circle.
>
> I was hoping that like Linear entity objects, the circle/ellipse would
> have a contains() method as well. But, contains() in the context of a
> circle or ellipse certainly means something else and I see that there
> is an encloses() method for that purpose.
>
> So, to do what I want to, this is my plan of action:
>
> - Find the equation of the circle
> - Substitute the point's co-ordinates in the above equation and see if
> it equates to 0
>
>>>> from sympy import Point, Circle
>>>> p = Point(0,0)
>>>> c = Circle(p,1)
>>>> c
> Circle(Point(0, 0), 1)
>
>>>> eq_c=c.equation()
>>>> eq_c.subs({x:0,y:1})
> x**2 + y**2 - 1
>
> That is not what I expect. Trying out a few other things (restarting
> the shell, etc), I finally hit the idea that may be the x and y in the
> equation are different objects from the ones I am specifying to
> subs(). So:
>
>>>> x=Symbol('x')
>>>> y=Symbol('y')
>>>> eq_c=c.equation(x=x,y=y)
>>>> eq_c.subs({x:0,y:1})
> 0
>
> And I have what I wanted to find
>
> (The same reasoning also applies if I want to use the solve() method
> and also to equations of other objects).
The issue is that the default symbols are set to be real, so if you
had used x = Symbol('x', real=True), it would have worked.
Really, the best way is to just pass in your own symbols, especially
if you plan to use those same symbols again for something.
>
> Query 1: Is there any reason why we don't have a method for finding
> whether a point lies on a circle/ellipse?
Use "in":
In [32]: c = Circle(Point(0, 0), 1)
In [30]: Point(0, 1) in c
Out[30]: True
In [31]: Point(0, 1.1) in c
Out[31]: False
Be aware the "in" relies on the ability to simplify things to zero, so
if you have a lot of symbolic parameters, it's possible to get a wrong
answer, simply because it couldn't actually determine if it is there
(normally SymPy would try to return None in this case, but Python does
not allow to return anything other than True and False from "in").
But of course, if everything is numeric, it should always be right.
Aaron Meurer
>
>
> Thanks for reading.
>
> Best,
> Amit.
> --
> http://echorand.me
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sympy.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
For more options, visit https://groups.google.com/groups/opt_out.