示例#1
0
文件: triangle.c 项目: ybits/rubymesh
Circle*
triangle_circumcircle(Triangle *t)
{
	if (t->circumcircle->radius) {
		Point *center = triangle_circumcenter(t);
		t->circumcircle = circle_new(center, triangle_circumcircle_radius(t, center));
		free(center);
	}
	return t->circumcircle;
}
示例#2
0
void test21011 ( )

/******************************************************************************/
/*
  Purpose:

    TEST21011 tests TRIANGLE_CIRCUMCENTER.

  Licensing:

    This code is distributed under the GNU LGPL license. 

  Modified:

    28 October 2010

  Author:

    John Burkardt
*/
{
# define M1 2
# define TEST_NUM 4

  double *a12;
  int i;
  int j;
  int k;
  int m2;
  double *o1;
  double *o2;
  int m1 = M1;
  double pc1[M1];
  double *pc2;
  int seed;
  double t1[M1*3];
  double *t2;
  double t_test[M1*3*TEST_NUM] = {
         10.0,  5.0, 
         11.0,  5.0, 
         10.0,  6.0, 
         10.0,  5.0, 
         11.0,  5.0, 
         10.5,  5.86602539, 
         10.0,  5.0, 
         11.0,  5.0, 
         10.5, 15.0, 
         10.0,  5.0, 
         11.0,  5.0, 
        20.0,   7.0 };
  int test;
  int test_num = TEST_NUM;

  printf ( "\n" );
  printf ( "TEST21011\n" );
  printf ( "  For a triangle in M dimensions, the circumenter can be computed by:\n" );
  printf ( "  TRIANGLE_CIRCUMCENTER;\n" );
//
//  Vary the dimension.
//
  for ( m2 = 2; m2 <= 5; m2++ )
  {
    seed = 123456789;

    printf ( "\n" );
    printf ( "  M2 = %d\n", m2 );

    t2 = ( double * ) malloc ( m2 * 3 * sizeof ( double ) );
//
//  Randomly choose a mapping P2 = O2 + A12 * ( P1 - O1 )
//
    a12 = r8mat_uniform_01_new ( m2, m1, &seed );
    o1 = r8vec_uniform_01_new ( m1, &seed );
    o2 = r8vec_uniform_01_new ( m2, &seed );
//
//  Map each M1-dimensional triangle into M2 space.
//
    for ( test = 0; test < test_num; test++ )
    {
      for ( j = 0; j < 3; j++ )
      {
        for ( i = 0; i < m1; i++ )
        {
          t1[i+j*m1] = t_test[i+j*m1+test*m1*3];
        }
      }
      for ( j = 0; j < 3; j++ )
      {
        t1[i+j*m1] = t1[i+j*m1] - o1[i];
      }

      for ( j = 0; j < 3; j++ )
      {
        for ( i = 0; i < m2; i++ )
        {
          t2[i+j*m2] = 0.0;
          for ( k = 0; k < m1; k++ )
          {
            t2[i+j*m2] = t2[i+j*m2] + a12[i+k*m2] * t1[k+j*m1];
          }
        }
      }
      for ( j = 0; j < 3; j++ )
      {
        for ( i = 0; i < m2; i++ )
        {
          t2[i+j*m2] = t2[i+j*m2] + o2[i];
        }
      }

      pc2 = triangle_circumcenter ( m2, t2 );

      r8vec_print ( m2, pc2, "  Circumcenter by TRIANGLE_CIRCUMCENTER:" );
      printf ( "\n" );
      printf ( "  Distances from circumcenter to vertices:\n" );
      printf ( "\n" );
      for ( j = 0; j < 3; j++ )
      {
        printf ( "  %f\n", r8vec_norm_affine ( m2, pc2, t2+j*m2 ) );
      }
      free ( pc2 );
    }
    free ( a12 );
    free ( o1 );
    free ( o2 );
    free ( t2 );
  }
  return;
}
示例#3
0
void test2101 ( )

/******************************************************************************/
/*
  Purpose:

    TEST2101 tests TRIANGLE_CIRCUMCENTER_2D and others.

  Discussion:

    The functions tested include
    * TRIANGLE_CIRCUMCENTER_2D;
    * TRIANGLE_CIRCUMCENTER_2D_2;
    * TRIANGLE_CIRCUMCENTER.

  Licensing:

    This code is distributed under the GNU LGPL license. 

  Modified:

    28 October 2010

  Author:

    John Burkardt
*/
{
# define M 2
# define TEST_NUM 4

  int i;
  int j;
  int m = M;
  double *pc;
  double t[M*3];
  double t_test[M*3*TEST_NUM] = {
         10.0,  5.0, 
         11.0,  5.0, 
         10.0,  6.0, 
         10.0,  5.0, 
         11.0,  5.0, 
         10.5,  5.86602539, 
         10.0,  5.0, 
         11.0,  5.0, 
         10.5, 15.0, 
         10.0,  5.0, 
         11.0,  5.0, 
        20.0,   7.0 };
  int test;
  int test_num = TEST_NUM;

  printf ( "\n" );
  printf ( "TEST2101\n" );
  printf ( "  For a triangle in 2D, the circumenter can be computed by:\n" );
  printf ( "  TRIANGLE_CIRCUMCENTER_2D;\n" );
  printf ( "  TRIANGLE_CIRCUMCENTER_2D_2;\n" );
  printf ( "  TRIANGLE_CIRCUMCENTER (any dimension);\n" );

  for ( test = 0; test < test_num; test++ )
  {
    for ( j = 0; j < 3; j++ )
    {
      for ( i = 0; i < m; i++ )
      {
        t[i+j*m] = t_test[i+j*m+test*m*3];
      }
    }
    r8mat_transpose_print ( m, 3, t, "  Triangle vertices:" );

    pc = triangle_circumcenter_2d ( t );
    r8vec_print ( m, pc, "  Circumcenter by TRIANGLE_CIRCUMCENTER_2D:" );
    free ( pc );

    pc = triangle_circumcenter_2d_2 ( t );
    r8vec_print ( m, pc, "  Circumcenter by TRIANGLE_CIRCUMCENTER_2D_2:" );
    free ( pc );

    pc = triangle_circumcenter ( m, t );
    r8vec_print ( m, pc, "  Circumcenter by TRIANGLE_CIRCUMCENTER:" );
    free ( pc );
  }
  return;
# undef M
# undef TEST_NUM
}