#! /usr/bin/env python # def annulus_area ( center, r1, r2 ): #*****************************************************************************80 # ## ANNULUS_AREA computes the area of a circular annulus in 2D. # # Discussion: # # A circular annulus with center (XC,YC), inner radius R1 and # outer radius R2, is the set of points (X,Y) so that # # R1^2 <= (X-XC)^2 + (Y-YC)^2 <= R2^2 # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 05 July 2018 # # Author: # # John Burkardt # # Parameters: # # Input, real CENTER(2), the coordinates of the center. # This data is actually not necessary for area calculations. # # Input, real R1, R2, the inner and outer radii of the annulus. # 0.0 <= R1 <= R2. # # Output, real AREA, the area of the annulus. # import numpy as np from sys import exit if ( r1 < 0.0 ): print ( '' ) print ( 'ANNULUS_AREA - Fatal error!' ) print ( ' Inner radius R1 < 0.0.' ) exit ( 'ANNULUS_AREA - Fatal error!' ) if ( r2 < r1 ): print ( '' ) print ( 'ANNULUS_AREA - Fatal error!' ) print ( ' Outer radius R1 < R1 = inner radius.' ) exit ( 'ANNULUS_AREA - Fatal error!' ) area = np.pi * ( r2 + r1 ) * ( r2 - r1 ) return area def annulus_area_test ( ): #*****************************************************************************80 # ## ANNULUS_AREA_TEST test ANNULUS_AREA. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 05 July 2018 # # Author: # # John Burkardt # import numpy as np from r8vec_uniform_01 import r8vec_uniform_01 print ( '' ) print ( 'ANNULUS_AREA_TEST' ) print ( ' ANNULUS_AREA computes the area of an annulus with' ) print ( ' center = (CX,CY), inner radius R1 and outer radius R2.' ) seed = 123456789 print ( '' ) print ( ' ( CX CY ) R1 R2 Area' ) print ( '' ) center = np.zeros ( 2 ) for i in range ( 0, 10 ): data, seed = r8vec_uniform_01 ( 4, seed ) center[0] = 10.0 * data[0] - 5.0 center[1] = 10.0 * data[1] - 5.0 r1 = data[2] r2 = r1 + data[3] area = annulus_area ( center, r1, r2 ) print ( ' (%9.6f,%9.6f) %9.6f %9.6f %9.6f' \ % ( center[0], center[1], r1, r2, area ) ) # # Terminate. # print ( '' ) print ( 'ANNULUS_AREA_TEST' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) annulus_area_test ( ) timestamp ( )