| 1 |
#include <stdio.h> |
| 2 |
#include <stdlib.h> |
| 3 |
#include <math.h> |
| 4 |
|
| 5 |
#define pi 3.1415927 |
| 6 |
#define ROOT2 1.4142136 |
| 7 |
|
| 8 |
#include "modeler.h" |
| 9 |
#include "modeler_proto.h" |
| 10 |
|
| 11 |
#ifdef STANDALONE |
| 12 |
int verbose=3; |
| 13 |
header(int verts, FILE *ofp) |
| 14 |
{ |
| 15 |
fprintf(ofp,"AC3Db\nMATERIAL \"ac3dmat1\" rgb 0.5 1 0.2 amb 0.5 1.0 0.2 emis 0 0 0 spec 0 0 0 shi 10 trans 0\nOBJECT world\n"); |
| 16 |
fprintf(ofp,"kids 1\nOBJECT poly\nname \"ellipse\"\nloc 0 0 0\ncrease 45.000000\nnumvert %d\n", verts); |
| 17 |
} |
| 18 |
|
| 19 |
footer(int surfs, FILE *ofp) |
| 20 |
{ |
| 21 |
int i; |
| 22 |
fprintf(ofp,"numsurf 1\nSURF 0x30\nmat 0\nrefs %d\n", surfs); |
| 23 |
for (i = surfs-1; i>=0;i--) |
| 24 |
{ |
| 25 |
fprintf(ofp,"%d 0 0\n", i); |
| 26 |
} |
| 27 |
fprintf(ofp,"kids 0\n"); |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
int main(int argc, char *argv[]) |
| 32 |
{ |
| 33 |
double S; |
| 34 |
int points=40; |
| 35 |
|
| 36 |
if (argc < 2) return 1; |
| 37 |
S=strtod(argv[1], NULL); |
| 38 |
|
| 39 |
header(points, stdout); |
| 40 |
// if(S < pi) return 1; |
| 41 |
GetRib(S, 0., 1., 1., 0, 0, 0, points, stdout); |
| 42 |
footer(points, stdout); |
| 43 |
exit(EXIT_SUCCESS); |
| 44 |
} |
| 45 |
#else |
| 46 |
extern int verbose; |
| 47 |
#endif |
| 48 |
/* S=Area, Perimeter, Y_Radius, Z_Radius, X_Center, Y_Center, Z_Center, Number of Points, File Pointer */ |
| 49 |
RIB3D *GetRib(double S, double P, double YR, double ZR, double XC, double YC, double ZC, int points, FILE *ofp) |
| 50 |
{ |
| 51 |
double d,f=1.0,theta=0.0,step,s_norm, area; |
| 52 |
int i; |
| 53 |
|
| 54 |
step = (pi/4.0)/(points/8); |
| 55 |
area = (YR*ZR); |
| 56 |
if (area) s_norm = S / area; |
| 57 |
else s_norm = 0.; |
| 58 |
|
| 59 |
if (s_norm > 4.0) |
| 60 |
if(verbose > 0) fprintf(stderr,"Detected area (S) greater than physically possible. Station = %0.3f, Width = %0.3f, Height = %0.3f, Area %0.3f > %0.3f\n", |
| 61 |
XC, YR*2., ZR*2., S, YR*ZR*4.); |
| 62 |
if( s_norm > 3.14 ) /* interpolate towards a square shape */ |
| 63 |
{ |
| 64 |
d = (s_norm-pi)/(4.0-pi); |
| 65 |
for(i=0;i < (points/8)+1 ; i++, theta += step) |
| 66 |
{ |
| 67 |
f = (fabs(1.0/cos(theta)) - 1) * d + 1; |
| 68 |
fprintf(ofp,"%f %f %f\n", XC, cos(theta)*f*ZR+ZC, sin(theta)*f*YR+YC); |
| 69 |
} |
| 70 |
for(i=0 ;i < points/4 ; i++, theta += step) |
| 71 |
{ |
| 72 |
f = (fabs(1.0/sin(theta)) - 1) * d + 1; |
| 73 |
fprintf(ofp,"%f %f %f\n", XC, cos(theta)*f*ZR+ZC, sin(theta)*f*YR+YC); |
| 74 |
} |
| 75 |
for(i=0;i < points/4; i++, theta += step) |
| 76 |
{ |
| 77 |
f = (fabs (1.0/cos(theta)) - 1) * d + 1; |
| 78 |
fprintf(ofp,"%f %f %f\n", XC, cos(theta)*f*ZR+ZC, sin(theta)*f*YR+YC); |
| 79 |
} |
| 80 |
for(i=0 ;i < points/4 ; i++, theta += step) |
| 81 |
{ |
| 82 |
f = (fabs(1.0/sin(theta)) - 1) * d + 1; |
| 83 |
fprintf(ofp,"%f %f %f\n", XC, cos(theta)*f*ZR+ZC, sin(theta)*f*YR+YC); |
| 84 |
} |
| 85 |
for(i=0;i < (points/8) - 1; i++, theta += step) |
| 86 |
{ |
| 87 |
f = (fabs (1.0/cos(theta)) - 1) * d + 1; |
| 88 |
fprintf(ofp,"%f %f %f\n", XC, cos(theta)*f*ZR+ZC, sin(theta)*f*YR+YC); |
| 89 |
} |
| 90 |
} else { /* s_norm < 3.14, interpolate towards a diamond shape */ |
| 91 |
d = (s_norm-pi)/(4.0-pi)*(-pi/4); |
| 92 |
for(i=0;i < points/4 ; i++, theta += step) |
| 93 |
{ // ROOOT2/( 2 * sin(0.75*pi-theta)) |
| 94 |
f = (( ROOT2/( 2 * sin(0.75*pi-theta)) ) - 1) * d + 1; |
| 95 |
fprintf(ofp,"%f %f %f\n", XC, cos(theta)*f*ZR+ZC, sin(theta)*f*YR+YC); |
| 96 |
} |
| 97 |
for(i=0 ;i < points/4 ; i++, theta += step) |
| 98 |
{ |
| 99 |
f = (( ROOT2/( 2 * cos(0.75*pi-theta)) ) - 1) * d + 1; |
| 100 |
fprintf(ofp,"%f %f %f\n", XC, cos(theta)*f*ZR+ZC, sin(theta)*f*YR+YC); |
| 101 |
} |
| 102 |
for(i=0;i < points/4; i++, theta += step) |
| 103 |
{ |
| 104 |
f = (( ROOT2/-( 2 * sin(0.75*pi-theta)) ) - 1) * d + 1; |
| 105 |
fprintf(ofp,"%f %f %f\n", XC, cos(theta)*f*ZR+ZC, sin(theta)*f*YR+YC); |
| 106 |
} |
| 107 |
for(i=0 ;i < points/4 ; i++, theta += step) |
| 108 |
{ |
| 109 |
f = (( ROOT2/-( 2 * cos(0.75*pi-theta)) ) - 1) * d + 1; |
| 110 |
fprintf(ofp,"%f %f %f\n", XC, cos(theta)*f*ZR+ZC, sin(theta)*f*YR+YC); |
| 111 |
} |
| 112 |
|
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
/* Radius, X_Center, Y_Center, Z_Center, X_Rotate, Y_Rotate, Z_rotate, Number of Points, File Pointer */ |
| 117 |
|
| 118 |
RIB3D *GetRibCircle(double R, double XC, double YC, double ZC, double Xrot, double Yrot, double Zrot, int points, FILE *ofp) |
| 119 |
{ |
| 120 |
int i,j; |
| 121 |
double theta, step; |
| 122 |
double omatrix[4][4], xmatrix[4][4], ymatrix[4][4], zmatrix[4][4], fmatrix[4][4]; |
| 123 |
} |