-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgenerate_sphere.c
71 lines (67 loc) · 1.58 KB
/
generate_sphere.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include"utils.h"
void generate_sphere(int nrows,int *tlist,double *vlist)
{
/*
* divides a unit sphere into triangles
* vlist is (4*nrows^2+2)x3 matrix
* tlist is 8*nrows^2 x 3 matrix
*/
double x,y,z;
double *t,*f;
t=calloc(4*pow(nrows,2)+2,sizeof(double));
f=calloc(4*pow(nrows,2)+2,sizeof(double));
triangulate_sphere(nrows,t,f,tlist);
for(int j=0;j<4*pow(nrows,2)+2;j++)
{
x=sin(t[j])*cos(f[j]);
y=sin(t[j])*sin(f[j]);
z=cos(t[j]);
vlist[3*j]=x;
vlist[3*j+1]=y;
vlist[3*j+2]=z;
}
free(t);
free(f);
}
void generate_ellipsoid(int nrows,double a,double b,double c,int *tlist,double *vlist)
{
/*
* divides a unit sphere into triangles
* vlist is (4*nrows^2+2)x3 matrix
* tlist is 8*nrows^2 x 3 matrix
*/
int *ifp;
double x,y,z;
double *t,*f;
t=calloc(4*pow(nrows,2)+2,sizeof(double));
f=calloc(4*pow(nrows,2)+2,sizeof(double));
triangulate_sphere(nrows,t,f,tlist);
for(int j=0;j<4*pow(nrows,2)+2;j++)
{
x=sin(t[j])*cos(f[j]);
y=sin(t[j])*sin(f[j]);
z=cos(t[j]);
vlist[3*j]=a*x;
vlist[3*j+1]=b*y;
vlist[3*j+2]=c*z;
}
free(t);
free(f);
}
/*
void main()
{
int *tlist;
int nrows=4;
double *vlist;
int nfac=8*pow(nrows,2);
int nvert=4*pow(nrows,2)+2;
tlist=calloc(3*nfac,sizeof(int));
vlist=calloc(4*nvert,sizeof(double));
generate_ellipsoid(nrows,3,2,1,tlist,vlist);
write_shape_file("/tmp/shape.txt",tlist,vlist,nfac,nvert);
}
*/