On May 28, 7:13 pm, Matteo Boscolo <[email protected]>
wrote:
> Hi all,
>
> I'm New using in sympy I would like to use sympy.geometry for my
> pythoncad Application.
>
> There are any way to find a tangent line of a circle or ellipse given
> as constraint an external point  ?.. somthing like
> Line=TangentLine(Circle,Point) where point is an external entity of
> the circle ?
>
> I  found the Circle.tangent_line(Point) .. but this means that i have
> to know the tangent point ..
>
> There are simple way to do such a operation ?
>

How about the following?

Let's imagine a line through a point (a,b) that has a slope m. For
concreteness we will assume that (a,b) = (7,11).

>>> a,b=7,11; var('m')
m
>>> l=Line(Point(a,b),Point(a+1,b+m))

(Maybe there is a way to define a line with point and slope, but no
hints pop up for me when I type Line so I'm not sure.)

OK, now imagine a circle of radius 2 centered at (2,3):

>>> c=Circle(Point(2,3),2)

There are two places that l will intersect with c:

>>> c.intersection(l)
[Point((2 - 8*m - I*(60 - 80*m + 21*m**2)**(1/2) + 7*m**2)/(1 + m**2),
(11 - 5*m - I*m*(60 - 80*m + 21*m**2)**(1/2) + 3*m**2)/(1 + m**2)),
Point((2 - 8*m + I*(60 - 80*m + 21*m**2)**(1/2) + 7*m**2)/(1 + m**2),
(11 - 5*m + I*m*(60 - 80*m + 21*m**2)**(1/2) + 3*m**2)/(1 + m**2))]

We capture and call those two intersection points i1 and i2:

>>> i1, i2 = _

Now if we just pick the right slope of the line, m, those two
intersection points will be identical so let's find the slope that
makes it so:

>>> solve(i1[0]-i2[0], m)
[40/21 - 2*85**(1/2)/21, -I, 40/21 + 2*85**(1/2)/21, I]

Numerically those are:

>>> [N(w) for w in _]
[1.02671005168639, -1.0*I, 2.78281375783742, I]

Only the two real ones make sense so we capture those as m1 and m2.
{I'm not sure right now how (from the 4) you will recognize the two
that you don't want.}

>>> m1,j,m2,j=_

And now we substitute those into i1 to see where the points of
intersection are. Since Point doesn't have the .subs method we have to
do the substitution to the arguments of the Point by hand:

>>> i1[0].subs(m,m1),i1[1].subs(m,m1)
(0.567272906554088, 4.39545443340370)
>>> i1[0].subs(m,m2),i1[1].subs(m,m2)
(3.88216529569310, 2.32364669019181)

Using turtle graphics to reconstruct this configuration indicates that
these are right on! Note that substituting m1 and m2 into i2 will give
the same values, so it was actually not necessary to keep both i1 and
i2.

Note: since we can check to see if a point is on a circle so we should
be able to make c.tangent_line return 0, 1 or 2 points depending on
whether a point is in, on or outside the circle.

>>> from sympy import *
>>> c=Circle(Point(2,3),2)

Check to see if (2,1) is validated as being on the circle:

>>> c.intersection(Point(2,1))
[Point(2, 1)]

And see that a point inside is not:

>>> c.intersection(Point(2,2))
[]

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

Reply via email to