@Dhara's answer needs to divide the angle by two as @Panos pointed out. Unfortunately, I couldn't post a comment due to my low reputation. Here is the code (also adapted to use matplotlib and numpy). There are two possible centers, the other one can be obtained by providing the negative value of the angle as an argument.
import matplotlib.pyplot as plt
import numpy as np
def find_center(p1, p2, angle):
angle = angle/2
# End points of the chord
x1, y1 = p1
x2, y2 = p2
# Slope of the line through the chord
slope = (y1-y2)/(x1-x2)
# Slope of a line perpendicular to the chord
new_slope = -1/slope
# Point on the line perpendicular to the chord
# Note that this line also passes through the center of the circle
xm, ym = (x1+x2)/2, (y1+y2)/2
# Distance between p1 and p2
d_chord = ((x1-x2)**2 + (y1-y2)**2)**0.5
# Distance between xm, ym and center of the circle (xc, yc)
d_perp = d_chord/(2*np.tan(angle))
# Equation of line perpendicular to the chord: y-ym = new_slope(x-xm)
# Distance between xm,ym and xc, yc: (yc-ym)^2 + (xc-xm)^2 = d_perp^2
# Substituting from 1st to 2nd equation for y,
# we get: (new_slope^2+1)(xc-xm)^2 = d^2
# Solve for xc:
xc = (d_perp)/(new_slope**2+1)**0.5 + xm
# Solve for yc:
yc = (new_slope)*(xc-xm) + ym
return xc, yc
def find_two_centers(p1, p2, angle):
return find_center(p1, p2, angle), find_center(p1, p2, -angle)
plt.figure()
p1 = [1., 2.]
p2 = [-3, 4.]
angle = np.pi/2
xc, yc = find_center(p1, p2, angle)
# Calculate the radius and draw a circle
r = ((xc-p1[0])**2 + (yc-p1[1])**2)**0.5
cir = plt.Circle((xc,yc), radius=r, fc='y')
plt.gca().add_patch(cir)
# mark p1 and p2 and the center of the circle
plt.plot(p1[0], p1[1], 'ro')
plt.plot(p2[0], p2[1], 'ro')
plt.plot(xc, yc, 'go')
plt.axis('equal')
xc, yc = find_center(p1, p2, -angle)
# Calculate the radius and draw a circle
r = ((xc-p1[0])**2 + (yc-p1[1])**2)**0.5
cir = plt.Circle((xc,yc), radius=r, fc='y')
plt.gca().add_patch(cir)
# mark p1 and p2 and the center of the circle
plt.plot(p1[0], p1[1], 'ro')
plt.plot(p2[0], p2[1], 'ro')
plt.plot(xc, yc, 'go')
plt.axis('equal')
plt.show()