Exemplo n.º 1
0
void
rose(vec1 r,int levels,int points)
{
	int	i, j, m, n;
	vec1	r1, theta, thinc;
	vec2	inner[100];
	vec2	outer[100];
	vec2	triangle[3];

	m = levels;
	n = points;
	thinc = 2*pi/n;

	/* initial inner circle*/
	for(i=0; i<n; ++i) {
		inner[i].x = 0.0;
		inner[i].y = 0.0;
	}

	/* loop thru m levels*/
	for(j=1; j<=m; ++j) {
		theta = -j*pi/n;
		r1 = r * (vec1)j/m;

		/* calc n points on outer circle*/
		for(i=0; i<n; ++i) {
			theta += thinc;
			outer[i].x = r1*cos(theta);
			outer[i].y = r1*sin(theta);
		}

		/* construct/draw triangles with vertices on
		 * inner and outer circles
		 */
		for(i=0; i<n; ++i) {
			triangle[0] = outer[i];
			triangle[1] = outer[(i+1) % n];
			triangle[2] = inner[i];

			/* fill triangle in red*/
			setcolor3(RED);
			polyfill(3, triangle);

#if 1
			/* outline triangle in white*/
			setcolor3(WHITE);
			moveto3(triangle[0]);
			lineto3(triangle[1]);
			lineto3(triangle[2]);
			lineto3(triangle[0]);
#endif
		}

		/* copy points on outer circle to inner arrays*/
		for(i=0; i<n; ++i)
			inner[i] = outer[i];
	}
}
Exemplo n.º 2
0
/* draw a triangle with cordners v0, v1, v2*/
void
triangle(vec2 v0, vec2 v1, vec2 v2)
{
	vec2	poly[3];

	poly[0] = v0;
	poly[1] = v1;
	poly[2] = v2;

	setcolor3(GREEN);
	polyfill(3, poly);
	setcolor3(BLACK);
	moveto3(poly[2]);
	lineto3(poly[0]);
	lineto3(poly[1]);
	lineto3(poly[2]);
}
Exemplo n.º 3
0
/* draw a quadrilateral with corners v0, v1, v2, v3*/
void
quadrilateral(vec2 v0, vec2 v1, vec2 v2, vec2 v3)
{
	vec2	poly[4];

	poly[0] = v0;
	poly[1] = v1;
	poly[2] = v2;
	poly[3] = v3;
	setcolor3(GREEN);
	polyfill(4, poly);
	setcolor3(BLACK);
	moveto3(poly[3]);
	lineto3(poly[0]);
	lineto3(poly[1]);
	lineto3(poly[2]);
	lineto3(poly[3]);
}
Exemplo n.º 4
0
Arquivo: nterm.c Projeto: rforge/muste
static int linear_regression(int m, int n) {
  double *Y, *X, *S, *U, *T, *B, *R;
  double *oma;
  int real_m; // ,real_n;
  int i,j,k,a;
  int tulos;
  double tulosterm;
  int tulosl;
// RS REM  struct murtoluku tulosml;

  oma=regressor[0];
  if (n>=m) n=m-1;
  nterm_type=UNIDENTIFIED;
  strcpy(nterm_output_buffer,comment_1);


  Y=matrixmalloc(m,1);
  if (Y==NULL) return(-1);
  for (i=0;i<m;i++) {
    *(Y+i)=sequence[i];
  }

  X=matrixmalloc(m,n);
  if (X==NULL) return(-1);
  S=matrixmalloc(m,n);
  if (S==NULL) return(-1);
  U=matrixmalloc(n,n);
  if (U==NULL) return(-1);  
  T=matrixmalloc(m,n);
  if (T==NULL) return(-1);  
  B=matrixmalloc(m,1);
  if (B==NULL) return(-1);
  R=matrixmalloc(m,1);
  if (R==NULL) return(-1);

  m-=1;n-=1;
  i=0;
  tulos=FALSE;




  k=0;
  polyfill(X,m,n,k);
  tulos=linreg(X,Y,S,U,T,B,R,m,n);
  if (tulos<0) return(-1);

  if (!tulos) {

    j=k;
    k++;

    do {
      j++;

      oma=regressor[j-1];
      for (i=0;i<m;i++) {
        *(X+i)=*(oma+i);
      }
      muutnim=data.v[j-1];

      polyfill(X,m,n,k);

/*
    showmatrix(X,m,n);
*/

      tulos=linreg(X,Y,S,U,T,B,R,m,n);
      if (tulos<0) return(-1);

    } while (tulos!=TRUE && j<data.m_act);
  }

/*
 showmatrix(B,m,1);
*/

  if (tulos) {

    if (k>0) *(X+0)=*(oma+m);

    polyrow(X,1,n,0,k,m+1);

/*
 showmatrix(X,1,n);
*/
    if ( pow( *(Y+m)-solve_term(X,B,1,n,0) ,2) < MINTOLERANCE ) {

      if (k>0) *(X+0)=*(oma+m+1);
      polyrow(X,1,n,0,k,m+2);
      tulosterm=solve_term(X,B,1,n,0);

      tulosl=(int)floor(tulosterm);
      if (fabs(tulosterm-tulosl)>.5) tulosl=(int)ceil(tulosterm);

      muste_ltoa(tulosl,nterm_output_buffer,10);
      nterm_type=POLYNOMIAL;



      construct_formula(B,k,n);


    }
  }
  else {

    real_m=m; // real_n=n;

  for (n=1;n<(real_m-n-1);n++) {

    a=n+1;
    m=real_m-n;

    for (i=0;i<m+1;i++) {
      *(Y+i)=sequence[i+n];
    }

/*
    showmatrix(Y,m,1);
*/


    for (i=0;i<m;i++) *(X+i)=1;

    for (j=1;j<=n;j++) {
      for (i=0;i<m;i++) {
        *(X+i+m*j)=sequence[n-j+i];
      }
    }

/*
    showmatrix(X,m,a);
*/

    tulos=linreg(X,Y,S,U,T,B,R,m,a);
    if (tulos<0) return(-1);

/*
    showmatrix(B,a,1);
*/

    if (tulos) {
      tulosterm=*(B+0);
      for (k=0;k<n;k++) {
        tulosterm+=(*(Y+m-1-k))*(*(B+1+k));
      }
/*
printf("\ntark:%f\n",pow(tulosterm-*(Y+m+1),2));WAIT;
*/

      if (pow(tulosterm-*(Y+m+1),2) < MINTOLERANCE) {
        tulosterm=*(B+0);
        for (k=0;k<n;k++) {
         tulosterm+=(*(Y+m-k))*(*(B+1+k));
        }
        tulosl=(int)floor(tulosterm);
        if (fabs(tulosterm-tulosl)>.5) tulosl=(int)ceil(tulosterm);

        muste_ltoa(tulosl,nterm_output_buffer,10);

        nterm_type=FIBONACCI;

        construct_formula(B,0,n);
        break;
      }
    }
  }

}
return(1);
}