File:Mrs Miniver's Problem.svg

From testwiki
Jump to navigation Jump to search
    Original file (SVG file, nominally 900 × 348 pixels, file size: 793 bytes)

    This file is from Wikimedia Commons and may be used by other projects. The description on its file description page there is shown below.

    Summary

    Description
    English: Three instances of Mrs. Miniver's problem, of arranging two circles so that their area of overlap equals the area of their symmetric difference. In each case the inner yellow area equals the total area of the surrounding blue regions. The left case shows two circles of equal areas, the right case shows one circle with twice the area of the other, and the middle case is intermediate between these two.
    Date
    Source Own work
    Author David Eppstein
    SVG development
    InfoField
     The SVG code is valid.
     This vector image was created with Python.

    Licensing

    David Eppstein, the copyright holder of this work, hereby publishes it under the following license:
    Creative Commons CC-Zero This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication.
    The person who associated a work with this deed has dedicated the work to the public domain by waiving all of their rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.

    Source code

    The logo of Python – general-purpose programming language
    The logo of Python – general-purpose programming language
    This media was created with Python (general-purpose programming language)
    Here is a listing of the source used to create this file.

    Deutsch ∙ македонски ∙ English ∙ +/−

    from math import pi,asin,sin,cos,acos
    from PADS.SVG import *
    import sys
    
    # Circular segment formulas from https://en.wikipedia.org/wiki/Circular_segment
    
    def areaFromRadius(r): return pi*r**2
    
    def twoCircleArea(r1,r2): return areaFromRadius(r1)+areaFromRadius(r2)
    
    def angleFromChord(r,c):
        return 2*asin(c/(2*r))
    
    def areaFromAngle(r,theta):
        return r**2*(theta-sin(theta))/2
    
    def areaFromChord(r,c):
        theta = angleFromChord(r,c)
        return areaFromAngle(r,theta)
    
    def distanceToChord(r,c):
        theta = angleFromChord(r,c)
        return r*cos(theta/2)
    
    def separationFromChord(r1,r2,c):
        return distanceToChord(r1,c)+distanceToChord(r2,c)
    
    # Bisection to solve Mrs. Miniver's problem within floating point accuracy
    
    def miniverSeparation(r1,r2):
        if r1 > r2: r1,r2 = r2,r1   # make sure small circle first
        totalArea = twoCircleArea(r1,r2)
        targetArea = totalArea/3
    
        def miniverTest(x):
            # x = cos(chord on small circle), -1: outside, 1: inside
            chord = 2*r1*sin(acos(x))
            area1 = areaFromChord(r1,chord)
            if x > 0:
                area1 = areaFromRadius(r1) - area1
            area2 = areaFromChord(r2,chord)
            return area1 + area2 < targetArea
    
        lo,hi = -1.0,1.0
        for i in range(100):
            mid = (hi+lo)/2
            if miniverTest(mid):
                lo = mid
            else:
                hi = mid
        chord = 2*r1*sin(acos(mid))
        return distanceToChord(r2,chord) - r1*mid
    
    # Make it into a nice picture
    # Monochromatic and with a loose frame for now; we'll fix it up later
    
    gridUnit = 150
    targetArea = 100000.0
    boundingBox = (6+4j)*gridUnit
    output = SVG(boundingBox,sys.stdout)
    output.group(fill="none",stroke="#000")
    
    for i in (0,1,2):
        ratio = 2.0**(i*0.25)
        areaWhenSmall = twoCircleArea(1.0,ratio)
        factor = (targetArea/areaWhenSmall)**0.5
        r1,r2 = factor,factor*ratio
        s = miniverSeparation(r1,r2)
        o = (1+2j+2*i)*gridUnit
        output.circle(o + (s+r2-r1)*0.5j, r1)
        output.circle(o - (s+r1-r2)*0.5j, r2)
      
    output.ungroup()
    output.close()
    

    Captions

    Three instances of Mrs. Miniver's Problem

    Items portrayed in this file

    depicts

    28 May 2022

    image/svg+xml

    793 byte

    04278de1885f6bc30806e41753b54bbe8c6addd4

    File history

    Click on a date/time to view the file as it appeared at that time.

    Date/TimeThumbnailDimensionsUserComment
    current20:35, 29 May 2022Thumbnail for version as of 20:35, 29 May 2022900 × 348 (793 bytes)wikimediacommons>David EppsteinKeep outer circles as circles for tighter svg coding; should be no visible change

    There are no pages that use this file.