Wow, thanks Michele!
Having two solutions will help me to understand sympy even better. I
really, really appreciate your replies and I'll be plugging in this code
interactively line-by-line along with the docs to see how every argument
and line contributes to the solution.
On Thursday, February 23, 2017 at 12:49:58 AM UTC-6, Michele Zaffalon wrote:
>
> Another quicker way is to impose that the circle slope is the same as the
> line.
> The first expression is the explicit equation for the top part of the
> circle. Then I impose that the slope is that of the line and I find the
> tangent `x` position.
>
> y = y0 + sqrt(r**2 - (x-d)**2)
> solve(diff(y,x) - m, x)
>
>
> On Thursday, February 23, 2017 at 7:40:17 AM UTC+1, Michele Zaffalon wrote:
>>
>> This is how I would do analytically: the equation for the circle is
>> (x-d)^2 + (y-y0)^2 = r^2, a circle of radius `r`, centered at `(d,y0)`. You
>> impose that `y` that belongs to the circle, belongs to the line as well. To
>> do this, you substitute the equation for the line in that for the circle
>> and you obtain `expr` below (y -> mx).
>> If you solve this second order equation, you find two solutions because
>> in general, the line crosses the circle in two points (or never). You want
>> these two points to be coincident because this is an alternative definition
>> of tangent and you solve for `y0`. There are again two solutions, one with
>> the circle to the right of the line, one to the left. You should pick the
>> correct one: on my computer, this is the second solution.
>> If you now substitute this into any of `sols`, you will find your tangent
>> `x` point.
>> Does this help?
>>
>> x, y, d, y0 = symbols("x, y, d, y0", real=True)
>> m, r = symbols("m, r", positive=True)
>> expr = (x+d)**2 + (m*x-y0)**2 - r**2
>> sols = solve(expr, x)
>> y0_sols = solve(sols[0] - sols[1], y0)
>> simplify(sols[1].subs(y0, y0_sol[1]))
>>
>>
>>
>> On Thursday, February 23, 2017 at 6:54:12 AM UTC+1, Kevin Pauba wrote:
>>>
>>> I'm trying to wrap my brain around sympy and am looking for a little
>>> help.
>>>
>>> Let's say I have a line 'y=m*x' (y-intercept is zero). Let's also say I
>>> have a circle of radius 'r' whose center is constrained to be along a
>>> horizontal line a specific distance 'd' below the x-axis.
>>> Given m, r and d, how might I code sympy to determine the circle's
>>> x-value where the given line is tangent to the circle (i'm only interested
>>> in the tangent on the left side of the circle). I also would like to
>>> determine the (x,y) of the tangent point.
>>>
>>> Feel free to nudge me in the right direction if you don't have the time
>>> to offer a more complete solution.
>>>
>>> For those interested, my interest is related to the design a cam profile
>>> that uses a roller-type follower.
>>>
>>
--
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 https://groups.google.com/group/sympy.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/24554465-9989-493c-b479-c665d55a015a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.