pdf – how to find an equation of the common chord of two intersected circles.

import numpy as np
import matplotlib.pyplot as plt
import math

def get_intersections(x0, y0, r0, x1, y1, r1):
    # circle 1: (x0, y0), radius r0
    # circle 2: (x1, y1), radius r1
    d=math.sqrt((x1-x0)**2 + (y1-y0)**2)
    # non intersecting
    if d > r0 + r1 :
        return None
    # One circle within other
    if d < abs(r0-r1):
        return None
    # coincident circles
    if d == 0 and r0 == r1:
        return None
    else:
        a=(r0**2-r1**2+d**2)/(2*d)
        h=math.sqrt(r0**2-a**2)
        x2=x0+a*(x1-x0)/d   
        y2=y0+a*(y1-y0)/d   
        x3=x2+h*(y1-y0)/d     
        y3=y2-h*(x1-x0)/d 
        x4=x2-h*(y1-y0)/d
        y4=y2+h*(x1-x0)/d
        return (x3, y3, x4, y4)

x = np.linspace(-10.0, 8.0, 100)
y = np.linspace(-10.0, 8.0, 100)
X, Y = np.meshgrid(x,y)
x0 = 1
y0 = -2
r0 = math.sqrt(18.0)
F1 = (X-x0)**2 + (Y-y0)**2 - r0**2
x1 = -3
y1 = 1
r1 = math.sqrt(36.0)
F2 = (X-x1)**2 + (Y-y1)**2 - r1**2
F3 = 8*X - 6*Y - 13
x3, y3, x4, y4 = get_intersections(x0, y0, r0, x1, y1, r1)
fig, ax = plt.subplots(1)
ax.contour(X, Y, F1, [0])
ax.contour(X, Y, F2, [0])
ax.contour(X, Y, F3, [0])
plt.plot(x3, y3, marker="o", markersize=10, markeredgecolor="red", markerfacecolor="green")
plt.plot(x4, y4, marker="o", markersize=10, markeredgecolor="red", markerfacecolor="green")
plt.text(x3 + 0.5, y3 + 0.1, 'P')
plt.text(x4 + 0.0, y4 - 1.0, 'Q')
ax.set_aspect(1)
plt.savefig("ex398.png", dpi=100)
plt.show()

Discover more from Tips and Hints for Aerospace Engineers

Subscribe now to keep reading and get access to the full archive.

Continue reading