Hi Ondřej,

On Tue, Jul 2, 2013 at 1:30 AM, Ondřej Čertík <[email protected]> wrote:
> Hi Amit,
>
> On Sat, Jun 29, 2013 at 4:32 AM, Amit Saha <[email protected]> wrote:
>> Hello,
>>
>> Currently the is_perpendicular() method is defined, like so:
>>
>> a1, b1, c1 = l1.coefficients
>>                                                                 a2,
>> b2, c2 = l2.coefficients
>>                                                             return
>> bool(simplify(a1*a2 + b1*b2) == 0)
>>
>> Now it is possible (as I have just found) that the above sum may
>> equate to something tlike 1e-15, but not 0 (same with the product of
>> the slope coming to -0.9994).
>>
>> Does it make sense to have the provision for adding an epsilon value
>> such that anything below that is deemed to be 0?
>
> Can you post your code that gives 1e-15? The idea is that when only symbolic
> values are used (i.e. no floating point numbers), you can compare directly to 
> 0.

Okay, this is the code:

>>> from sympy import Circle, Point, Segment
>>> c = Point(0,0)
>>> r=1
>>> circle = Circle(c,r)
>>> tp = circle.random_point()
>>> tangent = circle.tangent_lines(tp)
>>> tangent = tangent[0]

>>> rad = Segment(circle.center, tp)

>>> (tangent.slope * rad.slope).evalf()
-1.00000000000000
>>> tangent.is_perpendicular(rad)
True

So, in this case as you can see, both "tests" tell me that they are
perpendicular, as they should be.

However, for another point (when I originally wrote my query), the
product  (tangent.slope * rad.slope).evalf() resulted
in -0.999999 (I am sorry what I meant by 1e-15 was a made up figure to
illustrate the infinitesimal difference between -1 and the product and
*not* the product).

Also, the is_perpendicular() method returned False (the value was
close to 0 but not quite).

>From what I gather from your answer, such cases as the just mentioned
is unavoidable when dealing directly with floats. Is the idea of using
epsilon explicitly a good way to work around such cases?

Thank you.
-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.


Reply via email to