Quantcast
Channel: Uncategorized - Matplotlib
Viewing all articles
Browse latest Browse all 56

inscribed circle

$
0
0

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Circle, Arc

Set radius r=2 for better visibility

r = 2.0
O = np.array([0.0, 0.0])
A = np.array([r, 0.0])
M = np.array([0.0, r/2])
C = np.array([0.0, r])

Vector from M to A

vec_MA = A - M

Rotate vec_MA by 60 degrees counterclockwise to get direction for MB

theta = np.deg2rad(60)
rot_matrix = np.array([[np.cos(theta), -np.sin(theta)],
[np.sin(theta), np.cos(theta)]])
vec_MB = rot_matrix @ vec_MA

Unit vector in MB direction

len_MA = np.linalg.norm(vec_MA)
unit_MB = vec_MB / len_MA

Find intersection B: solve quadratic for parameter s along unit_MB

u = unit_MB
a = 1.0
b = 2 * np.dot(M, u)
c = np.dot(M, M) - r2
disc = b
2 - 4ac
s1 = (-b + np.sqrt(disc)) / (2a)
s2 = (-b - np.sqrt(disc)) / (2
a)
s = max([s for s in [s1, s2] if s > 0]) # Positive s for the far intersection
B = M + s * u

Angle bisector: rotate vec_MA by 30 degrees

theta_bis = np.deg2rad(30)
rot_bis = np.array([[np.cos(theta_bis), -np.sin(theta_bis)],
[np.sin(theta_bis), np.cos(theta_bis)]])
vec_bis = rot_bis @ vec_MA
unit_bis = vec_bis / np.linalg.norm(vec_bis)

Find s for center I along bisector

u = unit_bis
m2 = np.dot(M, M)
mu = np.dot(M, u)
a = 3/4
b_coeff = 2mu + r # Note: this is for the quadratic (3/4)s^2 + (2 mu + r) s + (m2 - r^2) = 0
c = m2 - r2
disc = b_coeff
2 - 4
ac
s = (-b_coeff + np.sqrt(disc)) / (2
a) # Positive root
rho = s / 2 # Inradius
I = M + s * unit_bis

Plot

fig, ax = plt.subplots(figsize=(8, 8))
ax.set_aspect(‘equal’)
ax.set_xlim(-0.5, r + 0.5)
ax.set_ylim(-0.5, r + 0.5)
ax.grid(True, alpha=0.3)

Quarter circle arc AB (from A to B)

theta_A = np.deg2rad(0)
theta_B = np.arctan2(B[1], B[0])
quarter = Arc(O, 2r, 2r, theta1=np.rad2deg(theta_A), theta2=np.rad2deg(theta_B),
color=‘black’, linewidth=2)
ax.add_patch(quarter)

Full quarter for reference (dashed)

full_quarter = Arc(O, 2r, 2r, theta1=0, theta2=90, color=‘black’, linestyle=‘–’, alpha=0.5)
ax.add_patch(full_quarter)

Points

ax.plot(*O, ‘ko’, markersize=8, label=‘O (0,0)’)
ax.plot(*A, ‘ko’, markersize=8, label=‘A (r,0)’)
ax.plot(*M, ‘ko’, markersize=8, label=‘M (0, r/2)’)
ax.plot(*C, ‘ko’, markersize=8, label=‘C (0,r)’)
ax.plot(*B, ‘ko’, markersize=8, label=‘B’)
ax.plot(*I, ‘ro’, markersize=6, label=‘I (center)’)

Segments and lines

ax.plot([M[0], A[0]], [M[1], A[1]], ‘b-’, linewidth=2, label=‘MA’)
ax.plot([M[0], B[0]], [M[1], B[1]], ‘g-’, linewidth=2, label=‘MB’)
ax.plot([O[0], A[0]], [O[1], A[1]], ‘k–’, alpha=0.5) # x-axis
ax.plot([O[0], M[0]], [O[1], M[1]], ‘k–’, alpha=0.5) # y-axis to M

Inscribed circle

incircle = Circle(I, rho, fill=False, color=‘red’, linestyle=‘-’, linewidth=2)
ax.add_patch(incircle)

Angle bisector (dashed from M through I)

ax.plot([M[0], I[0] + (I[0] - M[0])], [M[1], I[1] + (I[1] - M[1])], ‘r–’, alpha=0.7, label=‘Bisector’)

ax.legend(loc=‘upper right’)
ax.set_title(‘Inscribed Circle in Segment MA, MB, and Arc AB\n(Quarter Circle with r=2)’)
plt.tight_layout()
plt.show()

Print coordinates for reference

print(f"Key Coordinates (r={r}):“)
print(f"O: {O}”)
print(f"A: {A}“)
print(f"M: {M}”)
print(f"C: {C}“)
print(f"B: {B}”)
print(f"I: {I}“)
print(f"Inradius ρ: {rho:.4f}”)

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 56

Trending Articles