Exemple #1
0
Fichier : pf.c Projet : jxv/pf
PfTri _pf_tri(v2f radii, bool line, PfCorner hypotenuse) {
    const float radians = tri_angle(&radii, hypotenuse);
    return (PfTri) {
        .radii = radii,
        .line = line,
        .hypotenuse = hypotenuse,
        .radians = radians,
        .m = pf_tri_slope(&radii, hypotenuse),
        .proj = projection_vector(radians),
        .normal = tri_normal(&radii, hypotenuse),
        .sin = sinf(radians),
        .cos = cosf(radians),
    };
}

PfGroup _pf_platform() {
    return (PfGroup) {
        .tag = PF_GROUP_PLATFORM,
        .platform = (PfPlatform) {
            .allow = 0,
            .convey = _v2f(0,0),
            .left = NULL,
            .right = NULL,
        },
    };
}

PfBody _pf_body() {
    return (PfBody) {
        .mode = PF_MODE_DYNAMIC,
        .shape = (PfShape) {
                .tag = PF_SHAPE_CIRCLE,
                .radius = 0
            },
        .pos = _v2f(0,0),
        .group.object.parent = NULL,
        .group.object.check_parent = false,
        .dpos = _v2f(0,0),
        .in = { 
            .impulse = fillv2f(0),
            .decay = fillv2f(0.5),
            .cap = fillv2f(1000),
        },
        .ex = {
            .impulse = fillv2f(0),
            .decay = fillv2f(0.3),
            .cap = fillv2f(1000),
        },
        .gravity = {
void generate_basis()
{
	int i=0;int j=0;int k=0;int l=0; double norm=0; double u1,u2; int temp_int;
	double standard_basis[DIM][DIM]; double temp_basis[DIM][DIM];double temp_vector[DIM];double coefficients[DIM];

     double *temp_;

	 srand((unsigned int)time(NULL));
	 temp_=(double *) malloc(sizeof(double)*DIM);
	for(i=0;i<DIM;i++)
	{
	  coefficients[i]=(double)rand()/(M_PI *100);
	  temp_vector[i]=0;
	  temp_[i]=0;
	}

	for(i=0;i<DIM;i++)
	{
	   for(j=0;j<DIM;j++)
	   {
	      if(i==j)
		  {
		    standard_basis[i][j]=1;
			temp_basis[i][j]=0;
		  }
		  else
		  {
		    standard_basis[i][j]=0;
			temp_basis[i][j]=0;
		  }


	   }


	}

	if(DIM==2)
	{
	u1= (double)rand()/(M_PI *100);
	temp_int=u1;
	u1=u1-temp_int;
	basis[0][0]=u1;
	u2=1-u1*u1;
	u2=sqrtf(u2);
	basis[0][1]=u2;


	basis[1][0]=-u2;

	basis[1][1]=u1;


	}
	else{
	for(i=0;i<DIM;i++)
	{
		for(k=0;k<DIM;k++)
		{

			for(j=0;j<DIM;j++)
			{
				if(i==j)
				{
					continue;
				}
				else
				{
					temp_vector[k]= temp_vector[k]+standard_basis[j][k]*coefficients[j];

				}


			}
		}



		for(l=0;l<DIM;l++)
		{
			temp_basis[i][l]=temp_vector[l];
			temp_vector[l]=0;
		}


	}

	for(k=0;k<DIM;k++)
	basis[0][k]=temp_basis[0][k];

	for(k=1;k<DIM;k++)
	{
	  for(j=0;j<k;j++)
	  {
	    temp_=sum_of_vectors(temp_, projection_vector(basis[j],temp_basis[k]));
	  }


	  for(i=0;i<DIM;i++)
	  {
	   basis[k][i]=temp_basis[k][i]-temp_[i] ;

	  }

	  for(l=0;l<DIM;l++)
		  temp_[l]=0;

	}


	for(i=0;i<DIM;i++)
	{
		coefficients[i]=0;
	  for(j=0;j<DIM;j++)
	  {
	     coefficients[i]=coefficients[i]+ basis[i][j] * basis[i][j];

	  }
	    coefficients[i] =sqrtf(coefficients[i]);
	}

	for(i=0;i<DIM;i++)
	{
	  for(j=0;j<DIM;j++)
	  {
	    basis[i][j] = basis[i][j]/coefficients[i];
	  }
	}

	}


	  printf("\nORTHONORMAL BASIS: \n");

	for(i=0;i<DIM;i++)
	{
	  for(j=0;j<DIM;j++)
	  {
	    printf("%.4f ",basis[i][j]);

	  }
	  printf("\n");
	}
	  printf("\n");

}