/* [wxMaxima batch file version 1] [ DO NOT EDIT BY HAND! ]*/ /* [ Created with wxMaxima version 0.8.5 ] */ /* [wxMaxima: input start ] */ /* some initial settings */ load(draw)$ ratprint : false $ /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ /* let the polygon have n=5 vertices */ n : 5 $ /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ /* define the polygon's vertices */ v[1] : [ 1.0, 0.0] $ v[2] : [ 0.5, 0.8] $ v[3] : [-0.3, 1.0] $ v[4] : [-1.0, -0.2] $ v[5] : [ 0.0, -1.0] $ /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ /* plot the polygon */ draw2d( polygon( makelist( v[i], i,1,n ) ) ) $ /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ v : [x,y]; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ /* compute relevant areas and distances (as 'functions' of "v") */ for i : 1 thru n do ( ip : mod( i, n ) + 1, im : mod( i+n-2, n ) + 1, A[i] : determinant( matrix( v[i ]-v, v[ip]-v ) ), B[i] : determinant( matrix( v[im]-v, v[ip]-v ) ), r[i] : sqrt( (v[i]-v).(v[i]-v) ) ); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ /* set up some specific choice of functions c[i] */ /* note how the function "f" is define using ":=" */ f(x) := 1; for i : 1 thru n do ( c[i] : f(r[i]) ); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ /* general formula for homogeneous barycentric coordinates */ /* note that "ip" and "im" are equal to "i+1" and "i-1", w.r.t. to {1,2,...,n} */ for i : 1 thru n do ( ip : mod( i, n ) + 1, im : mod( i+n-2, n ) + 1, w[i] : ( c[ip] * A[im] - c[i] * B[i] + c[im] * A[i] ) / ( A[im] * A[i] ) ); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ /* we sum up all homogeneous coordinates */ W : sum( w[i], i,1,n ) $ /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ /* to then define the normalized barycentric coordinates */ for i : 1 thru n do ( b[i] : ratsimp( w[i] / W ) ); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ /* check that they add up to one */ ratsimp( sum( b[i], i,1,n ) ); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ /* and have the reproduction property */ ratsimp( sum( b[i]*v[i], i,1,n ) ); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ /* note that it can be a rather complicated function */ b[1]; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ /* plot of one of the barycentric basis functions with contour lines */ poly3d : append( makelist( [ v[i][1], v[i][2], 0 ], i,1,n ), [[ v[1][1], v[1][2], 0 ]] ) $ draw3d( line_type = solid, points_joined = true, points( poly3d ), color = green, explicit( b[1], x,-1.51,1.52, y,-1.53,1.54 ), contour_levels = [0, 0.1, 1.01], contour = both ) $ /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ /* alternative plot of the j-th basis function, and */ /* the piecewise linear behaviour along the polygon */ j : 1 $ for i : 1 thru n do ( f[i] : 0 ); f[j] : 1 $ poly3d : append( makelist( [ v[i][1], v[i][2], f[i] ], i,1,n ), [[ v[1][1], v[1][2], f[1] ]] ) $ draw3d( enhanced3d = true, palette = color, explicit( b[j], x,-1.51,1.52, y,-1.53,1.54 ), enhanced3d = false, color = black, line_type = solid, line_width = 3, points_joined = true, points( poly3d ) ) $ /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ /* the non-interactive version of the plot */ wxplot3d( b[j], [x,-1.51,1.52], [y,-1.53,1.54], [z,-1,2], [gnuplot_pm3d, false] ); /* [wxMaxima: input end ] */ /* Maxima can't load/batch files which end with a comment! */ "Created with wxMaxima"$