-2

Trying to find a set of points that would allow a point to seemingly connect to a circle, like the image below however there is no overlap and it lines up with the edge of the circle. Apologies if this is hard to understand it is hard to explain.

image of a circle with line crossing over it with connecting to (0, r)

1 Answers1

1

If you want something like this:

enter image description here

then the python code below does this.

import numpy as np

# function that calcuates the points at which the lines are tangent to the circle
def tangent_points(Point, Circle):
    Rot_90 = np.array([[0, -1], 
                       [1, 0]]) 
    O = Circle[0]
    r = Circle[1]
    unit_OP = Point - O
    OP = np.sqrt( unit_OP.dot(unit_OP) )
    unit_OP = unit_OP / OP
    a = r**2 / OP
    unit_perp = Rot_90.dot(unit_OP)
    b = np.sqrt(r**2 - a**2)
    return O + a*unit_OP + b*unit_perp, O + a*unit_OP - b*unit_perp

# Test example 
O = np.array([0,0])
r = 2
P = np.array([7,5])   
Circ = (O, r)
  
T1, T2 = tangent_points(P, Circ)

# plotting preparations:

# prepare circle
s = np.linspace( 0 , 2 * np.pi , 150 )
xc = O[0] + r*np.cos( s )
yc = O[1] + r*np.sin( s )

# prepare tangents
s = np.linspace( 0, 1, 150)  
L1 = P[:, np.newaxis]*(1-s[np.newaxis, :]) + T1[:, np.newaxis]*s[np.newaxis, :]
L2 = P[:, np.newaxis]*(1-s[np.newaxis, :]) + T2[:, np.newaxis]*s[np.newaxis, :]

# actual plotting
# setup a figure environment
figure, axes = plt.subplots()
axes.set_aspect( 1 )
# plotting circle and center
axes.plot( xc, yc )
axes.plot(O[0], O[1], 'bo')
# plotting point ouside circle
axes.plot(P[0], P[1], 'bo')

# plotting tagnetn lines
axes.plot( L1[0], L1[1] )
axes.plot( L2[0], L2[1] )

# plotting tangent points
axes.plot(T1[0], T1[1], 'ro')
axes.plot(T2[0], T2[1], 'ro')

plt.show()   
Futurologist
  • 1,874
  • 2
  • 7
  • 9