/* [wxMaxima batch file version 1] [ DO NOT EDIT BY HAND! ]*/ /* [ Created with wxMaxima version 0.8.5 ] */ /* [wxMaxima: input start ] */ /* define vertices of a triangle and data given at these vertices */ /* assignment with ":" | array elements via "[.]" */ /* generate output with ";" and suppress with "$" */ v[1] : [-1.0, 0.0]; f[1] : 0.5 $ v[2] : [ 1.0, -0.5]; f[2] : -0.5 $ v[3] : [ 0.8, 0.5]; f[3] : 1.0 $ /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ /* generate the list " [ v[1], v[2], v[3] ] " */ poly : makelist( v[i], i,1,3 ); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ /* plot the vertices in this list by connecting them with lines */ wxplot2d( [ 'discrete, poly ] ) $ /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ /* to connect v[3] with v[1], we simply extend the list by adding v[1] */ poly : append( poly, [v[1]] ); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ /* now the plot shows the complete triangle */ wxplot2d( [ 'discrete, poly ] ) $ /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ /* but the "draw" library also offers a simpler way to plot closed polygons */ load( draw ) $ draw2d( polygon( makelist( v[i], i,1,3 ) ) ) $ /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ /* let us introduce the general planar point "v" with coordiates (x,y) */ v : [x,y]; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ /* compute areas of triangles formed by "v" and each of the triangle's edges */ w[1] : determinant( matrix( v[2]-v, v[3]-v ) ); w[2] : determinant( matrix( v[3]-v, v[1]-v ) ); w[3] : determinant( matrix( v[1]-v, v[2]-v ) ); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ /* compute the sum of these areas */ W : sum( w[i], i,1,3 ); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ /* this should be equal to the area of the triangle, so let us check */ A : determinant ( matrix ( v[2]-v[1], v[3]-v[1] ) ); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ /* indeed, if we simplify "W", then we see that this is indeed the case */ /* note: setting "ratprint" to "false" suppresses some additional output */ ratprint : false $ ratsimp( W ); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ /* finally, we define the barycentric coordinates of "v" w.r.t. the triangle */ for i : 1 thru 3 do ( b[i] : w[i] / W ); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ /* after simplification, we can see the linear nature of the b.c.'s */ ratsimp( b[1] ); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ /* they clearly add up to one */ ratsimp( sum( b[i], i,1,3 ) ); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ /* and have the reproduction property */ ratsimp( sum( b[i]*v[i], i,1,3) ); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ /* this is one way of plotting a bivariate function */ wxplot3d( b[1], [x,-1,1], [y,-1,1], [z,0,1], [gnuplot_pm3d, false] ); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ /* here is an alternative way, which provides an interactive interface */ poly3d : append( makelist( [ v[i][1], v[i][2], 0 ], i,1,3 ), [[ v[1][1], v[1][2], 0 ]] ) $ draw3d( line_type = solid, points_joined = true, points( poly3d ), color = green, explicit( b[1], x,-1.5,1.5, y,-1.5,1.5 ), contour_levels = [0, 0.1, 1.01], contour = both ) $ /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ /* the linear interpolant to the given data is easily defined via b.c.'s */ F : ratsimp( sum( b[i] * f[i], i,1,3 ) ); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ /* and here is yet another way of plotting bivariate functions */ poly3d : append( makelist( [ v[i][1], v[i][2], f[i] ], i,1,3 ), [[ v[1][1], v[1][2], f[1] ]] ) $ draw3d( enhanced3d = true, palette = color, explicit( F, x,-1.5,1.5, y,-1.5,1.5 ), enhanced3d = false, color = black, line_type = solid, line_width = 3, points_joined = true, points( poly3d ) ) $ /* [wxMaxima: input end ] */ /* Maxima can't load/batch files which end with a comment! */ "Created with wxMaxima"$