Skip to content

Instantly share code, notes, and snippets.

@tobin
Created September 22, 2023 18:56
Show Gist options
  • Save tobin/156074fa0669197d70f9e9566112034d to your computer and use it in GitHub Desktop.
Save tobin/156074fa0669197d70f9e9566112034d to your computer and use it in GitHub Desktop.
Find radius of circle inscribed between y axis, unit circle, and y=sqrt(x).
# Solution to https://twitter.com/iwontoffendyou/status/1704935240907518367
# Tobin Fricke 2023-09-22
import numpy as np
import scipy.optimize
def dist_from_circle_center_to_curve(R):
# Center of circle of radius R that is tangent to the y axis and the unit circle.
x0 = R
# The point of tangency of the small circle with the big unit circle is found by drawing
# a line through their centers. From this we see that the center of the small circle is
# a distance (1-R) from the center of the unit circle. We can now draw a right triangle
# and use Pythagoras to get the y-coordinate of the origin of the small circle:
y0 = (1 - 2*R)**0.5
# What is the shortest distance from the point (x0, y0) to the curve y = sqrt(x)?
def dist_from_circle_center_to_curve(x):
# The curve y = sqrt(x)
y = x**0.5
# Distance from the circle center to the curve.
return ((x0 - x)**2 + (y0 - y)**2)**0.5
# Find the point on the curve closest to the origin of the circle.
_, fopt, _, _, _ = scipy.optimize.fmin(func=dist_from_circle_center_to_curve,
x0=0.5, full_output=True, disp=False)
return fopt
scipy.optimize.fixed_point(dist_from_circle_center_to_curve, x0=0.25)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment