/*! \fn MFImplicitMF MFIMFCreateSphere(double x,double y,double z,double R, MFErrorHandler e); * \brief Creates an implicitly defined manifold for a 2-sphere embedded in 3-space, centered at (x,y,z) with * radius R. * * \param x The x coordinate of the center of the sphere * \param y The y coordinate of the center of the sphere * \param z The z coordinate of the center of the sphere * \param R The radius. * \param e An error handler. * \returns An implicitly defined manifold. */ MFImplicitMF MFIMFCreateSphere(double x,double y,double z,double R, MFErrorHandler e) { static char RoutineName[]={"MFIMFCreateSphere"}; MFImplicitMF sphere; MFNSpace space; double *data; sphere=MFIMFCreateBaseClass(3,2,"Sphere",e); space=MFCreateNSpace(3,e); MFIMFSetSpace(sphere,space,e); MFFreeNSpace(space,e); data=(double*)malloc(4*sizeof(double)); #ifndef MFNPOSAFETYNET if(data==NULL) { sprintf(MFSphereMFErrorHandlerMsg,"Out of memory, trying to allocate %d bytes",4*sizeof(double)); MFSetError(e,12,RoutineName,MFSphereMFErrorHandlerMsg,__LINE__,__FILE__); MFErrorHandlerOutOfMemory(e); free(sphere); return NULL; } #endif data[0]=x; data[1]=y; data[2]=z; data[3]=R; MFIMFSetData(sphere,(void*)data,e); MFIMFSetFreeData(sphere,MFFreeSphereData,e); MFIMFSetProject(sphere,MFProjectSphere,e); MFIMFSetTangent(sphere,MFTangentSphere,e); MFIMFSetR(sphere,-1.,e); MFIMFSetScale(sphere,MFScaleSphere,e); MFIMFSetWriteData(sphere,MFWriteSphereData,e); MFIMFSetProjectForSave(sphere,MFSphereProjectToSave,e); MFIMFSetProjectForDraw(sphere,MFSphereProjectToDraw,e); MFIMFSetProjectForBB(sphere,MFSphereProjectForBB,e); MFIMFSetVectorFactory(sphere,MFNVectorFactory,e); MFIMFSetMatrixFactory(sphere,MFNKMatrixFactory,e); return sphere; }
/*! \fn MFImplicitMF MFIMFCreateCircle(double x,double y,double R, MFErrorHandler e); * \brief Creates an implicitly defined manifold for a circle embedded in the plane, centered at (x,y) with * radius R. * * \param x The x coordinate of the center of the circle * \param y The y coordinate of the center of the circle * \param R The radius. * \param e An error handler. * \returns An implicitly defined manifold. */ MFImplicitMF MFIMFCreateCircle(double x,double y,double R, MFErrorHandler e) { static char RoutineName[]={"MFIMFCreateCircle"}; MFImplicitMF circle; MFNSpace space; double *data; circle=MFIMFCreateBaseClass(2,1,"Circle",e); space=MFCreateNSpace(2,e); MFIMFSetSpace(circle,space,e); MFFreeNSpace(space,e); data=(double*)malloc(3*sizeof(double)); #ifndef MFNOSAFETYNET if(data==NULL) { sprintf(MFCircleMFErrorHandlerMsg,"Out of memory, trying to allocate %d bytes",3*sizeof(double)); MFSetError(e,12,RoutineName,MFCircleMFErrorHandlerMsg,__LINE__,__FILE__); free(circle); return NULL; } #endif data[0]=x; data[1]=y; data[2]=R; MFIMFSetData(circle,data,e); MFIMFSetFreeData(circle,MFFreeCircleData,e); MFIMFSetProject(circle,MFProjectCircle,e); MFIMFSetTangent(circle,MFTangentCircle,e); MFIMFSetScale(circle,MFScaleCircle,e); MFIMFSetWriteData(circle,MFWriteCircleData,e); MFIMFSetProjectForSave(circle,MFCircleProjectToSave,e); MFIMFSetProjectForDraw(circle,MFCircleProjectToDraw,e); MFIMFSetProjectForBB(circle,MFCircleProjectForBB,e); MFIMFSetVectorFactory(circle,MFNVectorFactory,e); MFIMFSetMatrixFactory(circle,MFNKMatrixFactory,e); return circle; }
MFImplicitMF MFIMFCreateLOCA(LOCAData* data) { MFImplicitMF loca; MFNSpace space; loca=MFIMFCreateBaseClass(-1, data->np, "LOCA", data->mfErrorHandler); space=MFCreateLOCANSpace(data); MFIMFSetSpace(loca,space, data->mfErrorHandler); MFFreeNSpace(space, data->mfErrorHandler); MFIMFSetData(loca,(void*)data, data->mfErrorHandler); data->space=space; MFRefNSpace(space, data->mfErrorHandler); MFIMFSetFreeData(loca,MFLOCAFreeData, data->mfErrorHandler); MFIMFSetProject(loca,MFProjectLOCA, data->mfErrorHandler); MFIMFSetTangent(loca,MFTangentLOCA, data->mfErrorHandler); MFIMFSetScale(loca,MFScaleLOCA, data->mfErrorHandler); MFIMFSetProjectForSave(loca,MFLOCAProjectToDraw, data->mfErrorHandler); MFIMFSetProjectForDraw(loca,MFLOCAProjectToDraw, data->mfErrorHandler); MFIMFSetProjectForBB(loca,MFLOCAProjectToDraw, data->mfErrorHandler); return loca; }
/*! \fn MFAtlas IMFComputeInvariantManifold(IMFFlow F,MFKVector p0,char *name, MFAtlas c,MFNRegion Omega, double eps, double dt, double tmax, int maxInterp, int maxCharts, double Rmax, MFErrorHandler e); * \brief Computes an atlas of charts that cover the image of a manifold under a flow. A streamsurface. * * \param L The flow. * \param name A name to used for paging files and so forth. * \param u0 The fixed point. * \param p0 The parameters of the flow for the fixed point. * \param c The manifold of initial conditions. * \param Omega A region to bound the computation. * \param eps The tolerance on the size of the quadratic terms over a balls. Controls the stepsize. * \param dt The initial timestep to use along a fat trajectory. * \param tmax The upper limit on trajectory length. * \param maxInterp The upper limit on the number of interpolation performed. * \param maxCharts The upper limit on the number of charts in the atlas. * \param RMax An upper limit to impose on the radius of the balls along the fat trajectories. * \param e An MFErrorHandler to handle exceptions and errors. * \returns A new Atlas */ MFAtlas IMFComputeInvariantManifold(IMFFlow F,MFKVector p0,char *name, MFAtlas c,MFNRegion Omega, double eps, double dt, double tmax, int maxInterp, int maxCharts, double Rmax,MFErrorHandler e) { static char RoutineName[]= {"IMFComputeInvariantManifold"}; double s0[2],s1[2]; double *ddu; double *du; MFKVector s; MFNVector ug,v; MFNKMatrix Phi; MFNKMatrix Psi; int i; int ii,jj; IMFExpansion cE,U; MFContinuationMethod H; MFAtlas A; MFAtlas I; MFImplicitMF M; double R,r; char sname[1024]; FILE *fid; MFNKMatrix TS; MFNVector ui; double t; int chart; MFNVector sigma; MFKVector zero; double *u0; int n,k; int verbose=0; if(verbose) { printf("in %s\n",RoutineName); fflush(stdout); } n=MFAtlasN(c,e); k=MFAtlasK(c,e); M=IMFCreateFlat(n,k+1,e); MFIMFSetProjectForDraw(M,MFIMFGetProjectForDraw(MFAtlasMF(c,e),e),e); MFIMFSetProjectForSave(M,MFIMFGetProjectForSave(MFAtlasMF(c,e),e),e); MFIMFSetProjectForBB (M,MFIMFGetProjectForBB (MFAtlasMF(c,e),e),e); MFIMFSetR(M,Rmax/2,e); I=MFCreateAtlas(M,e); printf("%s, Create Atlas I=0x%8.8x\n",RoutineName,I); fflush(stdout); H=MFCreateMultifariosMethod(e); MFMultifarioSetIntegerParameter(H,"page",0,e); MFMultifarioSetIntegerParameter(H,"maxCharts",-1,e); MFMultifarioSetIntegerParameter(H,"dumpToPlotFile",1,e); MFMultifarioSetFilename(H,name,e); u0=(double*)malloc(n*sizeof(double)); #ifndef MFNOSAFETYNET if(u0==NULL) { sprintf(MFNSpaceErrorMsg,"Out of memory trying to allocate %d bytes\n",n*k*sizeof(double)); MFSetError(e,12,RoutineName,MFNSpaceErrorMsg,__LINE__,__FILE__); MFErrorHandlerOutOfMemory(e); return NULL; } #endif du=(double*)malloc(n*k*sizeof(double)); #ifndef MFNOSAFETYNET if(du==NULL) { sprintf(MFNSpaceErrorMsg,"Out of memory trying to allocate %d bytes\n",n*k*sizeof(double)); MFSetError(e,12,RoutineName,MFNSpaceErrorMsg,__LINE__,__FILE__); MFErrorHandlerOutOfMemory(e); return NULL; } #endif ddu=(double*)malloc(n*k*k*sizeof(double)); #ifndef MFNOSAFETYNET if(ddu==NULL) { sprintf(MFNSpaceErrorMsg,"Out of memory trying to allocate %d bytes\n",n*sizeof(double)); MFSetError(e,12,RoutineName,MFNSpaceErrorMsg,__LINE__,__FILE__); MFErrorHandlerOutOfMemory(e); return NULL; } #endif zero=MFCreateKVector(k-1,e); s0[0]=-r; s1[0]= r; s0[1]=-r; s1[1]= r; for(i=0; i<n*k*k; i++)ddu[i]=0.; for(i=0; i<MFAtlasNumberOfCharts(c,e); i++) { if(verbose) { printf(" chart %d on the initial manifold\n",i); fflush(stdout); } if(MFNV_CStar(MFAtlasChartCenter(c,i,e),e)!=NULL) { for(ii=0; ii<n; ii++) u0[ii]=MFNV_CStar(MFAtlasChartCenter(c,i,e),e)[ii]; } else { for(ii=0; ii<n; ii++) u0[ii]=MFNV_C(MFAtlasChartCenter(c,i,e),ii,e); } Phi=MFAtlasChartTangentSpace(c,i,e); if(MFNKM_CStar(Phi,e)!=NULL) { for(ii=0; ii<n*k; ii++) du[ii]=MFNKM_CStar(Phi,e)[ii]; } else { for(ii=0; ii<n; ii++) for(jj=0; jj<k; jj++) du[ii+n*jj]=MFNKMGetC(Phi,ii,jj,e); } cE=IMFCreateExpansion(n,k,e); /* Assumes it's a straight line */ /* Assumes Phi is a dense matrix */ IMFExpansionSetDerivatives(cE,u0,du,ddu,NULL,e); U=IMFInflateExpansionWithFlow(cE,F,p0,e); ui=IMFCreateExpansionNVector(U,0.,MFAtlasCenterOfChart(c,i,e),-1,1,e); if(0&&i==0) /* Why??? */ { TS=IMFExpansionTS(cE,e); R=MFAtlasChartRadius(c,i,e); MFAtlasAddChartWithAll(I,ui,TS,R,e); } IMFExpansionNVSetChart0(ui,i,e); IMFExpansionNVSetS0(ui,zero,e); printf("*) Point on c\n"); fflush(stdout); MFPrintNVector(stdout,ui,e); printf(" Extend along fat traj\n"); fflush(stdout); IMFExtendAtlasAlongFatTraj(I,F,name,ui,p0,dt,0.,tmax,eps,Omega,maxCharts,maxCharts,Rmax,0,e); printf(" done fat traj\n"); fflush(stdout); if(0&&MFAtlasNumberOfCharts(I,e)%1000==0)MFAtlasPageOutChartsNotNearBoundary(I,1,0,name,e); MFFreeNVector(ui,e); IMFFreeExpansion(cE,e); IMFFreeExpansion(U,e); } printf("*** Done covering c\n"); fflush(stdout); #ifdef DOINTERPOLATIONPT sprintf(sname,"%s.intpt",name); IMFInterp=fopen(sname,"w"); IMFNInterp=0; #endif i=0; while(i<maxInterp&& (ui=IMFGetInterpolationPoint(I,F,p0,A,tmax,NULL,e))!=NULL && MFAtlasNumberOfCharts(I,e)<maxCharts) { printf("*** Interpolated Point %d\n",i); fflush(stdout); #ifdef DOINTERPOLATIONPT for(j=0; j<3; j++)fprintf(IMFInterp," %lf",IMFExpansionU(IMFExpansionNVGetE(ui,e))[j],e); fprintf(IMFInterp,"\n"); fflush(IMFInterp); IMFNInterp++; #endif IMFExtendAtlasAlongFatTraj(I,F,name,ui,p0,dt,IMFExpansionNVGetT(ui,e),tmax,eps,Omega,maxCharts,maxCharts,Rmax,0,e); if(0&&MFAtlasNumberOfCharts(I,e)%1000==0)MFAtlasPageOutChartsNotNearBoundary(I,1,0,name,e); MFFreeNVector(ui,e); i++; } if(i<maxInterp) { printf("*** No more interpolation points, total was %d\n",i); fflush(stdout); } else { printf("*** Max number of interpolation points reached, %d\n",i); fflush(stdout); } MFFlushAtlas(H,I,e); MFCloseAtlas(H,I,e); MFFreeContinuationMethod(H,e); MFFreeImplicitMF(M,e); free(u0); free(du); free(ddu); #ifdef DOINTERPOLATIONPT if(IMFInterp!=NULL) { fclose(IMFInterp); sprintf(sname,"i%s.dx",name); IMFInterp=fopen(sname,"w"); sprintf(sname,"%s.intpt",name); if(IMFNInterp>0) { fprintf(IMFInterp,"object \"Vertices\" class array type float rank 1 shape 3 items %d data file %s.dx\n",sname,IMFNInterp); } else { fprintf(IMFInterp,"object \"Vertices\" class array type float rank 1 shape 3 items 1 data follows\n"); fprintf(IMFInterp," 0. 0. 0.\n"); } fprintf(IMFInterper,"object \"interpolated points\" class field\n"); fprintf(IMFInterper,"component \"positions\" value \"Vertices\"\n"); fclose(IMFInterper); } #endif #ifdef DOINTERPANIM if(IMFInterper!=NULL) { fclose(IMFInterper); IMFInterper=fopen("gInterp1.dx","w"); if(IMFNInterper>0) { fprintf(IMFInterper,"object \"Vertices\" class array type float rank 1 shape 3 items %d data file Interp1.dx\n",IMFNInterper); } else { fprintf(IMFInterper,"object \"Vertices\" class array type float rank 1 shape 3 items 1 data follows\n"); fprintf(IMFInterper," 0. 0. 0.\n"); } fprintf(IMFInterper,"object \"interpolated points\" class field\n"); fprintf(IMFInterper,"component \"positions\" value \"Vertices\"\n"); fclose(IMFInterper); } if(IMFInterpee!=NULL) { fclose(IMFInterpee); IMFInterpee=fopen("gInterp2.dx","w"); if(IMFNInterpee>0) { fprintf(IMFInterpee,"object \"Vertices\" class array type float rank 1 shape 3 items %d data file Interp2.dx\n",IMFNInterpee); fprintf(IMFInterpee,"object \"Lines\" class array type int rank 1 shape 2 items %d data follows\n",IMFNInterpee/2); for(i=0; i<IMFNInterpee; i+=2) fprintf(IMFInterpee," %d %d\n",i,i+1); } else { fprintf(IMFInterpee,"object \"Vertices\" class array type float rank 1 shape 3 items 2 data follows\n"); fprintf(IMFInterpee," 0. 0. 0.\n"); fprintf(IMFInterpee," 0. 0. 0.001\n"); fprintf(IMFInterpee,"object \"Lines\" class array type int rank 1 shape 2 items 1 data follows\n"); fprintf(IMFInterpee," %d %d\n",0,1); } fprintf(IMFInterpee,"attribute \"ref\" string \"positions\"\n"); fprintf(IMFInterpee,"attribute \"element type\" string \"lines\"\n"); fprintf(IMFInterpee,"object \"interpolation points\" class field\n"); fprintf(IMFInterpee,"component \"positions\" value \"Vertices\"\n"); fprintf(IMFInterpee,"component \"connections\" value \"Lines\"\n"); fclose(IMFInterpee); } if(IMFInterpT!=NULL) { fclose(IMFInterpT); IMFInterpT=fopen("gInterp3.dx","w"); if(IMFNInterpT>0) { fprintf(IMFInterpT,"object \"Vertices\" class array type float rank 1 shape 3 items %d data file Interp3.dx\n",IMFNInterpT ); fprintf(IMFInterpT,"object \"Lines\" class array type int rank 1 shape 2 items %d data follows\n",IMFNInterpT-1); for(i=0; i<IMFNInterpT-1; i++) fprintf(IMFInterpT," %d %d\n",i,i+1); } else { fprintf(IMFInterpT,"object \"Vertices\" class array type float rank 1 shape 3 items 2 data follows\n"); fprintf(IMFInterpT," 0. 0. 0.\n"); fprintf(IMFInterpT," 0. 0. 0.001\n"); fprintf(IMFInterpT,"object \"Lines\" class array type int rank 1 shape 2 items 1 data follows\n"); fprintf(IMFInterpT," %d %d\n",0,1); } fprintf(IMFInterpT,"attribute \"ref\" string \"positions\"\n"); fprintf(IMFInterpT,"attribute \"element type\" string \"lines\"\n"); fprintf(IMFInterpT,"object \"interpolation points\" class field\n"); fprintf(IMFInterpT,"component \"positions\" value \"Vertices\"\n"); fprintf(IMFInterpT,"component \"connections\" value \"Lines\"\n"); fclose(IMFInterpT); } if(IMFCircle!=NULL) { fclose(IMFCircle); IMFCircle=fopen("gIMFCircle.dx","w"); fprintf(IMFCircle,"object \"Vertices\" class array type float rank 1 shape 3 items %d data file IMFCircle.dx\n",IMFNCircle); fprintf(IMFCircle,"object \"Lines\" class array type int rank 1 shape 2 items %d data follows\n",IMFNCircle/2); for(i=0; i<IMFNCircle; i+=2) fprintf(IMFCircle," %d %d\n",i,i+1); fprintf(IMFCircle,"attribute \"ref\" string \"positions\"\n"); fprintf(IMFCircle,"attribute \"element type\" string \"lines\"\n"); fprintf(IMFCircle,"object \"interpolation points\" class field\n"); fprintf(IMFCircle,"component \"positions\" value \"Vertices\"\n"); fprintf(IMFCircle,"component \"connections\" value \"Lines\"\n"); fclose(IMFCircle); } #endif #ifdef DOTRAJ if(IMFTraj!=NULL) { printf("dump trajectory file\n"); fflush(stdout); fclose(IMFTraj); IMFTraj=fopen("gIMFTraj.dx","w"); fprintf(IMFTraj,"object \"Vertices\" class array type float rank 1 shape 3 items %d data file IMFTraj.dx\n",IMFNTraj); fprintf(IMFTraj,"object \"Lines\" class array type int rank 1 shape 2 items %d data follows\n",IMFNTraj/2); for(i=0; i<IMFNTraj; i+=2) fprintf(IMFTraj," %d %d\n",i,i+1); fprintf(IMFTraj,"attribute \"ref\" string \"positions\"\n"); fprintf(IMFTraj,"attribute \"element type\" string \"lines\"\n"); fprintf(IMFTraj,"object \"trajectories\" class field\n"); fprintf(IMFTraj,"component \"positions\" value \"Vertices\"\n"); fprintf(IMFTraj,"component \"connections\" value \"Lines\"\n"); fclose(IMFTraj); } #endif printf("done %s\n",RoutineName); fflush(stdout); return I; }
/*! \fn MFImplicitMF MFIMFCreatePolygonIn3SpaceWithRadius(int nv,double *v,double R, MFErrorHandler e); * \brief Creates a Euclidean plane which contains the given polygon (which is assumed to be flat). * * \param nv The number of vertices. * \param v The vertices stored as (v[0+3*iv],v[1+3*iv],v[2+3*iv]). * \param R A radius to use for charts on the manifold. * \param e An error handler. * \returns An implicitly defined manifold. */ MFImplicitMF MFIMFCreatePolygonIn3SpaceWithRadius(int n,double *v,double R, MFErrorHandler e) { static char RoutineName[]={"MFIMFCreatePolygonIn3SpaceWithRadius"}; MFImplicitMF polygon; MFNSpace space; struct MFPolygonIn3SpaceData *p; double d; int verbose=0; int i; #ifdef MFALLOWVERBOSE if(verbose) { printf("%s\n",RoutineName); printf("%d\n",n); for(i=0;i<n;i++) printf(" %d (%lf,%lf,%lf)\n",i,v[3*i],v[3*i+1],v[3*i+2]); fflush(stdout); } #endif polygon=MFIMFCreateBaseClass(3,2,"PolygonIn3Space",e); space=MFCreateNSpace(3,e); MFIMFSetSpace(polygon,space,e); MFFreeNSpace(space,e); p=(struct MFPolygonIn3SpaceData*)malloc(sizeof(struct MFPolygonIn3SpaceData)); #ifndef MFNOSAFETYNET if(p==NULL) { sprintf(MFPolygonMFErrorHandlerMsg,"Out of memory, trying to allocate %d bytes",sizeof(struct MFPolygonIn3SpaceData)); MFSetError(e,12,RoutineName,MFPolygonMFErrorHandlerMsg,__LINE__,__FILE__); MFErrorHandlerOutOfMemory(e); return NULL; } #endif p->r=R; p->ox=v[0]; p->oy=v[1]; p->oz=v[2]; #ifdef MFALLOWVERBOSE if(verbose){printf(" o=(%lf,%lf,%lf)\n",p->ox,p->oy,p->oz);fflush(stdout);} #endif p->ax=v[3]-v[0]; p->ay=v[4]-v[1]; p->az=v[5]-v[2]; d=1./sqrt(p->ax*p->ax+p->ay*p->ay+p->az*p->az); p->ax=p->ax*d; p->ay=p->ay*d; p->az=p->az*d; #ifdef MFALLOWVERBOSE if(verbose){printf(" a=(%lf,%lf,%lf)\n",p->ax,p->ay,p->az);fflush(stdout);} #endif p->bx=v[6]-v[0]; p->by=v[7]-v[1]; p->bz=v[8]-v[2]; d=p->ax*p->bx+p->ay*p->by+p->az*p->bz; p->bx-=p->ax*d; p->by-=p->ay*d; p->bz-=p->az*d; d=1./sqrt(p->bx*p->bx+p->by*p->by+p->bz*p->bz); p->bx=p->bx*d; p->by=p->by*d; p->bz=p->bz*d; #ifdef MFALLOWVERBOSE if(verbose){printf(" b=(%lf,%lf,%lf)\n",p->bx,p->by,p->bz);fflush(stdout);} #endif p->nx=p->ay*p->bz-p->az*p->by; p->ny=p->az*p->bx-p->ax*p->bz; p->nz=p->ax*p->by-p->ay*p->bx; #ifdef MFALLOWVERBOSE if(verbose){printf(" n=(%lf,%lf,%lf)\n",p->nx,p->ny,p->nz);fflush(stdout);} #endif MFIMFSetData(polygon,(void*)p,e); MFIMFSetFreeData(polygon,MFFreePolygonIn3SpaceData,e); MFIMFSetProject(polygon,MFProjectPolygonIn3Space,e); MFIMFSetTangent(polygon,MFTangentPolygonIn3Space,e); MFIMFSetScale(polygon,MFScalePolygonIn3Space,e); MFIMFSetR(polygon,R,e); MFIMFSetProjectForBB(polygon,MFPolygonIn3SpaceProjectForBB,e); MFIMFSetProjectForDraw(polygon,MFPolygonIn3SpaceProjectForBB,e); MFIMFSetWriteData(polygon,MFWritePolygonIn3SpaceData,e); MFIMFSetVectorFactory(polygon,MFNVectorFactory,e); MFIMFSetMatrixFactory(polygon,MFNKMatrixFactory,e); /* Test */ #ifdef MFALLOWVERBOSE if(verbose) { printf("Tangent [ %lf %lf %lf ]\n", (p->ax*p->ax+p->ay*p->ay+p->az*p->az), (p->ax*p->bx+p->ay*p->by+p->az*p->bz), (p->ax*p->nx+p->ay*p->ny+p->az*p->nz)); printf(" [ %lf %lf %lf ]\n", (p->bx*p->ax+p->by*p->ay+p->bz*p->az), (p->bx*p->bx+p->by*p->by+p->bz*p->bz), (p->bx*p->nx+p->by*p->ny+p->bz*p->nz)); printf(" [ %lf %lf %lf ]\n", (p->nx*p->ax+p->ny*p->ay+p->nz*p->az), (p->nx*p->bx+p->ny*p->by+p->nz*p->bz), (p->nx*p->nx+p->ny*p->ny+p->nz*p->nz)); for(i=1;i<n;i++) { d=(p->nx*(v[3*i]-v[0])+p->ny*(v[3*i+1]-v[1])+p->nz*(v[3*i+2]-v[2])); printf(" (x[%d]-x[0]).n=%lf\n",i,d); } printf("done %s\n",RoutineName);fflush(stdout); } #endif return polygon; }
/*! \fn MFImplicitMF MFIMFCreateEdgeIn3SpaceWithRadius(double *o,double *d,double R, MFErrorHandler e); * \brief Creates a Euclidean line which contains the segment between the points l and r (left and right). * * \param o An array of length at least 3, with the coordinates of the left end point of the interval. * \param d An array of length at least 3, with the coordinates of the right end point of the interval. * \param R A radius to use for charts on the manifold. * \param e An error handler. * \returns An implicitly defined manifold. */ MFImplicitMF MFIMFCreateEdgeIn3SpaceWithRadius(double *v0, double *v1,double R, MFErrorHandler e) { static char RoutineName[]={"MFIMFCreateEdgeIn3SpaceWithRadius"}; MFImplicitMF edge; MFNSpace space; struct MFEdgeIn3SpaceData *p; double d; int verbose=0; int i; #ifdef MFALLOWVERBOSE if(verbose)printf("%s\n",RoutineName); #endif edge=MFIMFCreateBaseClass(3,1,"EdgeIn3Space",e); space=MFCreateNSpace(3,e); MFIMFSetSpace(edge,space,e); MFFreeNSpace(space,e); p=(struct MFEdgeIn3SpaceData*)malloc(sizeof(struct MFEdgeIn3SpaceData)); #ifndef MFNOSAFETYNET if(p==NULL) { sprintf(MFEdgeMFErrorHandlerMsg,"Out of memory, trying to allocate %d bytes",sizeof(struct MFEdgeIn3SpaceData)); MFSetError(e,12,RoutineName,MFEdgeMFErrorHandlerMsg,__LINE__,__FILE__); MFErrorHandlerOutOfMemory(e); return NULL; } #endif p->r=R; p->ox=v0[0]; p->oy=v0[1]; p->oz=v0[2]; p->ax=v1[0]-v0[0]; p->ay=v1[1]-v0[1]; p->az=v1[2]-v0[2]; d=1./sqrt(p->ax*p->ax+p->ay*p->ay+p->az*p->az); p->ax=p->ax*d; p->ay=p->ay*d; p->az=p->az*d; #ifdef MFALLOWVERBOSE if(verbose){printf("%s, data=0x%8.8x, o=(%lf,%lf,%lf), n=(%lf,%lf,%lf)\n",RoutineName,p,p->ox,p->oy,p->oz,p->ax,p->ay,p->az);fflush(stdout);} #endif MFIMFSetData(edge,(void*)p,e); MFIMFSetFreeData(edge,MFFreeEdgeIn3SpaceData,e); MFIMFSetProject(edge,MFProjectEdgeIn3Space,e); MFIMFSetProjectForBB(edge,MFEdgeIn3SpaceProjectForBB,e); MFIMFSetProjectForDraw(edge,MFEdgeIn3SpaceProjectForBB,e); MFIMFSetTangent(edge,MFTangentEdgeIn3Space,e); MFIMFSetScale(edge,MFScaleEdgeIn3Space,e); MFIMFSetR(edge,R,e); MFIMFSetWriteData(edge,MFWriteEdgeIn3SpaceData,e); MFIMFSetVectorFactory(edge,MFNVectorFactory,e); MFIMFSetMatrixFactory(edge,MFNKMatrixFactory,e); #ifdef MFALLOWVERBOSE if(verbose){printf("done %s\n",RoutineName);fflush(stdout);} #endif return edge; }