#! /usr/bin/env python def reference_to_physical_t3 ( t, n, ref ): #*****************************************************************************80 # ## REFERENCE_TO_PHYSICAL_T3 maps a reference point to a physical point. # # Discussion: # # Given the vertices of an order 3 physical triangle and a point # (XSI,ETA) in the reference triangle, the routine computes the value # of the corresponding image point (X,Y) in physical space. # # Note that this routine may also be appropriate for an order 6 # triangle, if the mapping between reference and physical space # is linear. This implies, in particular, that the sides of the # image triangle are straight and that the "midside" nodes in the # physical triangle are halfway along the sides of # the physical triangle. # # Reference Element T3: # # | # 1 3 # | |\ # | | \ # S | \ # | | \ # | | \ # 0 1-----2 # | # +--0--R--1--> # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 18 July 2018 # # Author: # # John Burkardt # # Parameters: # # Input, real T(2,3), the coordinates of the vertices. The vertices are assumed # to be the images of (0,0), (1,0) and (0,1) respectively. # # Input, integer N, the number of points to transform. # # Input, real REF(2,N), the coordinates of points in the reference space. # # Output, real PHY(2,N), the coordinates of the corresponding points in the # physical space. # import numpy as np phy = np.zeros ( [ 2, n ] ) for i in range ( 0, 2 ): phy[i,:] = t[i,0] * ( 1.0 - ref[0,:] - ref[1,:] ) \ + t[i,1] * ref[0,:] \ + t[i,2] * ref[1,:] return phy def reference_to_physical_t3_test ( ): #*****************************************************************************80 # ## REFERENCE_TO_PHYSICAL_T3_TEST tests REFERENCE_TO_PHYSICAL_T3. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 18 July 2018 # # Author: # # John Burkardt # import numpy as np import platform from r8mat_transpose_print import r8mat_transpose_print print ( '' ) print ( 'REFERENCE_TO_PHYSICAL_T3_TEST:' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' REFERENCE_TO_PHYSICAL_T3 maps points in a reference triangle' ) print ( ' to points in a physical triangle.' ) t = np.array ( [ \ [ 2.0, 3.0, 0.0 ], \ [ 0.0, 4.0, 3.0 ] ] ) n = 3 ref = np.array ( [ \ [ 0.0, 1.0, 0.0 ], \ [ 0.0, 0.0, 1.0 ] ] ) r8mat_transpose_print ( 2, 3, t, ' XY triangle vertices:' ) phy = reference_to_physical_t3 ( t, n, ref ) print ( '' ) print ( ' Apply map to RS triangle vertices.' ) print ( ' Recover XY vertices (2,0), (3,4) and (0,3).' ) print ( '' ) for j in range ( 0, 3 ): print ( ' V(%d) = ( %g, %g )' % ( j, phy[0,j], phy[1,j] ) ) # # Terminate. # print ( '' ) print ( 'REFERENCE_TO_PHYSICAL_T3_TEST:' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) reference_to_physical_t3_test ( ) timestamp ( )