#! /usr/bin/env python # def tetrahedron_grid_count ( n ): #*****************************************************************************80 # ## TETRAHEDRON_GRID_COUNT counts the grid points inside a tetrahedron. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 15 April 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer N, the number of subintervals. # # Output, integer NG, the number of grid points. # ng = ( ( n + 1 ) * ( n + 2 ) * ( n + 3 ) ) // 6 return ng def tetrahedron_grid_count_test ( ): #*****************************************************************************80 # ## TETRAHEDRON_GRID_COUNT_TEST tests TETRAHEDRON_GRID_COUNT. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 15 April 2015 # # Author: # # John Burkardt # import platform print ( '' ) print ( 'TETRAHEDRON_GRID_COUNT_TEST:' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' TETRAHEDRON_GRID_COUNT can count the points in a grid' ) print ( ' with N+1 points on a side, based on any tetrahedron.' ) print ( '' ) print ( ' N NG' ) print ( '' ) for n in [ 1, 2, 3, 4, 5, 10, 15, 20, 25, 50, 100 ]: ng = tetrahedron_grid_count ( n ) print ( ' %4d %8d' % ( n, ng ) ) # # Terminate. # print ( '' ) print ( 'TETRAHEDRON_GRID_COUNT_TEST:' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) tetrahedron_grid_count_test ( ) timestamp ( )