1

I am trying to plot the endpoints of the line segment which is a tangent to a circle in Python. I know the circle has center of (A, B), and a radius of r. The point at which I want to find the tangent at is (a, b). I want the tangent to be a segment of length c. How do I write a code which allows me to restrict the length of the line?

I have the equation of the tangent to be y = (-(B - b)/(A - a))(x - a) + b. So I know how to plot the two endpoints if the length of the segment did not matter. But how would I determine the x-coordinates of the point? Is there some sort of command which allows me to limit the length of a line?

Thank you!!!

Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52
Kerushi
  • 11
  • 2

1 Answers1

0

I don't know thonny, and it sounds like your implementation will depend a bit on the context of this computation.

That said, it sounds like what you're looking for is the two points of intersection of your tangent line and a (new, conceptual) cicle with a given radius centered on (a,b). You should be able to put together the algebraic expression for those points, and simplify it into something tidy. Watch out for special cases though, where the slope of the tangent is undefined (or where it's zero).

ShapeOfMatter
  • 991
  • 6
  • 25
  • https://www.thonny.org is a beginner's IDE for Python, so I think this is more of a beginner's question than actually related to thonny. – icedwater Mar 16 '20 at 09:28