Пример #1
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
}
Пример #2
0
void test06 ( )

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

    TEST06 tests TRIANGLE_CIRCUMCENTER_2D;

  Licensing:

    This code is distributed under the GNU LGPL license.

  Modified:

    23 October 2012

  Author:

    John Burkardt
*/
{
# define DIM_NUM 2

  double *center;
  int i;
  int ntest = 4;
  double t[DIM_NUM*3];

  printf ( "\n" );
  printf ( "TEST06\n" );
  printf ( "  For a triangle in 2D:\n" );
  printf ( "  TRIANGLE_CIRCUMCENTER_2D computes the circumcenter.\n" );

  for ( i = 1; i <= ntest; i++ )
  {
    if ( i == 1 )
    {
      t[0+0*2] = 0.0;
      t[1+0*2] = 0.0;
      t[0+1*2] = 1.0;
      t[1+1*2] = 0.0;
      t[0+2*2] = 0.0;
      t[1+2*2] = 1.0;
    }
    else if ( i == 2 )
    {
      t[0+0*2] = 0.0;
      t[1+0*2] = 0.0;
      t[0+1*2] = 1.0;
      t[1+1*2] = 0.0;
      t[0+2*2] = 0.5;
      t[1+2*2] = sqrt ( 3.0 ) / 2.0;
    }
    else if ( i == 3 )
    {
      t[0+0*2] = 0.0;
      t[1+0*2] = 0.0;
      t[0+1*2] = 1.0;
      t[1+1*2] = 0.0;
      t[0+2*2] = 0.5;
      t[1+2*2] = 10.0;
    }
    else if ( i == 4 )
    {
      t[0+0*2] = 0.0;
      t[1+0*2] = 0.0;
      t[0+1*2] = 1.0;
      t[1+1*2] = 0.0;
      t[0+2*2] = 10.0;
      t[1+2*2] = 2.0;
    }

    r8mat_transpose_print ( DIM_NUM, 3, t, "  The triangle" );

    center = triangle_circumcenter_2d ( t );

    r8vec_print ( DIM_NUM, center, "  Circumcenter" );

    free ( center );
  }

  return;
# undef DIM_NUM
}