+/* convert a geodetic point lon(arcsec), lat(arcsec), elev(meter) to
+ * a cartesian point */
+struct fgCartesianPoint geod_to_cart(double geod[3]) {
+ struct fgCartesianPoint p;
+ double gc_lon, gc_lat, sl_radius;
+
+ /* printf("A geodetic point is (%.2f, %.2f, %.2f)\n",
+ geod[0], geod[1], geod[2]); */
+
+ gc_lon = geod[0]*ARCSEC_TO_RAD;
+ fgGeodToGeoc(geod[1]*ARCSEC_TO_RAD, geod[2], &sl_radius, &gc_lat);
+
+ /* printf("A geocentric point is (%.2f, %.2f, %.2f)\n", gc_lon,
+ gc_lat, sl_radius+geod[2]); */
+
+ p = fgPolarToCart(gc_lon, gc_lat, sl_radius+geod[2]);
+
+ /* printf("A cart point is (%.8f, %.8f, %.8f)\n", p.x, p.y, p.z); */
+
+ return(p);
+}
+
+
+/* given three points defining a triangle, calculate the normal */
+void calc_normal(struct fgCartesianPoint p1, struct fgCartesianPoint p2,
+ struct fgCartesianPoint p3, double normal[3])
+{
+ double v1[3], v2[3];
+ float temp;
+
+ v1[0] = p2.x - p1.x; v1[1] = p2.y - p1.y; v1[2] = p2.z - p1.z;
+ v2[0] = p3.x - p1.x; v2[1] = p3.y - p1.y; v2[2] = p3.z - p1.z;
+
+ MAT3cross_product(normal, v1, v2);
+ MAT3_NORMALIZE_VEC(normal,temp);
+
+ /* printf("Normal = %.2f %.2f %.2f\n", normal[0], normal[1], normal[2]); */
+}
+
+
+/* return the index of all triangles containing the specified node */
+void find_tris(int n, int *t1, int *t2, int *t3) {
+ int i;
+
+ *t1 = *t2 = *t3 = 0;
+
+ i = 1;
+ while ( i <= tricount ) {
+ if ( (n == tris[i][0]) || (n == tris[i][1]) || (n == tris[i][2]) ) {
+ if ( *t1 == 0 ) {
+ *t1 = i;
+ } else if ( *t2 == 0 ) {
+ *t2 = i;
+ } else {
+ *t3 = i;
+ }
+ }
+ i++;
+ }
+}
+
+