~hrg/hrg-packaging/zeo

« back to all changes in this revision

Viewing changes to example/bv/bball_test.c

  • Committer: Yosuke Matsusaka
  • Date: 2016-01-12 04:55:51 UTC
  • Revision ID: yosuke.matsusaka@gmail.com-20160112045551-9xbrsuokuwqdfnc9
initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <zeo/zeo.h>
 
2
 
 
3
#define N 2000
 
4
zVec3D v[N];
 
5
 
 
6
void veclist_create_rand(void)
 
7
{
 
8
  register int i;
 
9
 
 
10
  for( i=0; i<N; i++ ){
 
11
    zVec3DCreatePolar( &v[i], zRandF(-5,5), zRandF(-zPI,zPI), zRandF(-0.5*zPI,0.5*zPI) );
 
12
    zVec3DDataNLWrite( &v[i] );
 
13
  }
 
14
}
 
15
 
 
16
void verify(zSphere3D *bb, int n, zVec3D *vp[])
 
17
{
 
18
  register int i;
 
19
  double r1, r;
 
20
  int count;
 
21
 
 
22
  zSphere3DFWrite( stderr, bb );
 
23
  eprintf( "++verify+++\n" );
 
24
  r = zSphere3DRadius(bb);
 
25
  for( count=0, i=0; i<N; i++ ){
 
26
    r1 = zVec3DDist(zSphere3DCenter(bb),&v[i]);
 
27
    if( r1 > r ) ZRUNWARN( "%f > %f, impossible error, must be a bug", r1, r );
 
28
    if( zIsTol( r1-r, zTOL*2 ) ) count++;
 
29
  }
 
30
  eprintf( "rim points: %d\n", count );
 
31
  if( count <= 1 ) ZRUNWARN( "impossible error, must be a bug" );
 
32
 
 
33
  eprintf( "points on the sphere: %d\n", n );
 
34
  for( i=0; i<n; i++ ){
 
35
    r1 = zVec3DDist(zSphere3DCenter(bb),vp[i]);
 
36
    eprintf( "r = %.10f\n", r1 );
 
37
    if( !zIsTol( r1-r, zTOL*2 ) )
 
38
      ZRUNWARN( "%f VS %f, impossible error, must be a bug", r1, r );
 
39
  }
 
40
}
 
41
 
 
42
int main(void)
 
43
{
 
44
  zSphere3D bb;
 
45
  zVec3D *vp[4]; /* vertices on the sphere up to four. */
 
46
  int n;
 
47
 
 
48
  zRandInit();
 
49
  veclist_create_rand();
 
50
  n = zBBall( &bb, v, N, vp );
 
51
  verify( &bb, n, vp );
 
52
  return 0;
 
53
}