First attempt to calculate points of cross-section
4 files added
1 files modified
New file |
| | |
| | | #include<general.h> |
| | | |
| | | |
| | | |
| | | ts_coord_list *init_coord_list(){ |
| | | ts_coord_list *coordlist=(ts_coord_list *)calloc(1,sizeof(ts_coord_list)); |
| | | if(coordlist==NULL){ |
| | | fatal("Cannot allocate memory for coordlist",999); |
| | | } |
| | | return coordlist; |
| | | } |
| | | |
| | | ts_coord_list add_coord(ts_coord_list *coordlist, ts_double e1, ts_double e2, ts_double e3, ts_uint coord_type){ |
| | | |
| | | coordlist->N++; |
| | | coordlist->coord=(ts_coord *)realloc(coordlist->coord,N*sizeof(ts_coord)); |
| | | |
| | | if(coordlist->coord==NULL){ |
| | | fatal("Cannot allocate memory for coord in coordlist",998); |
| | | } |
| | | |
| | | coordlist->coord[coordlist->N-1]->e1=e1; |
| | | coordlist->coord[coordlist->N-1]->e2=e2; |
| | | coordlist->coord[coordlist->N-1]->e3=e3; |
| | | coordlist->coord[coordlist->N-1]->coord_type=coord_type; |
| | | |
| | | } |
| | | |
| | | ts_bool coord_list_free(ts_coord_list coordlist){ |
| | | ts_uint i; |
| | | if(coordlist==NULL) return TS_SUCCESS; |
| | | for(i=0; i<coordlist->N;i++){ |
| | | if(coordlist->coord[N]!=NULL) free(coordlist->coord[N]); |
| | | } |
| | | |
| | | free(coordlist); |
| | | return TS_SUCCESS; |
| | | |
| | | |
| | | } |
New file |
| | |
| | | #ifndef _H_COORD |
| | | #define _H_COORD |
| | | ts_coord_list *init_coord_list(); |
| | | ts_coord_list add_coord(ts_coord_list *coordlist, ts_double e1, ts_double e2, ts_double e3, ts_uint coord_type); |
| | | ts_bool coord_list_free(ts_coord_list coordlist); |
| | | #endif |
New file |
| | |
| | | #include<general.h> |
| | | #include<cross-section.h> |
| | | #include<coord.h> |
| | | |
| | | /** @brief Calculates cross-section of vesicle with plane. |
| | | * |
| | | * Function returns points of cross-section of vesicle with plane. Plane is described with equation $ax+by+cz+d=0$. Algorithm extracts coordinates of each vertex of a vesicle and then: |
| | | * |
| | | * if a distance of point to plane (given by equation $D=\frac{ax_0+by_0+cz_0+d}{\sqrt{a^2+b^2+c^2}}$, where $x_0$, $y_0$ and $z_0$ are coordinates of a given vertex) is less than maximal allowed distance between vertices {\tt sqrt(vesicle->dmax)} than vertex is a candidate for crossection calculation. |
| | | * |
| | | */ |
| | | ts_coord_list get_crossection_with_plane(ts_vesicle vesicle,ts_double a,ts_double b,ts_double c, ts_double d){ |
| | | |
| | | |
| | | ts_uint i, j, k; |
| | | ts_double pp,Dsq; // distance from the plane squared |
| | | ts_double ppn,Dsqn; // distance from the plane squared of a neighbor |
| | | ts_double u; //factor to scale vector from first vector to the second to get intersection |
| | | ts_vertex *vtx; |
| | | |
| | | ts_coord_list *pts=init_coord_list(); |
| | | for(i=0;i<vesicle->vlist->N;i++){ |
| | | vtx=vesicle->vlist->vtx[i]; |
| | | |
| | | pp=vtx->x*a+vtx->y*b+vtx->z*c+d; |
| | | Dsq=pp*pp/(a*a+b*b+c*c); |
| | | if(Dsq<vesicle->dmax){ |
| | | for(j=0;j<vtx->neigh_no;j++){ |
| | | ppn=vtx->neigh[j]->x*a+vtx->neigh[j]->y*b+vtx->neigh[j]->z*c+d; |
| | | if(pp*ppn<0){ //the combination of vertices are good candidates for a crossection |
| | | u=pp/(a*(vtx->x-vtx->neigh[j]->x)+b*(vtx->y-vtx->neigh[j]->y)+c(vtx->z-vtx->neigh[j]->z)); |
| | | add_coord(pts, vtx->x+u(vtx->neigh[j]->x - vtx->x), |
| | | vtx->y+u(vtx->neigh[j]->y - vtx->y), |
| | | vtx->z+u(vtx->neigh[j]->z - vtx->z), |
| | | TS_COORD_CARTESIAN); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return pts; |
| | | } |
| | | |
| | | |
New file |
| | |
| | | #ifndef _H_CROSS_SECTION |
| | | #define _H_CROSS_SECTION |
| | | |
| | | #endif |
| | | |
| | |
| | | ts_uint coord_type; |
| | | } ts_coord; |
| | | |
| | | |
| | | typedef struct { |
| | | ts_double N; |
| | | ts_coord *coord; |
| | | } ts_coord_list; |
| | | |
| | | /** @brief Data structure of all data connected to a vertex |
| | | * |
| | | * ts_vertex holds the data for one single point (bead, vertex). To understand how to use it |