{"id":1984,"date":"2023-12-26T01:03:07","date_gmt":"2023-12-26T09:03:07","guid":{"rendered":"https:\/\/gantovnik.com\/bio-tips\/?p=1984"},"modified":"2024-01-13T16:25:31","modified_gmt":"2024-01-14T00:25:31","slug":"398-find-points-of-intersection-of-two-circles","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2023\/12\/398-find-points-of-intersection-of-two-circles\/","title":{"rendered":"#398 Find points of intersection of two circles"},"content":{"rendered":"<p><a href=\"https:\/\/gantovnik.com\/bio-tips\/2023\/12\/398-find-points-of-intersection-of-two-circles\/ex398\/\" rel=\"attachment wp-att-1985\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/12\/ex398.png?resize=640%2C480&#038;ssl=1\" alt=\"\" width=\"640\" height=\"480\" class=\"alignnone size-full wp-image-1985\" srcset=\"https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/12\/ex398.png 640w, https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/12\/ex398-480x360.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 640px, 100vw\" \/><\/a><\/p>\n<a href='https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/12\/ex398.pdf' class='big-button bigblue'>pdf<\/a> &#8211; how to find an equation of the common chord of two intersected circles.<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport numpy as np\r\nimport matplotlib.pyplot as plt\r\nimport math\r\n\r\ndef get_intersections(x0, y0, r0, x1, y1, r1):\r\n    # circle 1: (x0, y0), radius r0\r\n    # circle 2: (x1, y1), radius r1\r\n    d=math.sqrt((x1-x0)**2 + (y1-y0)**2)\r\n    # non intersecting\r\n    if d &gt; r0 + r1 :\r\n        return None\r\n    # One circle within other\r\n    if d &lt; abs(r0-r1):\r\n        return None\r\n    # coincident circles\r\n    if d == 0 and r0 == r1:\r\n        return None\r\n    else:\r\n        a=(r0**2-r1**2+d**2)\/(2*d)\r\n        h=math.sqrt(r0**2-a**2)\r\n        x2=x0+a*(x1-x0)\/d   \r\n        y2=y0+a*(y1-y0)\/d   \r\n        x3=x2+h*(y1-y0)\/d     \r\n        y3=y2-h*(x1-x0)\/d \r\n        x4=x2-h*(y1-y0)\/d\r\n        y4=y2+h*(x1-x0)\/d\r\n        return (x3, y3, x4, y4)\r\n\r\nx = np.linspace(-10.0, 8.0, 100)\r\ny = np.linspace(-10.0, 8.0, 100)\r\nX, Y = np.meshgrid(x,y)\r\nx0 = 1\r\ny0 = -2\r\nr0 = math.sqrt(18.0)\r\nF1 = (X-x0)**2 + (Y-y0)**2 - r0**2\r\nx1 = -3\r\ny1 = 1\r\nr1 = math.sqrt(36.0)\r\nF2 = (X-x1)**2 + (Y-y1)**2 - r1**2\r\nF3 = 8*X - 6*Y - 13\r\nx3, y3, x4, y4 = get_intersections(x0, y0, r0, x1, y1, r1)\r\nfig, ax = plt.subplots(1)\r\nax.contour(X, Y, F1, &#x5B;0])\r\nax.contour(X, Y, F2, &#x5B;0])\r\nax.contour(X, Y, F3, &#x5B;0])\r\nplt.plot(x3, y3, marker=&quot;o&quot;, markersize=10, markeredgecolor=&quot;red&quot;, markerfacecolor=&quot;green&quot;)\r\nplt.plot(x4, y4, marker=&quot;o&quot;, markersize=10, markeredgecolor=&quot;red&quot;, markerfacecolor=&quot;green&quot;)\r\nplt.text(x3 + 0.5, y3 + 0.1, 'P')\r\nplt.text(x4 + 0.0, y4 - 1.0, 'Q')\r\nax.set_aspect(1)\r\nplt.savefig(&quot;ex398.png&quot;, dpi=100)\r\nplt.show()\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&#8211; 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 &gt; r0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1985,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","_lmt_disableupdate":"yes","_lmt_disable":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[69,2],"tags":[],"class_list":["post-1984","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-matplotlib","category-python"],"modified_by":"gantovnik","jetpack_featured_media_url":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/12\/ex398.png?fit=640%2C480&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8bH0k-w0","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":1746,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/01\/204-mandelbrot-fractal-using-python-2-2-2-2-2-2-2-2-2-2\/","url_meta":{"origin":1984,"position":0},"title":"#331 Interpolation with Newton&#8217;s polynomial using python","author":"gantovnik","date":"2023-01-04","format":false,"excerpt":"interpolation.py [code language=\"python\"] def interpolation(c,x,x0): # Evaluate Newton's polynomial at x0. # Degree of polynomial n = len(x) - 1 y0 = c[n] for k in range(1,n+1): y0 = c[n-k] + (x0 - x[n-k]) * y0 return y0 def coef(x,y): # Computes the coefficients of Newton's polynomial. # Number of\u2026","rel":"","context":"In &quot;interpolation&quot;","block_context":{"text":"interpolation","link":"https:\/\/gantovnik.com\/bio-tips\/category\/interpolation\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/01\/ex331.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1494,"url":"https:\/\/gantovnik.com\/bio-tips\/2022\/06\/210-parametric-curve-in-3d-2-2-2-2-2-2-2-2-2-2-2-2-2-3-2-2-2-2-2-2-2-2-2-3-2-2-2-2-2-2-2-2-2\/","url_meta":{"origin":1984,"position":1},"title":"#285 Find min and max lengths of lines in HyperMesh database","author":"gantovnik","date":"2022-06-15","format":false,"excerpt":"#285 Find min and max lengths of lines in HyperMesh database [code language=\"python\"] proc myRand {min max} { set range [expr {$max - $min}] return [expr {$min + rand() * $range}] } proc create_random_lines {} { set n 30 for {set i 0} {$i < $n} {incr i} { set\u2026","rel":"","context":"In &quot;HyperMesh&quot;","block_context":{"text":"HyperMesh","link":"https:\/\/gantovnik.com\/bio-tips\/category\/hypermesh\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/06\/2022-06-15_143821.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/06\/2022-06-15_143821.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/06\/2022-06-15_143821.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/06\/2022-06-15_143821.jpg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/06\/2022-06-15_143821.jpg?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":2175,"url":"https:\/\/gantovnik.com\/bio-tips\/2024\/05\/425-an-animation-of-a-bouncing-ball-using-python\/","url_meta":{"origin":1984,"position":2},"title":"#425 An animation of a bouncing ball using python","author":"gantovnik","date":"2024-05-05","format":false,"excerpt":"[code language=\"python\"] import numpy as np import matplotlib.pyplot as plt import matplotlib. Animation as animation # Acceleration due to gravity, m.s-2. g = 9.81 # The maximum x-range of ball's trajectory to plot. XMAX = 5 # The coefficient of restitution for bounces (-v_up\/v_down). cor = 0.65 # The time\u2026","rel":"","context":"In &quot;animation&quot;","block_context":{"text":"animation","link":"https:\/\/gantovnik.com\/bio-tips\/category\/animation\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/05\/ex425-1.gif?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/05\/ex425-1.gif?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/05\/ex425-1.gif?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1758,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/01\/335-solution-of-nonlinear-equation-using-brent-method-in-python\/","url_meta":{"origin":1984,"position":3},"title":"#335 Solution of nonlinear equation by Brent&#8217;s method in python","author":"gantovnik","date":"2023-01-06","format":false,"excerpt":"Brent's method is a hybrid root-finding algorithm combining the bisection method, the secant method, and inverse quadratic interpolation. ex335.py [code language=\"python\"] import numpy as np import matplotlib.pyplot as plt import scipy.optimize as optimize def f(x): return 2*x - 1 + 2*np.cos(np.pi*x) x = np.linspace(0.0,2.0,201) y=f(x) plt.plot(x,y,label='$2x - 1 + 2\\\\cos(\\\\pi\u2026","rel":"","context":"In &quot;optimization&quot;","block_context":{"text":"optimization","link":"https:\/\/gantovnik.com\/bio-tips\/category\/optimization\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/01\/ex335.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1109,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/11\/193-animation-using-python\/","url_meta":{"origin":1984,"position":4},"title":"#193 Animation using python","author":"gantovnik","date":"2021-11-19","format":false,"excerpt":"[code language=\"python\"] # create an animation import numpy as np import matplotlib.pyplot as plt import matplotlib. Animation as manimation n = 1000 x = np.linspace(0, 6*np.pi, n) y = np.sin(x) # Define the meta data for the movie FFMpegWriter = manimation.writers[\"ffmpeg\"] metadata = dict(title=\"Movie Test\", artist=\"Matplotlib\", comment=\"a red circle following\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex193.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex193.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex193.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex193.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":1980,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/12\/397-spiral-that-goes-around-circular-paraboloid-by-python\/","url_meta":{"origin":1984,"position":5},"title":"#397 Spiral that goes around circular paraboloid by python","author":"gantovnik","date":"2023-12-18","format":false,"excerpt":"[code language=\"python\"] import numpy as np import matplotlib.pyplot as plt fig = plt.figure() ax = plt.axes(projection='3d') # Surface ------------------ # Create the mesh in polar coordinates and compute corresponding Z r0 = 5 r = np.linspace(0, r0, 50) p = np.linspace(0, 2*np.pi, 50) R, P = np.meshgrid(r, p) Z =\u2026","rel":"","context":"In &quot;matplotlib&quot;","block_context":{"text":"matplotlib","link":"https:\/\/gantovnik.com\/bio-tips\/category\/matplotlib\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/12\/ex397.png?fit=640%2C480&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/12\/ex397.png?fit=640%2C480&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/12\/ex397.png?fit=640%2C480&ssl=1&resize=525%2C300 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/1984","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/comments?post=1984"}],"version-history":[{"count":2,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/1984\/revisions"}],"predecessor-version":[{"id":2047,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/1984\/revisions\/2047"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media\/1985"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=1984"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=1984"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=1984"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}