Esempio n. 1
0
void Confo_Back::Construct_Mol_II(XYZ pre,XYZ cur,XYZ nxt,double bend,double tort,double dist,XYZ &out)
{
	XYZ xyz;
	double x[3],y[3];
	double z[3];
	double cb1[3],cb2[3];
	xyz=nxt-cur;
	xyz.xyz2double(x);
	xyz=cur-pre;
	xyz.xyz2double(y);
	//check
	double angle=Vector_Angle(x,y,3);
	if(fabs(angle)<1.e-3||fabs(angle-M_PI)<1.e-3)
	{
		x[0]+=0.05;
		x[2]-=0.05;
		y[0]-=0.05;
		y[2]+=0.05;
	}
	//calc
	cross(z,x,y);
	Universal_Rotation(z,bend,Confo_Back_ROT_TOT);
	Vector_Multiply(cb1,Confo_Back_ROT_TOT,x);
	Universal_Rotation(x,tort,Confo_Back_ROT_TOT);
	Vector_Multiply(cb2,Confo_Back_ROT_TOT,cb1);
	Vector_Normalize(cb2,3);
	Vector_Dot(cb2,dist,cb2,3);
	out.double2xyz(cb2);
	out+=nxt;
}
Esempio n. 2
0
void Confo_Back::Construct_CB(XYZ N,XYZ Ca,XYZ C,double bend,double tort,double dist,XYZ &Cb)
{
	XYZ xyz;
	double x[3],y[3];
	double z[3];
	double cb1[3],cb2[3];
	xyz=C-Ca;
	xyz.xyz2double(x);
	xyz=Ca-N;
	xyz.xyz2double(y);
	cross(z,x,y);
	Universal_Rotation(z,-1.0*bend,Confo_Back_ROT_TOT);
	Vector_Multiply(cb1,Confo_Back_ROT_TOT,x);
	Universal_Rotation(x,-1.0*tort,Confo_Back_ROT_TOT);
	Vector_Multiply(cb2,Confo_Back_ROT_TOT,cb1);
	Vector_Normalize(cb2,3);
	Vector_Dot(cb2,dist,cb2,3);
	Cb.double2xyz(cb2);
	Cb+=Ca;
}
Esempio n. 3
0
//===================== Recon_Beta ==================//
//given CA+CB, and AMI_Dist, update SC
void Confo_Beta::Recon_Beta_1(XYZ *CA,XYZ *CB,int moln,char *ami)  //return SC
{
	int i;
	XYZ xyz;
	double radii;
	double multi;
	double v[3];
	for(i=0;i<moln;i++)
	{
		xyz=(CB[i]-CA[i]);
		xyz.xyz2double(v);
		radii=dot(v,v);
		if(radii<1.e-3)continue;
		Vector_Normalize(v,3);
		multi=CB_AMI_Dist[ami[i]-'A'];
		if(multi<0.0)continue;
		Vector_Dot(v,multi,v,3);
		xyz.double2xyz(v);
		CB[i]=CA[i]+xyz;
	}
}
Esempio n. 4
0
//input Confo_Angle (*dist,*bend,*tort), output XYZ_Type data_structure (*r)
//dist[0]    : -1.0;
//dist[1]-[n]: normal
//bend[0]-[1]: -9.9
//bend[2]-[n]: normal
//tort[0]-[2]: -9.9
//tort[3]-[n]: normal
void Confo_Lett::ctc_ori(double *dist,double *bend,double *tort,int n,XYZ *r,XYZ *init)
{
	int i;
	double radi;
	XYZ xyz;
	xyz=0.0;
	XYZ ori[3],pos[3];	

	//real_process//
	Matrix_Unit(cle_T_Back,1.0);
	for(i=0;i<n;i++)
	{
		if(dist==NULL)radi=3.8;
		else radi=dist[i];

		if(i==0)r[i]=0.0;
		else if(i==1)
		{
			r[i]=0.0;
			r[i].X=radi;
		}
		else if(i==2)
		{
			Universal_Rotation(cle_Z_Axis,bend[i],cle_R_Theta);
			Vector_Dot(cle_D_Back,radi,cle_X_Axis,3);
			Matrix_Multiply(cle_T_Pre,cle_T_Back,cle_R_Theta);
			Vector_Multiply(cle_D_Pre,cle_T_Pre,cle_D_Back);
			Matrix_Equal(cle_T_Back,cle_T_Pre);
			xyz.double2xyz(cle_D_Pre);
			r[i]=r[i-1]+xyz;
		}
		else
		{
			Universal_Rotation(cle_Z_Axis,bend[i],cle_R_Theta);
			Universal_Rotation(cle_X_Axis,tort[i],cle_R_Thor);
			Vector_Dot(cle_D_Back,radi,cle_X_Axis,3);
			Matrix_Multiply(cle_temp,cle_R_Thor,cle_R_Theta);
			Matrix_Multiply(cle_T_Pre,cle_T_Back,cle_temp);
			Vector_Multiply(cle_D_Pre,cle_T_Pre,cle_D_Back);
			Matrix_Equal(cle_T_Back,cle_T_Pre);
			xyz.double2xyz(cle_D_Pre);
			r[i]=r[i-1]+xyz;
		}
	}

	//whether do ini_vector
	if(init!=NULL && n>=3)
	{
		for(i=0;i<3;i++)
		{
			ori[i]=init[i];
			pos[i]=r[i];
		}
		Get_Initial(ori,pos,cle_r1,cle_r2);
		Matrix_Multiply(cle_T_Pre,cle_r2,cle_r1);
		for(i=0;i<n;i++)
		{
			r[i].xyz2double(cle_D_Back);			
			Vector_Multiply(cle_D_Pre,cle_T_Pre,cle_D_Back);
			xyz.double2xyz(cle_D_Pre);
			r[i]=ori[0]+xyz;
		}
	}
}
Esempio n. 5
0
//---------------------------------------------------------------------------//
// CalculaTangentes
//
//---------------------------------------------------------------------------//
void CObjeto3D::CalculaTangentes()
{
    TVector3 *pTan1 = NEW_ARRAY(TVector3, m_uNumVertices);
    //TVector3 *pTan2 = pTan1 + m_uNumVertices;
    memset(pTan1, 0, m_uNumVertices * sizeof(TVector3));

    for (int i = 0; i < m_uNumFaces; i++)
    {
        int i1 = m_pFaces[i].i0;
        int i2 = m_pFaces[i].i1;
        int i3 = m_pFaces[i].i2;

        const TVector3 &v1 = m_pVertices[i1];
        const TVector3 &v2 = m_pVertices[i2];
        const TVector3 &v3 = m_pVertices[i3];

        const TVector2 &w1 = m_pCacheUV[i*3+0];
        const TVector2 &w2 = m_pCacheUV[i*3+1];
        const TVector2 &w3 = m_pCacheUV[i*3+2];

        float x1 = v2.x - v1.x;
        float x2 = v3.x - v1.x;
        float y1 = v2.y - v1.y;
        float y2 = v3.y - v1.y;
        float z1 = v2.z - v1.z;
        float z2 = v3.z - v1.z;

        float s1 = w2.x - w1.x;
        float s2 = w3.x - w1.x;
        float t1 = w2.y - w1.y;
        float t2 = w3.y - w1.y;

        float r = 1.0f / (s1 * t2 - s2 * t1);
        TVector3 sdir((t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r, (t2 * z1 - t1 * z2) * r);
        //TVector3 tdir((s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r, (s1 * z2 - s2 * z1) * r);

        pTan1[i1].x += sdir.x;
        pTan1[i1].y += sdir.y;
        pTan1[i1].z += sdir.z;
        pTan1[i2].x += sdir.x;
        pTan1[i2].y += sdir.y;
        pTan1[i2].z += sdir.z;
        pTan1[i3].x += sdir.x;
        pTan1[i3].y += sdir.y;
        pTan1[i3].z += sdir.z;
        /*
        pTan2[i1].x += tdir.x; pTan2[i1].y += tdir.y; pTan2[i1].z += tdir.z;
        pTan2[i2].x += tdir.x; pTan2[i2].y += tdir.y; pTan2[i2].z += tdir.z;
        pTan2[i3].x += tdir.x; pTan2[i3].y += tdir.y; pTan2[i3].z += tdir.z;
        */
    }

    for (int i = 0; i < m_uNumVertices; i++)
    {
        TVector3 n = m_pVNormales[i];
        TVector3 t = pTan1[i];

        TVector3 r;
        float fDot = Vector_Dot(&n, &t);
        r.x = t.x - n.x * fDot;
        r.y = t.y - n.y * fDot;
        r.z = t.z - n.z * fDot;
        Vector_Unit (&m_pTangentes[i], &r);
        Vector_Cross(&m_pBinormales[i], &n, &m_pTangentes[i]);
    }

    DISPOSE_ARRAY(pTan1);
}
Esempio n. 6
0
Bool pointInElement( void* _context, Coord point, Element_DomainIndex dElementInd ) {
	Snac_Context*		context = (Snac_Context*)_context;
	Mesh*			mesh = context->mesh;
	NodeLayout*		nLayout = mesh->layout->nodeLayout;
	unsigned		nEltNodes;
	Node_DomainIndex*	eltNodes;
	Coord			crds[8];
	double			bc[4];
	unsigned		inds[4];
	unsigned		eltNode_i;

	/* Extract the element's nodes, of which there should be eight. */
	{
		Element_GlobalIndex	gEltInd;
		
		nEltNodes = 8;
		eltNodes = Memory_Alloc_Array( Node_DomainIndex, nEltNodes, "SnacRemesher" );
		gEltInd = Mesh_ElementMapDomainToGlobal( mesh, dElementInd );
		nLayout->buildElementNodes( nLayout, gEltInd, eltNodes );
	}
	
	/* Convert the node indices back to domain values. */
	for( eltNode_i = 0; eltNode_i < nEltNodes; eltNode_i++ ) {
		eltNodes[eltNode_i] = Mesh_NodeMapGlobalToDomain( mesh, eltNodes[eltNode_i] );
	}

	/* Copy coordinates. */
	for( eltNode_i = 0; eltNode_i < nEltNodes; eltNode_i++ )
		memcpy( crds[eltNode_i], mesh->nodeCoord[eltNodes[eltNode_i]], sizeof(Coord) );

	if( _HexaEL_FindTetBarycenter( crds, point, bc, inds, INCLUSIVE_UPPER_BOUNDARY, NULL, 0 ) ) {
		return True;
	}

	return False;

#if 0

	unsigned				plane_i;

	
	const unsigned			planeInds[6][3] = { { 0, 4, 1 }, { 3, 2, 7 }, { 0, 3, 4 }, 
										{ 1, 5, 2 }, { 0, 1, 3 }, { 5, 4, 6 } };
	
	/* As we are dealing with hexahedral meshes with Snac, there will be six planes to check. */
	for( plane_i = 0; plane_i < 6; plane_i++ ) {
		Coord	norm;
		double	dist;
		
		/* Build the plane normal. */
		{
			Node_DomainIndex	inds[3];
			Coord			tmpA, tmpB;
			
			inds[0] = eltNodes[planeInds[plane_i][0]];
			inds[1] = eltNodes[planeInds[plane_i][1]];
			inds[2] = eltNodes[planeInds[plane_i][2]];
			
			Vector_Sub( tmpA, mesh->nodeCoord[inds[1]], mesh->nodeCoord[inds[0]] );
			Vector_Sub( tmpB, mesh->nodeCoord[inds[2]], mesh->nodeCoord[inds[0]] );
			Vector_Cross( norm, tmpA, tmpB );
			Vector_Norm( norm, norm );
		}
		
		/* Calc distance. */
		dist = Vector_Dot( norm, mesh->nodeCoord[planeInds[plane_i][0]] );
		
		/* Check which side of the plane our new point is. */
		if( Vector_Dot( norm, point ) <= dist ) {
			/* It is inside, so we may continue. */
			continue;
		}
		else {
			/* It's outside, so this is the wrong element. */
			break;
		}
	}
	
	/* Free the element nodes array. */
	FreeArray( eltNodes );
	
	/* Return appropriately. */
	
	return (plane_i < 6) ? False : True;
#endif
}