#!/usr/bin/env python # def tetrahedron_grid_display ( xv, ng, xg, filename ): #*****************************************************************************80 # ## TETRAHEDRON_GRID_DISPLAY displays grid points inside a tetrahedron. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 15 April 2015 # # Author: # # John Burkardt # # Parameters: # # Input, real XV[4,3], the vertices. # # Input, integer NG, the number of grid points. # # Input, real XG[NG,3], the grid points. # # Input, string FILENAME, the name of the plotfile to be created. # import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D fig = plt.figure ( ) ax = fig.add_subplot ( 111, projection = '3d' ) # # Draw the grid points. # ax.scatter ( xg[:,0], xg[:,1], xg[:,2], 'b' ) # # Outline the region by its edges. # ax.plot ( [ xv[0,0], xv[1,0] ], [ xv[0,1], xv[1,1] ], [ xv[0,2], xv[1,2] ], 'r' ) ax.plot ( [ xv[0,0], xv[2,0] ], [ xv[0,1], xv[2,1] ], [ xv[0,2], xv[2,2] ], 'r' ) ax.plot ( [ xv[0,0], xv[3,0] ], [ xv[0,1], xv[3,1] ], [ xv[0,2], xv[3,2] ], 'r' ) ax.plot ( [ xv[1,0], xv[2,0] ], [ xv[1,1], xv[2,1] ], [ xv[1,2], xv[2,2] ], 'r' ) ax.plot ( [ xv[1,0], xv[3,0] ], [ xv[1,1], xv[3,1] ], [ xv[1,2], xv[3,2] ], 'r' ) ax.plot ( [ xv[2,0], xv[3,0] ], [ xv[2,1], xv[3,1] ], [ xv[2,2], xv[3,2] ], 'r' ) ax.set_xlabel ( '<---X--->' ) ax.set_ylabel ( '<---Y--->' ) ax.set_zlabel ( '<---Z--->' ) ax.set_title ( 'Grid points in tetrahedron' ) ax.grid ( True ) ax.axis ( 'equal' ) plt.savefig ( filename ) plt.show ( ) plt.clf ( ) return def tetrahedron_grid_display_test ( ): #*****************************************************************************80 # ## TETRAHEDRON_GRID_DISPLAY displays grid points inside a tetrahedron. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 15 April 2015 # # Author: # # John Burkardt # import numpy as np import platform print ( '' ) print ( 'TETRAHEDRON_GRID_DISPLAY_TEST:' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' TETRAHEDRON_GRID_DISPLAY can display a grid of points in a tetrahedron.' ) xv = np.array ( [ \ [ 0.0, 0.0, 0.0 ], \ [ 2.0, 0.0, 0.0 ], \ [ 0.0, 2.0, 0.0 ], \ [ 0.0, 0.0, 2.0 ] ] ) ng = 10 xg = np.array ( [ \ [ 0.0, 0.0, 0.0 ], \ [ 1.0, 0.0, 0.0 ], \ [ 2.0, 0.0, 0.0 ], \ [ 0.0, 1.0, 0.0 ], \ [ 0.0, 2.0, 0.0 ], \ [ 1.0, 1.0, 0.0 ], \ [ 0.0, 0.0, 1.0 ], \ [ 1.0, 0.0, 1.0 ], \ [ 0.0, 1.0, 1.0 ], \ [ 0.0, 0.0, 2.0 ] ] ) filename = 'tetrahedron_grid_display.png' tetrahedron_grid_display ( xv, ng, xg, filename ) # # Terminate. # print ( '' ) print ( 'TETRAHEDRON_GRID_DISPLAY_TEST:' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) tetrahedron_grid_display_test ( ) timestamp ( )