/* Autor: Amaro R. Silva, Prof. IST- Mar. 1994 * ponha libML.a e mathlink.h em locais acessiveis ao compilador e linker * uso geral em unix: * * mprep templatefile.tm -o templatefile.tm.c * gcc -o exefile codefile.c templatefile.tm.c -lML -lm * * (veja as notas de ajuda para compilar noutros sistemas) * * Use Line[Partition[Arrow[...],2]] no Mathematica para desenhar o resultado */ #include "mathlink.h" #include "mdefs.h" #include #include #include /*==========================Global Vars============================*/ double *arrowlist,x,y,L,s; void rotatetip(); arrow(double *data,int n,double h) { int i,j,k=0; s=h; MLFlush(stdlink); MLClearError(stdlink); k=0; while(k<=n){arrowlist[k]=data[k];k++;} L=sqrt(data[0]*data[0]+data[1]*data[1]); rotatetip(arrowlist); MLPutRealList(stdlink,arrowlist,n+10); MLEndPacket(stdlink); MLFlush(stdlink); MLClearError(stdlink); return; } /*========================================================================*/ void rotatetip(double *data) /*========================================================================*/ { double tip[]={-2.,0.,-1., 1., 3., -1.,-3.,-1.,1.,1.}; int i; x=data[0]; y=data[1]; for(i=0;i<10;i+=2){ arrowlist[2+i]=arrowlist[i]+s*(tip[i]*x-tip[i+1]*y)/(L+.1); arrowlist[2+i+1]=arrowlist[i+1]+s*(tip[i]*y+tip[i+1]*x)/(L+.1); } return ; } int main(int argc, char *argv[]) { arrowlist=(double *)malloc(sizeof(double)*100000); MLMain(argc, argv); free(arrowlist); return ; }