#include "stdlib.h" #include "stdio.h" #include "math.h" /* Create a spherical triangle between three points on a sphere */ typedef struct { double x,y,z; } XYZ; typedef struct { XYZ p1,p2,p3; } FACET3; #define DTOR 0.0174532925 XYZ MidPoint(XYZ,XYZ); void Normalise(XYZ *); int main(int argc,char **argv) { int i,j; int n=0,nstart; int iterations = 2; FACET3 *f = NULL; double theta[3] = {0.0,35.0,80.0}, phi[3] = {10.0,15.0,80.0}; // corner in polar coordinates XYZ p1,p2,p3; if (argc > 1) iterations = atoi(argv[1]); // Start with the vertices of the triangle f = malloc(sizeof(FACET3)); f[0].p1.x = cos(phi[0]*DTOR) * cos(theta[0]*DTOR); f[0].p1.y = cos(phi[0]*DTOR) * sin(theta[0]*DTOR); f[0].p1.z = sin(phi[0]*DTOR); f[0].p2.x = cos(phi[1]*DTOR) * cos(theta[1]*DTOR); f[0].p2.y = cos(phi[1]*DTOR) * sin(theta[1]*DTOR); f[0].p2.z = sin(phi[1]*DTOR); f[0].p3.x = cos(phi[2]*DTOR) * cos(theta[2]*DTOR); f[0].p3.y = cos(phi[2]*DTOR) * sin(theta[2]*DTOR); f[0].p3.z = sin(phi[2]*DTOR); n = 1; for (i=1;ix * p->x + p->y * p->y + p->z * p->z); if (length != 0) { p->x /= length; p->y /= length; p->z /= length; } else { p->x = 0; p->y = 0; p->z = 0; } }