1
0
Fork 0

Now use libMath rather than having local copies of math routines.

This commit is contained in:
curt 1998-04-18 04:01:01 +00:00
parent 2c866a0b5c
commit db45671ad3
23 changed files with 71 additions and 2176 deletions

View file

@ -1,149 +0,0 @@
/* Copyright 1988, Brown Computer Graphics Group. All Rights Reserved. */
/* --------------------------------------------------------------------------
* This file contains routines that operate on matrices and vectors, or
* vectors and vectors.
* -------------------------------------------------------------------------*/
/* #include "sphigslocal.h" */
/* -------------------------- Static Routines ---------------------------- */
/* ------------------------- Internal Routines --------------------------- */
/* -------------------------- Public Routines ---------------------------- */
/*
* Multiplies a vector by a matrix, setting the result vector.
* It assumes all homogeneous coordinates are 1.
* The two vectors involved may be the same.
*/
#include "mat3.h"
#ifndef TRUE
# define TRUE 1
#endif
#ifndef FALSE
# define FALSE 0
#endif
void
MAT3mult_vec(double *result_vec, register double *vec, register double (*mat)[4])
{
MAT3vec tempvec;
register double *temp = tempvec;
temp[0] = vec[0] * mat[0][0] + vec[1] * mat[1][0] +
vec[2] * mat[2][0] + mat[3][0];
temp[1] = vec[0] * mat[0][1] + vec[1] * mat[1][1] +
vec[2] * mat[2][1] + mat[3][1];
temp[2] = vec[0] * mat[0][2] + vec[1] * mat[1][2] +
vec[2] * mat[2][2] + mat[3][2];
MAT3_COPY_VEC(result_vec, temp);
}
/*
* Multiplies a vector of size 4 by a matrix, setting the result vector.
* The fourth element of the vector is the homogeneous coordinate, which
* may or may not be 1. If the "normalize" parameter is TRUE, then the
* result vector will be normalized so that the homogeneous coordinate is 1.
* The two vectors involved may be the same.
* This returns zero if the vector was to be normalized, but couldn't be.
*/
int
MAT3mult_hvec(double *result_vec, register double *vec, register double (*mat)[4], int normalize)
{
MAT3hvec tempvec;
double norm_fac;
register double *temp = tempvec;
register int ret = TRUE;
temp[0] = vec[0] * mat[0][0] + vec[1] * mat[1][0] +
vec[2] * mat[2][0] + vec[3] * mat[3][0];
temp[1] = vec[0] * mat[0][1] + vec[1] * mat[1][1] +
vec[2] * mat[2][1] + vec[3] * mat[3][1];
temp[2] = vec[0] * mat[0][2] + vec[1] * mat[1][2] +
vec[2] * mat[2][2] + vec[3] * mat[3][2];
temp[3] = vec[0] * mat[0][3] + vec[1] * mat[1][3] +
vec[2] * mat[2][3] + vec[3] * mat[3][3];
/* Normalize if asked for, possible, and necessary */
if (normalize) {
if (MAT3_IS_ZERO(temp[3])) {
#ifndef THINK_C
fprintf (stderr,
"Can't normalize vector: homogeneous coordinate is 0");
#endif
ret = FALSE;
}
else {
norm_fac = 1.0 / temp[3];
MAT3_SCALE_VEC(result_vec, temp, norm_fac);
result_vec[3] = 1.0;
}
}
else MAT3_COPY_HVEC(result_vec, temp);
return(ret);
}
/*
* Sets the first vector to be the cross-product of the last two vectors.
*/
void
MAT3cross_product(double *result_vec, register double *vec1, register double *vec2)
{
MAT3vec tempvec;
register double *temp = tempvec;
temp[0] = vec1[1] * vec2[2] - vec1[2] * vec2[1];
temp[1] = vec1[2] * vec2[0] - vec1[0] * vec2[2];
temp[2] = vec1[0] * vec2[1] - vec1[1] * vec2[0];
MAT3_COPY_VEC(result_vec, temp);
}
/*
* Finds a vector perpendicular to vec and stores it in result_vec.
* Method: take any vector (we use <0,1,0>) and subtract the
* portion of it pointing in the vec direction. This doesn't
* work if vec IS <0,1,0> or is very near it. So if this is
* the case, use <0,0,1> instead.
* If "is_unit" is TRUE, the given vector is assumed to be unit length.
*/
#define SELECT .7071 /* selection constant (roughly .5*sqrt(2) */
void
MAT3perp_vec(double *result_vec, double *vec, int is_unit)
{
MAT3vec norm;
double dot;
MAT3_SET_VEC(result_vec, 0.0, 1.0, 0.0);
MAT3_COPY_VEC(norm, vec);
if (! is_unit) MAT3_NORMALIZE_VEC(norm, dot);
/* See if vector is too close to <0,1,0>. If so, use <0,0,1> */
if ((dot = MAT3_DOT_PRODUCT(norm, result_vec)) > SELECT || dot < -SELECT) {
result_vec[1] = 0.0;
result_vec[2] = 1.0;
dot = MAT3_DOT_PRODUCT(norm, result_vec);
}
/* Subtract off non-perpendicular part */
result_vec[0] -= dot * norm[0];
result_vec[1] -= dot * norm[1];
result_vec[2] -= dot * norm[2];
/* Make result unit length */
MAT3_NORMALIZE_VEC(result_vec, dot);
}

View file

@ -26,15 +26,18 @@
bin_PROGRAMS = fixobj
fixobj_SOURCES = main.c mat3.h obj.c obj.h MAT3vec.c
fixobj_SOURCES = main.c obj.c obj.h
fixobj_LDADD =
fixobj_LDADD = $(top_builddir)/Lib/Math/libMath.la
INCLUDES += -I$(top_builddir)
INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib
#---------------------------------------------------------------------------
# $Log$
# Revision 1.3 1998/04/18 04:01:02 curt
# Now use libMath rather than having local copies of math routines.
#
# Revision 1.2 1998/04/14 02:26:05 curt
# Code reorganizations. Added a Lib/ directory for more general libraries.
#

View file

@ -98,9 +98,9 @@ VERSION = @VERSION@
bin_PROGRAMS = fixobj
fixobj_SOURCES = main.c mat3.h obj.c obj.h MAT3vec.c
fixobj_SOURCES = main.c obj.c obj.h
fixobj_LDADD =
fixobj_LDADD = $(top_builddir)/Lib/Math/libMath.la
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = ../../Include/config.h
CONFIG_CLEAN_FILES =
@ -115,8 +115,8 @@ X_CFLAGS = @X_CFLAGS@
X_LIBS = @X_LIBS@
X_EXTRA_LIBS = @X_EXTRA_LIBS@
X_PRE_LIBS = @X_PRE_LIBS@
fixobj_OBJECTS = main.o obj.o MAT3vec.o
fixobj_DEPENDENCIES =
fixobj_OBJECTS = main.o obj.o
fixobj_DEPENDENCIES = $(top_builddir)/Lib/Math/libMath.la
fixobj_LDFLAGS =
CFLAGS = @CFLAGS@
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
@ -129,7 +129,7 @@ DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = tar
GZIP = --best
DEP_FILES = .deps/MAT3vec.P .deps/main.P .deps/obj.P
DEP_FILES = .deps/main.P .deps/obj.P
SOURCES = $(fixobj_SOURCES)
OBJECTS = $(fixobj_OBJECTS)
@ -339,10 +339,13 @@ clean-generic maintainer-clean-generic clean mostlyclean distclean \
maintainer-clean
INCLUDES += -I$(top_builddir)
INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib
#---------------------------------------------------------------------------
# $Log$
# Revision 1.3 1998/04/18 04:01:02 curt
# Now use libMath rather than having local copies of math routines.
#
# Revision 1.2 1998/04/14 02:26:05 curt
# Code reorganizations. Added a Lib/ directory for more general libraries.
#

View file

@ -1,147 +0,0 @@
/* Copyright 1988, Brown Computer Graphics Group. All Rights Reserved. */
/* -------------------------------------------------------------------------
Public MAT3 include file
------------------------------------------------------------------------- */
#ifndef MAT3_HAS_BEEN_INCLUDED
#define MAT3_HAS_BEEN_INCLUDED
/* ----------------------------- Constants ------------------------------ */
/*
* Make sure the math library .h file is included, in case it wasn't.
*/
#ifndef HUGE
#include <math.h>
#endif
#include <stdio.h>
#define MAT3_DET0 -1 /* Indicates singular mat */
#define MAT3_EPSILON 1e-12 /* Close enough to zero */
#define MAT3_PI 3.141592653589793 /* Pi */
/* ------------------------------ Types --------------------------------- */
typedef double MAT3mat[4][4]; /* 4x4 matrix */
typedef double MAT3vec[3]; /* Vector */
typedef double MAT3hvec[4]; /* Vector with homogeneous coord */
/* ------------------------------ Macros -------------------------------- */
/* Tests if a number is within EPSILON of zero */
#define MAT3_IS_ZERO(N) ((N) < MAT3_EPSILON && (N) > -MAT3_EPSILON)
/* Sets a vector to the three given values */
#define MAT3_SET_VEC(V,X,Y,Z) ((V)[0]=(X), (V)[1]=(Y), (V)[2]=(Z))
/* Tests a vector for all components close to zero */
#define MAT3_IS_ZERO_VEC(V) (MAT3_IS_ZERO((V)[0]) && \
MAT3_IS_ZERO((V)[1]) && \
MAT3_IS_ZERO((V)[2]))
/* Dot product of two vectors */
#define MAT3_DOT_PRODUCT(V1,V2) \
((V1)[0]*(V2)[0] + (V1)[1]*(V2)[1] + (V1)[2]*(V2)[2])
/* Copy one vector to other */
#define MAT3_COPY_VEC(TO,FROM) ((TO)[0] = (FROM)[0], \
(TO)[1] = (FROM)[1], \
(TO)[2] = (FROM)[2])
/* Normalize vector to unit length, using TEMP as temporary variable.
* TEMP will be zero if vector has zero length */
#define MAT3_NORMALIZE_VEC(V,TEMP) \
if ((TEMP = sqrt(MAT3_DOT_PRODUCT(V,V))) > MAT3_EPSILON) { \
TEMP = 1.0 / TEMP; \
MAT3_SCALE_VEC(V,V,TEMP); \
} else TEMP = 0.0
/* Scale vector by given factor, storing result vector in RESULT_V */
#define MAT3_SCALE_VEC(RESULT_V,V,SCALE) \
MAT3_SET_VEC(RESULT_V, (V)[0]*(SCALE), (V)[1]*(SCALE), (V)[2]*(SCALE))
/* Adds vectors V1 and V2, storing result in RESULT_V */
#define MAT3_ADD_VEC(RESULT_V,V1,V2) \
MAT3_SET_VEC(RESULT_V, (V1)[0]+(V2)[0], (V1)[1]+(V2)[1], \
(V1)[2]+(V2)[2])
/* Subtracts vector V2 from V1, storing result in RESULT_V */
#define MAT3_SUB_VEC(RESULT_V,V1,V2) \
MAT3_SET_VEC(RESULT_V, (V1)[0]-(V2)[0], (V1)[1]-(V2)[1], \
(V1)[2]-(V2)[2])
/* Multiplies vectors V1 and V2, storing result in RESULT_V */
#define MAT3_MULT_VEC(RESULT_V,V1,V2) \
MAT3_SET_VEC(RESULT_V, (V1)[0]*(V2)[0], (V1)[1]*(V2)[1], \
(V1)[2]*(V2)[2])
/* Sets RESULT_V to the linear combination of V1 and V2, scaled by
* SCALE1 and SCALE2, respectively */
#define MAT3_LINEAR_COMB(RESULT_V,SCALE1,V1,SCALE2,V2) \
MAT3_SET_VEC(RESULT_V, (SCALE1)*(V1)[0] + (SCALE2)*(V2)[0], \
(SCALE1)*(V1)[1] + (SCALE2)*(V2)[1], \
(SCALE1)*(V1)[2] + (SCALE2)*(V2)[2])
/* Several of the vector macros are useful for homogeneous-coord vectors */
#define MAT3_SET_HVEC(V,X,Y,Z,W) ((V)[0]=(X), (V)[1]=(Y), \
(V)[2]=(Z), (V)[3]=(W))
#define MAT3_COPY_HVEC(TO,FROM) ((TO)[0] = (FROM)[0], \
(TO)[1] = (FROM)[1], \
(TO)[2] = (FROM)[2], \
(TO)[3] = (FROM)[3])
#define MAT3_SCALE_HVEC(RESULT_V,V,SCALE) \
MAT3_SET_HVEC(RESULT_V, (V)[0]*(SCALE), (V)[1]*(SCALE), \
(V)[2]*(SCALE), (V)[3]*(SCALE))
#define MAT3_ADD_HVEC(RESULT_V,V1,V2) \
MAT3_SET_HVEC(RESULT_V, (V1)[0]+(V2)[0], (V1)[1]+(V2)[1], \
(V1)[2]+(V2)[2], (V1)[3]+(V2)[3])
#define MAT3_SUB_HVEC(RESULT_V,V1,V2) \
MAT3_SET_HVEC(RESULT_V, (V1)[0]-(V2)[0], (V1)[1]-(V2)[1], \
(V1)[2]-(V2)[2], (V1)[3]-(V2)[3])
#define MAT3_MULT_HVEC(RESULT_V,V1,V2) \
MAT3_SET_HVEC(RESULT_V, (V1)[0]*(V2)[0], (V1)[1]*(V2)[1], \
(V1)[2]*(V2)[2], (V1)[3]*(V2)[3])
/* ------------------------------ Entries ------------------------------- */
/* In MAT3geom.c */
void MAT3direction_matrix (MAT3mat result_mat, MAT3mat mat);
int MAT3normal_matrix (MAT3mat result_mat, MAT3mat mat);
void MAT3rotate (MAT3mat result_mat, MAT3vec axis, double angle_in_radians);
void MAT3translate (MAT3mat result_mat, MAT3vec trans);
void MAT3scale (MAT3mat result_mat, MAT3vec scale);
void MAT3shear(MAT3mat result_mat, double xshear, double yshear);
/* In MAT3mat.c */
void MAT3identity(MAT3mat);
void MAT3zero(MAT3mat);
void MAT3copy (MAT3mat to, MAT3mat from);
void MAT3mult (MAT3mat result, MAT3mat, MAT3mat);
void MAT3transpose (MAT3mat result, MAT3mat);
int MAT3invert (MAT3mat result, MAT3mat);
void MAT3print (MAT3mat, FILE *fp);
void MAT3print_formatted (MAT3mat, FILE *fp,
char *title, char *head, char *format, char *tail);
extern int MAT3equal( void );
extern double MAT3trace( void );
extern int MAT3power( void );
extern int MAT3column_reduce( void );
extern int MAT3kernel_basis( void );
/* In MAT3vec.c */
void MAT3mult_vec(MAT3vec result_vec, MAT3vec vec, MAT3mat mat);
int MAT3mult_hvec (MAT3hvec result_vec, MAT3hvec vec, MAT3mat mat, int normalize);
void MAT3cross_product(MAT3vec result,MAT3vec,MAT3vec);
void MAT3perp_vec(MAT3vec result_vec, MAT3vec vec, int is_unit);
#endif /* MAT3_HAS_BEEN_INCLUDED */

View file

@ -29,7 +29,7 @@
#include "obj.h"
#include "mat3.h"
#include <Math/mat3.h>
/* what do ya' know, here's some global variables */
@ -291,9 +291,12 @@ void obj_fix(char *infile, char *outfile) {
/* $Log$
/* Revision 1.8 1998/04/08 23:19:37 curt
/* Adopted Gnu automake/autoconf system.
/* Revision 1.9 1998/04/18 04:01:03 curt
/* Now use libMath rather than having local copies of math routines.
/*
* Revision 1.8 1998/04/08 23:19:37 curt
* Adopted Gnu automake/autoconf system.
*
* Revision 1.7 1998/03/19 02:51:41 curt
* Added special case handling to compensate for bugs in our beloved tri striper
*

View file

@ -1,149 +0,0 @@
/* Copyright 1988, Brown Computer Graphics Group. All Rights Reserved. */
/* --------------------------------------------------------------------------
* This file contains routines that operate on matrices and vectors, or
* vectors and vectors.
* -------------------------------------------------------------------------*/
/* #include "sphigslocal.h" */
/* -------------------------- Static Routines ---------------------------- */
/* ------------------------- Internal Routines --------------------------- */
/* -------------------------- Public Routines ---------------------------- */
/*
* Multiplies a vector by a matrix, setting the result vector.
* It assumes all homogeneous coordinates are 1.
* The two vectors involved may be the same.
*/
#include "mat3.h"
#ifndef TRUE
# define TRUE 1
#endif
#ifndef FALSE
# define FALSE 0
#endif
void
MAT3mult_vec(double *result_vec, register double *vec, register double (*mat)[4])
{
MAT3vec tempvec;
register double *temp = tempvec;
temp[0] = vec[0] * mat[0][0] + vec[1] * mat[1][0] +
vec[2] * mat[2][0] + mat[3][0];
temp[1] = vec[0] * mat[0][1] + vec[1] * mat[1][1] +
vec[2] * mat[2][1] + mat[3][1];
temp[2] = vec[0] * mat[0][2] + vec[1] * mat[1][2] +
vec[2] * mat[2][2] + mat[3][2];
MAT3_COPY_VEC(result_vec, temp);
}
/*
* Multiplies a vector of size 4 by a matrix, setting the result vector.
* The fourth element of the vector is the homogeneous coordinate, which
* may or may not be 1. If the "normalize" parameter is TRUE, then the
* result vector will be normalized so that the homogeneous coordinate is 1.
* The two vectors involved may be the same.
* This returns zero if the vector was to be normalized, but couldn't be.
*/
int
MAT3mult_hvec(double *result_vec, register double *vec, register double (*mat)[4], int normalize)
{
MAT3hvec tempvec;
double norm_fac;
register double *temp = tempvec;
register int ret = TRUE;
temp[0] = vec[0] * mat[0][0] + vec[1] * mat[1][0] +
vec[2] * mat[2][0] + vec[3] * mat[3][0];
temp[1] = vec[0] * mat[0][1] + vec[1] * mat[1][1] +
vec[2] * mat[2][1] + vec[3] * mat[3][1];
temp[2] = vec[0] * mat[0][2] + vec[1] * mat[1][2] +
vec[2] * mat[2][2] + vec[3] * mat[3][2];
temp[3] = vec[0] * mat[0][3] + vec[1] * mat[1][3] +
vec[2] * mat[2][3] + vec[3] * mat[3][3];
/* Normalize if asked for, possible, and necessary */
if (normalize) {
if (MAT3_IS_ZERO(temp[3])) {
#ifndef THINK_C
fprintf (stderr,
"Can't normalize vector: homogeneous coordinate is 0");
#endif
ret = FALSE;
}
else {
norm_fac = 1.0 / temp[3];
MAT3_SCALE_VEC(result_vec, temp, norm_fac);
result_vec[3] = 1.0;
}
}
else MAT3_COPY_HVEC(result_vec, temp);
return(ret);
}
/*
* Sets the first vector to be the cross-product of the last two vectors.
*/
void
MAT3cross_product(double *result_vec, register double *vec1, register double *vec2)
{
MAT3vec tempvec;
register double *temp = tempvec;
temp[0] = vec1[1] * vec2[2] - vec1[2] * vec2[1];
temp[1] = vec1[2] * vec2[0] - vec1[0] * vec2[2];
temp[2] = vec1[0] * vec2[1] - vec1[1] * vec2[0];
MAT3_COPY_VEC(result_vec, temp);
}
/*
* Finds a vector perpendicular to vec and stores it in result_vec.
* Method: take any vector (we use <0,1,0>) and subtract the
* portion of it pointing in the vec direction. This doesn't
* work if vec IS <0,1,0> or is very near it. So if this is
* the case, use <0,0,1> instead.
* If "is_unit" is TRUE, the given vector is assumed to be unit length.
*/
#define SELECT .7071 /* selection constant (roughly .5*sqrt(2) */
void
MAT3perp_vec(double *result_vec, double *vec, int is_unit)
{
MAT3vec norm;
double dot;
MAT3_SET_VEC(result_vec, 0.0, 1.0, 0.0);
MAT3_COPY_VEC(norm, vec);
if (! is_unit) MAT3_NORMALIZE_VEC(norm, dot);
/* See if vector is too close to <0,1,0>. If so, use <0,0,1> */
if ((dot = MAT3_DOT_PRODUCT(norm, result_vec)) > SELECT || dot < -SELECT) {
result_vec[1] = 0.0;
result_vec[2] = 1.0;
dot = MAT3_DOT_PRODUCT(norm, result_vec);
}
/* Subtract off non-perpendicular part */
result_vec[0] -= dot * norm[0];
result_vec[1] -= dot * norm[1];
result_vec[2] -= dot * norm[2];
/* Make result unit length */
MAT3_NORMALIZE_VEC(result_vec, dot);
}

View file

@ -26,21 +26,20 @@
bin_PROGRAMS = splittris
splittris_SOURCES = \
MAT3vec.c \
fg_geodesy.c fg_geodesy.h \
mat3.h \
polar.c polar.h \
splittris.c splittris.h
splittris_SOURCES = splittris.c splittris.h
splittris_LDADD = \
$(top_builddir)/Lib/Bucket/libBucket.la
$(top_builddir)/Lib/Bucket/libBucket.la \
$(top_builddir)/Lib/Math/libMath.la
INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib
#---------------------------------------------------------------------------
# $Log$
# Revision 1.3 1998/04/18 04:01:17 curt
# Now use libMath rather than having local copies of math routines.
#
# Revision 1.2 1998/04/14 02:26:06 curt
# Code reorganizations. Added a Lib/ directory for more general libraries.
#

View file

@ -98,15 +98,11 @@ VERSION = @VERSION@
bin_PROGRAMS = splittris
splittris_SOURCES = \
MAT3vec.c \
fg_geodesy.c fg_geodesy.h \
mat3.h \
polar.c polar.h \
splittris.c splittris.h
splittris_SOURCES = splittris.c splittris.h
splittris_LDADD = \
$(top_builddir)/Lib/Bucket/libBucket.la
$(top_builddir)/Lib/Bucket/libBucket.la \
$(top_builddir)/Lib/Math/libMath.la
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = ../../Include/config.h
CONFIG_CLEAN_FILES =
@ -121,8 +117,9 @@ X_CFLAGS = @X_CFLAGS@
X_LIBS = @X_LIBS@
X_EXTRA_LIBS = @X_EXTRA_LIBS@
X_PRE_LIBS = @X_PRE_LIBS@
splittris_OBJECTS = MAT3vec.o fg_geodesy.o polar.o splittris.o
splittris_DEPENDENCIES = $(top_builddir)/Lib/Bucket/libBucket.la
splittris_OBJECTS = splittris.o
splittris_DEPENDENCIES = $(top_builddir)/Lib/Bucket/libBucket.la \
$(top_builddir)/Lib/Math/libMath.la
splittris_LDFLAGS =
CFLAGS = @CFLAGS@
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
@ -135,8 +132,7 @@ DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = tar
GZIP = --best
DEP_FILES = .deps/MAT3vec.P .deps/fg_geodesy.P .deps/polar.P \
.deps/splittris.P
DEP_FILES = .deps/splittris.P
SOURCES = $(splittris_SOURCES)
OBJECTS = $(splittris_OBJECTS)
@ -350,7 +346,10 @@ INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib
#---------------------------------------------------------------------------
# $Log$
# Revision 1.2 1998/04/14 02:26:07 curt
# Revision 1.3 1998/04/18 04:01:17 curt
# Now use libMath rather than having local copies of math routines.
#
# Revision 1.2 1998/04/14 02:26:06 curt
# Code reorganizations. Added a Lib/ directory for more general libraries.
#
# Revision 1.1 1998/04/08 23:21:10 curt

View file

@ -1,230 +0,0 @@
/**************************************************************************
* fg_geodesy.c -- routines to convert between geodetic and geocentric
* coordinate systems.
*
* Copied and adapted directly from LaRCsim/ls_geodesy.c
*
* See below for the complete original LaRCsim comments.
*
* $Id$
* (Log is kept at end of this file)
**************************************************************************/
#include <math.h>
#include <Include/fg_constants.h>
#include "fg_geodesy.h"
/* ONE_SECOND is pi/180/60/60, or about 100 feet at earths' equator */
#define ONE_SECOND 4.848136811E-6
/* fgGeocToGeod(lat_geoc, radius, *lat_geod, *alt, *sea_level_r)
* INPUTS:
* lat_geoc Geocentric latitude, radians, + = North
* radius C.G. radius to earth center, ft
*
* OUTPUTS:
* lat_geod Geodetic latitude, radians, + = North
* alt C.G. altitude above mean sea level, ft
* sea_level_r radius from earth center to sea level at
* local vertical (surface normal) of C.G.
*/
void fgGeocToGeod( double lat_geoc, double radius, double
*lat_geod, double *alt, double *sea_level_r )
{
double t_lat, x_alpha, mu_alpha, delt_mu, r_alpha, l_point, rho_alpha;
double sin_mu_a, denom,delt_lambda, lambda_sl, sin_lambda_sl;
if( ( (FG_PI_2 - lat_geoc) < ONE_SECOND ) /* near North pole */
|| ( (FG_PI_2 + lat_geoc) < ONE_SECOND ) ) /* near South pole */
{
*lat_geod = lat_geoc;
*sea_level_r = EQUATORIAL_RADIUS_KM*E;
*alt = radius - *sea_level_r;
} else {
t_lat = tan(lat_geoc);
x_alpha = E*EQUATORIAL_RADIUS_KM/sqrt(t_lat*t_lat + E*E);
mu_alpha = atan2(sqrt(RESQ_KM - x_alpha*x_alpha),E*x_alpha);
if (lat_geoc < 0) mu_alpha = - mu_alpha;
sin_mu_a = sin(mu_alpha);
delt_lambda = mu_alpha - lat_geoc;
r_alpha = x_alpha/cos(lat_geoc);
l_point = radius - r_alpha;
*alt = l_point*cos(delt_lambda);
denom = sqrt(1-EPS*EPS*sin_mu_a*sin_mu_a);
rho_alpha = EQUATORIAL_RADIUS_KM*(1-EPS)/
(denom*denom*denom);
delt_mu = atan2(l_point*sin(delt_lambda),rho_alpha + *alt);
*lat_geod = mu_alpha - delt_mu;
lambda_sl = atan( E*E * tan(*lat_geod) ); /* SL geoc. latitude */
sin_lambda_sl = sin( lambda_sl );
*sea_level_r =
sqrt(RESQ_KM / (1 + ((1/(E*E))-1)*sin_lambda_sl*sin_lambda_sl));
}
}
/* fgGeodToGeoc( lat_geod, alt, *sl_radius, *lat_geoc )
* INPUTS:
* lat_geod Geodetic latitude, radians, + = North
* alt C.G. altitude above mean sea level, ft
*
* OUTPUTS:
* sl_radius SEA LEVEL radius to earth center, ft (add Altitude to
* get true distance from earth center.
* lat_geoc Geocentric latitude, radians, + = North
*
*/
void fgGeodToGeoc( double lat_geod, double alt, double *sl_radius,
double *lat_geoc )
{
double lambda_sl, sin_lambda_sl, cos_lambda_sl, sin_mu, cos_mu, px, py;
lambda_sl = atan( E*E * tan(lat_geod) ); /* sea level geocentric latitude */
sin_lambda_sl = sin( lambda_sl );
cos_lambda_sl = cos( lambda_sl );
sin_mu = sin(lat_geod); /* Geodetic (map makers') latitude */
cos_mu = cos(lat_geod);
*sl_radius =
sqrt(RESQ_KM / (1 + ((1/(E*E))-1)*sin_lambda_sl*sin_lambda_sl));
py = *sl_radius*sin_lambda_sl + alt*sin_mu;
px = *sl_radius*cos_lambda_sl + alt*cos_mu;
*lat_geoc = atan2( py, px );
}
/***************************************************************************
TITLE: ls_geodesy
----------------------------------------------------------------------------
FUNCTION: Converts geocentric coordinates to geodetic positions
----------------------------------------------------------------------------
MODULE STATUS: developmental
----------------------------------------------------------------------------
GENEALOGY: Written as part of LaRCSim project by E. B. Jackson
----------------------------------------------------------------------------
DESIGNED BY: E. B. Jackson
CODED BY: E. B. Jackson
MAINTAINED BY: E. B. Jackson
----------------------------------------------------------------------------
MODIFICATION HISTORY:
DATE PURPOSE BY
930208 Modified to avoid singularity near polar region. EBJ
930602 Moved backwards calcs here from ls_step. EBJ
931214 Changed erroneous Latitude and Altitude variables to
*lat_geod and *alt in routine ls_geoc_to_geod. EBJ
940111 Changed header files from old ls_eom.h style to ls_types,
and ls_constants. Also replaced old DATA type with new
SCALAR type. EBJ
CURRENT RCS HEADER:
$Header$
$Log$
Revision 1.1 1998/04/08 23:21:11 curt
Adopted Gnu automake/autoconf system.
Revision 1.4 1998/01/27 00:47:59 curt
Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
system and commandline/config file processing code.
Revision 1.3 1998/01/19 19:27:12 curt
Merged in make system changes from Bob Kuehne <rpk@sgi.com>
This should simplify things tremendously.
Revision 1.2 1997/12/15 23:54:54 curt
Add xgl wrappers for debugging.
Generate terrain normals on the fly.
Revision 1.1 1997/07/31 23:13:14 curt
Initial revision.
Revision 1.1 1997/05/29 00:09:56 curt
Initial Flight Gear revision.
* Revision 1.5 1994/01/11 18:47:05 bjax
* Changed include files to use types and constants, not ls_eom.h
* Also changed DATA type to SCALAR type.
*
* Revision 1.4 1993/12/14 21:06:47 bjax
* Removed global variable references Altitude and Latitude. EBJ
*
* Revision 1.3 1993/06/02 15:03:40 bjax
* Made new subroutine for calculating geodetic to geocentric; changed name
* of forward conversion routine from ls_geodesy to ls_geoc_to_geod.
*
----------------------------------------------------------------------------
REFERENCES:
[ 1] Stevens, Brian L.; and Lewis, Frank L.: "Aircraft
Control and Simulation", Wiley and Sons, 1992.
ISBN 0-471-61397-5
----------------------------------------------------------------------------
CALLED BY: ls_aux
----------------------------------------------------------------------------
CALLS TO:
----------------------------------------------------------------------------
INPUTS:
lat_geoc Geocentric latitude, radians, + = North
radius C.G. radius to earth center, ft
----------------------------------------------------------------------------
OUTPUTS:
lat_geod Geodetic latitude, radians, + = North
alt C.G. altitude above mean sea level, ft
sea_level_r radius from earth center to sea level at
local vertical (surface normal) of C.G.
--------------------------------------------------------------------------*/
/* $Log$
/* Revision 1.1 1998/04/08 23:21:11 curt
/* Adopted Gnu automake/autoconf system.
/*
* Revision 1.4 1998/01/27 00:47:59 curt
* Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
* system and commandline/config file processing code.
*
* Revision 1.3 1998/01/19 19:27:12 curt
* Merged in make system changes from Bob Kuehne <rpk@sgi.com>
* This should simplify things tremendously.
*
* Revision 1.2 1997/12/15 23:54:54 curt
* Add xgl wrappers for debugging.
* Generate terrain normals on the fly.
*
* Revision 1.1 1997/07/31 23:13:14 curt
* Initial revision.
*
*/

View file

@ -1,163 +0,0 @@
/**************************************************************************
* fg_geodesy.h -- routines to convert between geodetic and geocentric
* coordinate systems.
*
* Copied and adapted directly from LaRCsim/ls_geodesy.c
*
* See below for the complete original LaRCsim comments.
*
* $Id$
* (Log is kept at end of this file)
**************************************************************************/
#ifndef _FG_GEODESY_H
#define _FG_GEODESY_H
/* fgGeocToGeod(lat_geoc, radius, *lat_geod, *alt, *sea_level_r)
* INPUTS:
* lat_geoc Geocentric latitude, radians, + = North
* radius C.G. radius to earth center, ft
*
* OUTPUTS:
* lat_geod Geodetic latitude, radians, + = North
* alt C.G. altitude above mean sea level, ft
* sea_level_r radius from earth center to sea level at
* local vertical (surface normal) of C.G.
*/
void fgGeocToGeod( double lat_geoc, double radius, double
*lat_geod, double *alt, double *sea_level_r );
/* fgGeodToGeoc( lat_geod, alt, *sl_radius, *lat_geoc )
* INPUTS:
* lat_geod Geodetic latitude, radians, + = North
* alt C.G. altitude above mean sea level, ft
*
* OUTPUTS:
* sl_radius SEA LEVEL radius to earth center, ft (add Altitude to
* get true distance from earth center.
* lat_geoc Geocentric latitude, radians, + = North
*
*/
void fgGeodToGeoc( double lat_geod, double alt, double *sl_radius,
double *lat_geoc );
/***************************************************************************
TITLE: ls_geodesy
----------------------------------------------------------------------------
FUNCTION: Converts geocentric coordinates to geodetic positions
----------------------------------------------------------------------------
MODULE STATUS: developmental
----------------------------------------------------------------------------
GENEALOGY: Written as part of LaRCSim project by E. B. Jackson
----------------------------------------------------------------------------
DESIGNED BY: E. B. Jackson
CODED BY: E. B. Jackson
MAINTAINED BY: E. B. Jackson
----------------------------------------------------------------------------
MODIFICATION HISTORY:
DATE PURPOSE BY
930208 Modified to avoid singularity near polar region. EBJ
930602 Moved backwards calcs here from ls_step. EBJ
931214 Changed erroneous Latitude and Altitude variables to
*lat_geod and *alt in routine ls_geoc_to_geod. EBJ
940111 Changed header files from old ls_eom.h style to ls_types,
and ls_constants. Also replaced old DATA type with new
SCALAR type. EBJ
CURRENT RCS HEADER:
$Header$
$Log$
Revision 1.1 1998/04/08 23:21:12 curt
Adopted Gnu automake/autoconf system.
Revision 1.2 1998/01/22 02:59:38 curt
Changed #ifdef FILE_H to #ifdef _FILE_H
Revision 1.1 1997/07/31 23:13:14 curt
Initial revision.
Revision 1.1 1997/05/29 00:09:56 curt
Initial Flight Gear revision.
* Revision 1.5 1994/01/11 18:47:05 bjax
* Changed include files to use types and constants, not ls_eom.h
* Also changed DATA type to SCALAR type.
*
* Revision 1.4 1993/12/14 21:06:47 bjax
* Removed global variable references Altitude and Latitude. EBJ
*
* Revision 1.3 1993/06/02 15:03:40 bjax
* Made new subroutine for calculating geodetic to geocentric; changed name
* of forward conversion routine from ls_geodesy to ls_geoc_to_geod.
*
----------------------------------------------------------------------------
REFERENCES:
[ 1] Stevens, Brian L.; and Lewis, Frank L.: "Aircraft
Control and Simulation", Wiley and Sons, 1992.
ISBN 0-471-61397-5
----------------------------------------------------------------------------
CALLED BY: ls_aux
----------------------------------------------------------------------------
CALLS TO:
----------------------------------------------------------------------------
INPUTS:
lat_geoc Geocentric latitude, radians, + = North
radius C.G. radius to earth center, ft
----------------------------------------------------------------------------
OUTPUTS:
lat_geod Geodetic latitude, radians, + = North
alt C.G. altitude above mean sea level, ft
sea_level_r radius from earth center to sea level at
local vertical (surface normal) of C.G.
--------------------------------------------------------------------------*/
#endif /* _FG_GEODESY_H */
/* $Log$
/* Revision 1.1 1998/04/08 23:21:12 curt
/* Adopted Gnu automake/autoconf system.
/*
* Revision 1.2 1998/01/22 02:59:38 curt
* Changed #ifdef FILE_H to #ifdef _FILE_H
*
* Revision 1.1 1997/07/31 23:13:14 curt
* Initial revision.
*
*/

View file

@ -1,147 +0,0 @@
/* Copyright 1988, Brown Computer Graphics Group. All Rights Reserved. */
/* -------------------------------------------------------------------------
Public MAT3 include file
------------------------------------------------------------------------- */
#ifndef MAT3_HAS_BEEN_INCLUDED
#define MAT3_HAS_BEEN_INCLUDED
/* ----------------------------- Constants ------------------------------ */
/*
* Make sure the math library .h file is included, in case it wasn't.
*/
#ifndef HUGE
#include <math.h>
#endif
#include <stdio.h>
#define MAT3_DET0 -1 /* Indicates singular mat */
#define MAT3_EPSILON 1e-12 /* Close enough to zero */
#define MAT3_PI 3.141592653589793 /* Pi */
/* ------------------------------ Types --------------------------------- */
typedef double MAT3mat[4][4]; /* 4x4 matrix */
typedef double MAT3vec[3]; /* Vector */
typedef double MAT3hvec[4]; /* Vector with homogeneous coord */
/* ------------------------------ Macros -------------------------------- */
/* Tests if a number is within EPSILON of zero */
#define MAT3_IS_ZERO(N) ((N) < MAT3_EPSILON && (N) > -MAT3_EPSILON)
/* Sets a vector to the three given values */
#define MAT3_SET_VEC(V,X,Y,Z) ((V)[0]=(X), (V)[1]=(Y), (V)[2]=(Z))
/* Tests a vector for all components close to zero */
#define MAT3_IS_ZERO_VEC(V) (MAT3_IS_ZERO((V)[0]) && \
MAT3_IS_ZERO((V)[1]) && \
MAT3_IS_ZERO((V)[2]))
/* Dot product of two vectors */
#define MAT3_DOT_PRODUCT(V1,V2) \
((V1)[0]*(V2)[0] + (V1)[1]*(V2)[1] + (V1)[2]*(V2)[2])
/* Copy one vector to other */
#define MAT3_COPY_VEC(TO,FROM) ((TO)[0] = (FROM)[0], \
(TO)[1] = (FROM)[1], \
(TO)[2] = (FROM)[2])
/* Normalize vector to unit length, using TEMP as temporary variable.
* TEMP will be zero if vector has zero length */
#define MAT3_NORMALIZE_VEC(V,TEMP) \
if ((TEMP = sqrt(MAT3_DOT_PRODUCT(V,V))) > MAT3_EPSILON) { \
TEMP = 1.0 / TEMP; \
MAT3_SCALE_VEC(V,V,TEMP); \
} else TEMP = 0.0
/* Scale vector by given factor, storing result vector in RESULT_V */
#define MAT3_SCALE_VEC(RESULT_V,V,SCALE) \
MAT3_SET_VEC(RESULT_V, (V)[0]*(SCALE), (V)[1]*(SCALE), (V)[2]*(SCALE))
/* Adds vectors V1 and V2, storing result in RESULT_V */
#define MAT3_ADD_VEC(RESULT_V,V1,V2) \
MAT3_SET_VEC(RESULT_V, (V1)[0]+(V2)[0], (V1)[1]+(V2)[1], \
(V1)[2]+(V2)[2])
/* Subtracts vector V2 from V1, storing result in RESULT_V */
#define MAT3_SUB_VEC(RESULT_V,V1,V2) \
MAT3_SET_VEC(RESULT_V, (V1)[0]-(V2)[0], (V1)[1]-(V2)[1], \
(V1)[2]-(V2)[2])
/* Multiplies vectors V1 and V2, storing result in RESULT_V */
#define MAT3_MULT_VEC(RESULT_V,V1,V2) \
MAT3_SET_VEC(RESULT_V, (V1)[0]*(V2)[0], (V1)[1]*(V2)[1], \
(V1)[2]*(V2)[2])
/* Sets RESULT_V to the linear combination of V1 and V2, scaled by
* SCALE1 and SCALE2, respectively */
#define MAT3_LINEAR_COMB(RESULT_V,SCALE1,V1,SCALE2,V2) \
MAT3_SET_VEC(RESULT_V, (SCALE1)*(V1)[0] + (SCALE2)*(V2)[0], \
(SCALE1)*(V1)[1] + (SCALE2)*(V2)[1], \
(SCALE1)*(V1)[2] + (SCALE2)*(V2)[2])
/* Several of the vector macros are useful for homogeneous-coord vectors */
#define MAT3_SET_HVEC(V,X,Y,Z,W) ((V)[0]=(X), (V)[1]=(Y), \
(V)[2]=(Z), (V)[3]=(W))
#define MAT3_COPY_HVEC(TO,FROM) ((TO)[0] = (FROM)[0], \
(TO)[1] = (FROM)[1], \
(TO)[2] = (FROM)[2], \
(TO)[3] = (FROM)[3])
#define MAT3_SCALE_HVEC(RESULT_V,V,SCALE) \
MAT3_SET_HVEC(RESULT_V, (V)[0]*(SCALE), (V)[1]*(SCALE), \
(V)[2]*(SCALE), (V)[3]*(SCALE))
#define MAT3_ADD_HVEC(RESULT_V,V1,V2) \
MAT3_SET_HVEC(RESULT_V, (V1)[0]+(V2)[0], (V1)[1]+(V2)[1], \
(V1)[2]+(V2)[2], (V1)[3]+(V2)[3])
#define MAT3_SUB_HVEC(RESULT_V,V1,V2) \
MAT3_SET_HVEC(RESULT_V, (V1)[0]-(V2)[0], (V1)[1]-(V2)[1], \
(V1)[2]-(V2)[2], (V1)[3]-(V2)[3])
#define MAT3_MULT_HVEC(RESULT_V,V1,V2) \
MAT3_SET_HVEC(RESULT_V, (V1)[0]*(V2)[0], (V1)[1]*(V2)[1], \
(V1)[2]*(V2)[2], (V1)[3]*(V2)[3])
/* ------------------------------ Entries ------------------------------- */
/* In MAT3geom.c */
void MAT3direction_matrix (MAT3mat result_mat, MAT3mat mat);
int MAT3normal_matrix (MAT3mat result_mat, MAT3mat mat);
void MAT3rotate (MAT3mat result_mat, MAT3vec axis, double angle_in_radians);
void MAT3translate (MAT3mat result_mat, MAT3vec trans);
void MAT3scale (MAT3mat result_mat, MAT3vec scale);
void MAT3shear(MAT3mat result_mat, double xshear, double yshear);
/* In MAT3mat.c */
void MAT3identity(MAT3mat);
void MAT3zero(MAT3mat);
void MAT3copy (MAT3mat to, MAT3mat from);
void MAT3mult (MAT3mat result, MAT3mat, MAT3mat);
void MAT3transpose (MAT3mat result, MAT3mat);
int MAT3invert (MAT3mat result, MAT3mat);
void MAT3print (MAT3mat, FILE *fp);
void MAT3print_formatted (MAT3mat, FILE *fp,
char *title, char *head, char *format, char *tail);
extern int MAT3equal( void );
extern double MAT3trace( void );
extern int MAT3power( void );
extern int MAT3column_reduce( void );
extern int MAT3kernel_basis( void );
/* In MAT3vec.c */
void MAT3mult_vec(MAT3vec result_vec, MAT3vec vec, MAT3mat mat);
int MAT3mult_hvec (MAT3hvec result_vec, MAT3hvec vec, MAT3mat mat, int normalize);
void MAT3cross_product(MAT3vec result,MAT3vec,MAT3vec);
void MAT3perp_vec(MAT3vec result_vec, MAT3vec vec, int is_unit);
#endif /* MAT3_HAS_BEEN_INCLUDED */

View file

@ -1,128 +0,0 @@
/**************************************************************************
* polar.c -- routines to deal with polar math and transformations
*
* Written by Curtis Olson, started June 1997.
*
* Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id$
* (Log is kept at end of this file)
**************************************************************************/
#include <math.h>
#include <stdio.h>
#include <Include/fg_constants.h>
#include "polar.h"
/* we can save these values between calls for efficiency */
static double st, ct, sp, cp;
/* Convert a polar coordinate to a cartesian coordinate. Lon and Lat
* must be specified in radians. The FG convention is for distances
* to be specified in meters */
struct fgCartesianPoint fgPolarToCart(double lon, double lat, double radius) {
struct fgCartesianPoint pnew;
pnew.x = cos(lon) * cos(lat) * radius;
pnew.y = sin(lon) * cos(lat) * radius;
pnew.z = sin(lat) * radius;
return(pnew);
}
/* Precalculate as much as possible so we can do a batch of transforms
* through the same angles, will rotates a cartesian point about the
* center of the earth by Theta (longitude axis) and Phi (latitude
* axis) */
/* Here are the unoptimized transformation equations
x' = cos(Phi) * cos(Theta) * x + cos(Phi) * sin(Theta) * y +
sin(Phi) * z
y' = -sin(Theta) * x + cos(Theta) * y
z' = -sin(Phi) * sin(Theta) * y - sin(Phi) * cos(Theta) * x +
cos(Phi) * z;
*/
void fgRotateBatchInit(double Theta, double Phi) {
printf("Theta = %.3f, Phi = %.3f\n", Theta, Phi);
st = sin(Theta);
ct = cos(Theta);
sp = sin(-Phi);
cp = cos(-Phi);
}
/* Rotates a cartesian point about the center of the earth by Theta
* (longitude axis) and Phi (latitude axis) */
struct fgCartesianPoint fgRotateCartesianPoint(struct fgCartesianPoint p) {
struct fgCartesianPoint p1, p2;
/* printf("start = %.3f %.3f %.3f\n", p.x, p.y, p.z); */
/* rotate about the z axis */
p1.x = ct * p.x - st * p.y;
p1.y = st * p.x + ct * p.y;
p1.z = p.z;
/* printf("step 1 = %.3f %.3f %.3f\n", p1.x, p1.y, p1.z); */
/* rotate new point about y axis */
p2.x = cp * p1.x + sp * p1.z;
p2.y = p1.y;
p2.z = cp * p1.z - sp * p1.x;
/* printf("cp = %.5f, sp = %.5f\n", cp, sp); */
/* printf("(1) = %.5f, (2) = %.5f\n", cp * p1.z, sp * p1.x); */
/* printf("step 2 = %.3f %.3f %.3f\n", p2.x, p2.y, p2.z); */
return(p2);
}
/* $Log$
/* Revision 1.2 1998/04/14 02:26:07 curt
/* Code reorganizations. Added a Lib/ directory for more general libraries.
/*
* Revision 1.1 1998/04/08 23:21:12 curt
* Adopted Gnu automake/autoconf system.
*
* Revision 1.5 1998/01/27 00:48:00 curt
* Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
* system and commandline/config file processing code.
*
* Revision 1.4 1998/01/19 19:27:12 curt
* Merged in make system changes from Bob Kuehne <rpk@sgi.com>
* This should simplify things tremendously.
*
* Revision 1.3 1997/12/15 23:54:54 curt
* Add xgl wrappers for debugging.
* Generate terrain normals on the fly.
*
* Revision 1.2 1997/07/31 22:52:27 curt
* Working on redoing internal coordinate systems & scenery transformations.
*
* Revision 1.1 1997/07/07 21:02:36 curt
* Initial revision.
* */

View file

@ -1,93 +0,0 @@
/**************************************************************************
* polar.h -- routines to deal with polar math and transformations
*
* Written by Curtis Olson, started June 1997.
*
* Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id$
* (Log is kept at end of this file)
**************************************************************************/
#ifndef _POLAR_H
#define _POLAR_H
#include <Include/fg_types.h>
/* Convert a polar coordinate to a cartesian coordinate. Lon and Lat
* must be specified in radians. The FG convention is for distances
* to be specified in meters */
struct fgCartesianPoint fgPolarToCart(double lon, double lat, double radius);
/* Precalculate as much as possible so we can do a batch of transforms
* through the same angles, will rotates a cartesian point about the
* center of the earth by Theta (longitude axis) and Phi (latitude
* axis) */
/* Here are the unoptimized transformation equations
x' = cos(Phi) * cos(Theta) * x + cos(Phi) * sin(Theta) * y +
sin(Phi) * z
y' = -sin(Theta) * x + cos(Theta) * y
z' = -sin(Phi) * sin(Theta) * y - sin(Phi) * cos(Theta) * x +
cos(Phi) * z;
*/
void fgRotateBatchInit(double Theta, double Phi);
/* Rotates a cartesian point about the center of the earth by Theta
* (longitude axis) and Phi (latitude axis) */
struct fgCartesianPoint fgRotateCartesianPoint(struct fgCartesianPoint p);
#endif /* _POLAR_H */
/* $Log$
/* Revision 1.1 1998/04/08 23:21:13 curt
/* Adopted Gnu automake/autoconf system.
/*
* Revision 1.7 1998/01/27 00:48:00 curt
* Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
* system and commandline/config file processing code.
*
* Revision 1.6 1998/01/22 02:59:39 curt
* Changed #ifdef FILE_H to #ifdef _FILE_H
*
* Revision 1.5 1998/01/19 19:27:13 curt
* Merged in make system changes from Bob Kuehne <rpk@sgi.com>
* This should simplify things tremendously.
*
* Revision 1.4 1997/12/15 23:54:55 curt
* Add xgl wrappers for debugging.
* Generate terrain normals on the fly.
*
* Revision 1.3 1997/07/31 22:52:28 curt
* Working on redoing internal coordinate systems & scenery transformations.
*
* Revision 1.2 1997/07/23 21:52:21 curt
* Put comments around the text after an #endif for increased portability.
*
* Revision 1.1 1997/07/07 21:02:37 curt
* Initial revision.
*
*/

View file

@ -38,9 +38,9 @@
#include <Include/fg_types.h>
#include <Bucket/bucketutils.h>
#include "fg_geodesy.h"
#include "mat3.h"
#include "polar.h"
#include <Math/fg_geodesy.h>
#include <Math/mat3.h>
#include <Math/polar.h>
int nodecount, tricount;
double xmin, xmax, ymin, ymax;
@ -612,9 +612,12 @@ int main(int argc, char **argv) {
/* $Log$
/* Revision 1.8 1998/04/14 02:26:08 curt
/* Code reorganizations. Added a Lib/ directory for more general libraries.
/* Revision 1.9 1998/04/18 04:01:20 curt
/* Now use libMath rather than having local copies of math routines.
/*
* Revision 1.8 1998/04/14 02:26:08 curt
* Code reorganizations. Added a Lib/ directory for more general libraries.
*
* Revision 1.7 1998/04/08 23:21:13 curt
* Adopted Gnu automake/autoconf system.
*

View file

@ -1,149 +0,0 @@
/* Copyright 1988, Brown Computer Graphics Group. All Rights Reserved. */
/* --------------------------------------------------------------------------
* This file contains routines that operate on matrices and vectors, or
* vectors and vectors.
* -------------------------------------------------------------------------*/
/* #include "sphigslocal.h" */
/* -------------------------- Static Routines ---------------------------- */
/* ------------------------- Internal Routines --------------------------- */
/* -------------------------- Public Routines ---------------------------- */
/*
* Multiplies a vector by a matrix, setting the result vector.
* It assumes all homogeneous coordinates are 1.
* The two vectors involved may be the same.
*/
#include "mat3.h"
#ifndef TRUE
# define TRUE 1
#endif
#ifndef FALSE
# define FALSE 0
#endif
void
MAT3mult_vec(double *result_vec, register double *vec, register double (*mat)[4])
{
MAT3vec tempvec;
register double *temp = tempvec;
temp[0] = vec[0] * mat[0][0] + vec[1] * mat[1][0] +
vec[2] * mat[2][0] + mat[3][0];
temp[1] = vec[0] * mat[0][1] + vec[1] * mat[1][1] +
vec[2] * mat[2][1] + mat[3][1];
temp[2] = vec[0] * mat[0][2] + vec[1] * mat[1][2] +
vec[2] * mat[2][2] + mat[3][2];
MAT3_COPY_VEC(result_vec, temp);
}
/*
* Multiplies a vector of size 4 by a matrix, setting the result vector.
* The fourth element of the vector is the homogeneous coordinate, which
* may or may not be 1. If the "normalize" parameter is TRUE, then the
* result vector will be normalized so that the homogeneous coordinate is 1.
* The two vectors involved may be the same.
* This returns zero if the vector was to be normalized, but couldn't be.
*/
int
MAT3mult_hvec(double *result_vec, register double *vec, register double (*mat)[4], int normalize)
{
MAT3hvec tempvec;
double norm_fac;
register double *temp = tempvec;
register int ret = TRUE;
temp[0] = vec[0] * mat[0][0] + vec[1] * mat[1][0] +
vec[2] * mat[2][0] + vec[3] * mat[3][0];
temp[1] = vec[0] * mat[0][1] + vec[1] * mat[1][1] +
vec[2] * mat[2][1] + vec[3] * mat[3][1];
temp[2] = vec[0] * mat[0][2] + vec[1] * mat[1][2] +
vec[2] * mat[2][2] + vec[3] * mat[3][2];
temp[3] = vec[0] * mat[0][3] + vec[1] * mat[1][3] +
vec[2] * mat[2][3] + vec[3] * mat[3][3];
/* Normalize if asked for, possible, and necessary */
if (normalize) {
if (MAT3_IS_ZERO(temp[3])) {
#ifndef THINK_C
fprintf (stderr,
"Can't normalize vector: homogeneous coordinate is 0");
#endif
ret = FALSE;
}
else {
norm_fac = 1.0 / temp[3];
MAT3_SCALE_VEC(result_vec, temp, norm_fac);
result_vec[3] = 1.0;
}
}
else MAT3_COPY_HVEC(result_vec, temp);
return(ret);
}
/*
* Sets the first vector to be the cross-product of the last two vectors.
*/
void
MAT3cross_product(double *result_vec, register double *vec1, register double *vec2)
{
MAT3vec tempvec;
register double *temp = tempvec;
temp[0] = vec1[1] * vec2[2] - vec1[2] * vec2[1];
temp[1] = vec1[2] * vec2[0] - vec1[0] * vec2[2];
temp[2] = vec1[0] * vec2[1] - vec1[1] * vec2[0];
MAT3_COPY_VEC(result_vec, temp);
}
/*
* Finds a vector perpendicular to vec and stores it in result_vec.
* Method: take any vector (we use <0,1,0>) and subtract the
* portion of it pointing in the vec direction. This doesn't
* work if vec IS <0,1,0> or is very near it. So if this is
* the case, use <0,0,1> instead.
* If "is_unit" is TRUE, the given vector is assumed to be unit length.
*/
#define SELECT .7071 /* selection constant (roughly .5*sqrt(2) */
void
MAT3perp_vec(double *result_vec, double *vec, int is_unit)
{
MAT3vec norm;
double dot;
MAT3_SET_VEC(result_vec, 0.0, 1.0, 0.0);
MAT3_COPY_VEC(norm, vec);
if (! is_unit) MAT3_NORMALIZE_VEC(norm, dot);
/* See if vector is too close to <0,1,0>. If so, use <0,0,1> */
if ((dot = MAT3_DOT_PRODUCT(norm, result_vec)) > SELECT || dot < -SELECT) {
result_vec[1] = 0.0;
result_vec[2] = 1.0;
dot = MAT3_DOT_PRODUCT(norm, result_vec);
}
/* Subtract off non-perpendicular part */
result_vec[0] -= dot * norm[0];
result_vec[1] -= dot * norm[1];
result_vec[2] -= dot * norm[2];
/* Make result unit length */
MAT3_NORMALIZE_VEC(result_vec, dot);
}

View file

@ -26,21 +26,20 @@
bin_PROGRAMS = tri2obj
tri2obj_SOURCES = \
tri2obj.c tri2obj.h \
MAT3vec.c \
fg_geodesy.c fg_geodesy.h \
mat3.h \
polar.c polar.h
tri2obj_SOURCES = tri2obj.c tri2obj.h
tri2obj_LDADD = \
$(top_builddir)/Lib/Bucket/libBucket.la
$(top_builddir)/Lib/Bucket/libBucket.la \
$(top_builddir)/Lib/Math/libMath.la
INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib
#---------------------------------------------------------------------------
# $Log$
# Revision 1.3 1998/04/18 04:01:29 curt
# Now use libMath rather than having local copies of math routines.
#
# Revision 1.2 1998/04/14 02:26:09 curt
# Code reorganizations. Added a Lib/ directory for more general libraries.
#

View file

@ -98,15 +98,11 @@ VERSION = @VERSION@
bin_PROGRAMS = tri2obj
tri2obj_SOURCES = \
tri2obj.c tri2obj.h \
MAT3vec.c \
fg_geodesy.c fg_geodesy.h \
mat3.h \
polar.c polar.h
tri2obj_SOURCES = tri2obj.c tri2obj.h
tri2obj_LDADD = \
$(top_builddir)/Lib/Bucket/libBucket.la
$(top_builddir)/Lib/Bucket/libBucket.la \
$(top_builddir)/Lib/Math/libMath.la
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = ../../Include/config.h
CONFIG_CLEAN_FILES =
@ -121,8 +117,9 @@ X_CFLAGS = @X_CFLAGS@
X_LIBS = @X_LIBS@
X_EXTRA_LIBS = @X_EXTRA_LIBS@
X_PRE_LIBS = @X_PRE_LIBS@
tri2obj_OBJECTS = tri2obj.o MAT3vec.o fg_geodesy.o polar.o
tri2obj_DEPENDENCIES = $(top_builddir)/Lib/Bucket/libBucket.la
tri2obj_OBJECTS = tri2obj.o
tri2obj_DEPENDENCIES = $(top_builddir)/Lib/Bucket/libBucket.la \
$(top_builddir)/Lib/Math/libMath.la
tri2obj_LDFLAGS =
CFLAGS = @CFLAGS@
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
@ -135,8 +132,7 @@ DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = tar
GZIP = --best
DEP_FILES = .deps/MAT3vec.P .deps/fg_geodesy.P .deps/polar.P \
.deps/tri2obj.P
DEP_FILES = .deps/tri2obj.P
SOURCES = $(tri2obj_SOURCES)
OBJECTS = $(tri2obj_OBJECTS)
@ -350,7 +346,10 @@ INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib
#---------------------------------------------------------------------------
# $Log$
# Revision 1.2 1998/04/14 02:26:10 curt
# Revision 1.3 1998/04/18 04:01:29 curt
# Now use libMath rather than having local copies of math routines.
#
# Revision 1.2 1998/04/14 02:26:09 curt
# Code reorganizations. Added a Lib/ directory for more general libraries.
#
# Revision 1.1 1998/04/08 23:22:13 curt

View file

@ -1,230 +0,0 @@
/**************************************************************************
* fg_geodesy.c -- routines to convert between geodetic and geocentric
* coordinate systems.
*
* Copied and adapted directly from LaRCsim/ls_geodesy.c
*
* See below for the complete original LaRCsim comments.
*
* $Id$
* (Log is kept at end of this file)
**************************************************************************/
#include <math.h>
#include <Include/fg_constants.h>
#include "fg_geodesy.h"
/* ONE_SECOND is pi/180/60/60, or about 100 feet at earths' equator */
#define ONE_SECOND 4.848136811E-6
/* fgGeocToGeod(lat_geoc, radius, *lat_geod, *alt, *sea_level_r)
* INPUTS:
* lat_geoc Geocentric latitude, radians, + = North
* radius C.G. radius to earth center, ft
*
* OUTPUTS:
* lat_geod Geodetic latitude, radians, + = North
* alt C.G. altitude above mean sea level, ft
* sea_level_r radius from earth center to sea level at
* local vertical (surface normal) of C.G.
*/
void fgGeocToGeod( double lat_geoc, double radius, double
*lat_geod, double *alt, double *sea_level_r )
{
double t_lat, x_alpha, mu_alpha, delt_mu, r_alpha, l_point, rho_alpha;
double sin_mu_a, denom,delt_lambda, lambda_sl, sin_lambda_sl;
if( ( (FG_PI_2 - lat_geoc) < ONE_SECOND ) /* near North pole */
|| ( (FG_PI_2 + lat_geoc) < ONE_SECOND ) ) /* near South pole */
{
*lat_geod = lat_geoc;
*sea_level_r = EQUATORIAL_RADIUS_KM*E;
*alt = radius - *sea_level_r;
} else {
t_lat = tan(lat_geoc);
x_alpha = E*EQUATORIAL_RADIUS_KM/sqrt(t_lat*t_lat + E*E);
mu_alpha = atan2(sqrt(RESQ_KM - x_alpha*x_alpha),E*x_alpha);
if (lat_geoc < 0) mu_alpha = - mu_alpha;
sin_mu_a = sin(mu_alpha);
delt_lambda = mu_alpha - lat_geoc;
r_alpha = x_alpha/cos(lat_geoc);
l_point = radius - r_alpha;
*alt = l_point*cos(delt_lambda);
denom = sqrt(1-EPS*EPS*sin_mu_a*sin_mu_a);
rho_alpha = EQUATORIAL_RADIUS_KM*(1-EPS)/
(denom*denom*denom);
delt_mu = atan2(l_point*sin(delt_lambda),rho_alpha + *alt);
*lat_geod = mu_alpha - delt_mu;
lambda_sl = atan( E*E * tan(*lat_geod) ); /* SL geoc. latitude */
sin_lambda_sl = sin( lambda_sl );
*sea_level_r =
sqrt(RESQ_KM / (1 + ((1/(E*E))-1)*sin_lambda_sl*sin_lambda_sl));
}
}
/* fgGeodToGeoc( lat_geod, alt, *sl_radius, *lat_geoc )
* INPUTS:
* lat_geod Geodetic latitude, radians, + = North
* alt C.G. altitude above mean sea level, ft
*
* OUTPUTS:
* sl_radius SEA LEVEL radius to earth center, ft (add Altitude to
* get true distance from earth center.
* lat_geoc Geocentric latitude, radians, + = North
*
*/
void fgGeodToGeoc( double lat_geod, double alt, double *sl_radius,
double *lat_geoc )
{
double lambda_sl, sin_lambda_sl, cos_lambda_sl, sin_mu, cos_mu, px, py;
lambda_sl = atan( E*E * tan(lat_geod) ); /* sea level geocentric latitude */
sin_lambda_sl = sin( lambda_sl );
cos_lambda_sl = cos( lambda_sl );
sin_mu = sin(lat_geod); /* Geodetic (map makers') latitude */
cos_mu = cos(lat_geod);
*sl_radius =
sqrt(RESQ_KM / (1 + ((1/(E*E))-1)*sin_lambda_sl*sin_lambda_sl));
py = *sl_radius*sin_lambda_sl + alt*sin_mu;
px = *sl_radius*cos_lambda_sl + alt*cos_mu;
*lat_geoc = atan2( py, px );
}
/***************************************************************************
TITLE: ls_geodesy
----------------------------------------------------------------------------
FUNCTION: Converts geocentric coordinates to geodetic positions
----------------------------------------------------------------------------
MODULE STATUS: developmental
----------------------------------------------------------------------------
GENEALOGY: Written as part of LaRCSim project by E. B. Jackson
----------------------------------------------------------------------------
DESIGNED BY: E. B. Jackson
CODED BY: E. B. Jackson
MAINTAINED BY: E. B. Jackson
----------------------------------------------------------------------------
MODIFICATION HISTORY:
DATE PURPOSE BY
930208 Modified to avoid singularity near polar region. EBJ
930602 Moved backwards calcs here from ls_step. EBJ
931214 Changed erroneous Latitude and Altitude variables to
*lat_geod and *alt in routine ls_geoc_to_geod. EBJ
940111 Changed header files from old ls_eom.h style to ls_types,
and ls_constants. Also replaced old DATA type with new
SCALAR type. EBJ
CURRENT RCS HEADER:
$Header$
$Log$
Revision 1.1 1998/04/08 23:22:14 curt
Adopted Gnu automake/autoconf system.
Revision 1.4 1998/01/27 00:47:59 curt
Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
system and commandline/config file processing code.
Revision 1.3 1998/01/19 19:27:12 curt
Merged in make system changes from Bob Kuehne <rpk@sgi.com>
This should simplify things tremendously.
Revision 1.2 1997/12/15 23:54:54 curt
Add xgl wrappers for debugging.
Generate terrain normals on the fly.
Revision 1.1 1997/07/31 23:13:14 curt
Initial revision.
Revision 1.1 1997/05/29 00:09:56 curt
Initial Flight Gear revision.
* Revision 1.5 1994/01/11 18:47:05 bjax
* Changed include files to use types and constants, not ls_eom.h
* Also changed DATA type to SCALAR type.
*
* Revision 1.4 1993/12/14 21:06:47 bjax
* Removed global variable references Altitude and Latitude. EBJ
*
* Revision 1.3 1993/06/02 15:03:40 bjax
* Made new subroutine for calculating geodetic to geocentric; changed name
* of forward conversion routine from ls_geodesy to ls_geoc_to_geod.
*
----------------------------------------------------------------------------
REFERENCES:
[ 1] Stevens, Brian L.; and Lewis, Frank L.: "Aircraft
Control and Simulation", Wiley and Sons, 1992.
ISBN 0-471-61397-5
----------------------------------------------------------------------------
CALLED BY: ls_aux
----------------------------------------------------------------------------
CALLS TO:
----------------------------------------------------------------------------
INPUTS:
lat_geoc Geocentric latitude, radians, + = North
radius C.G. radius to earth center, ft
----------------------------------------------------------------------------
OUTPUTS:
lat_geod Geodetic latitude, radians, + = North
alt C.G. altitude above mean sea level, ft
sea_level_r radius from earth center to sea level at
local vertical (surface normal) of C.G.
--------------------------------------------------------------------------*/
/* $Log$
/* Revision 1.1 1998/04/08 23:22:14 curt
/* Adopted Gnu automake/autoconf system.
/*
* Revision 1.4 1998/01/27 00:47:59 curt
* Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
* system and commandline/config file processing code.
*
* Revision 1.3 1998/01/19 19:27:12 curt
* Merged in make system changes from Bob Kuehne <rpk@sgi.com>
* This should simplify things tremendously.
*
* Revision 1.2 1997/12/15 23:54:54 curt
* Add xgl wrappers for debugging.
* Generate terrain normals on the fly.
*
* Revision 1.1 1997/07/31 23:13:14 curt
* Initial revision.
*
*/

View file

@ -1,163 +0,0 @@
/**************************************************************************
* fg_geodesy.h -- routines to convert between geodetic and geocentric
* coordinate systems.
*
* Copied and adapted directly from LaRCsim/ls_geodesy.c
*
* See below for the complete original LaRCsim comments.
*
* $Id$
* (Log is kept at end of this file)
**************************************************************************/
#ifndef _FG_GEODESY_H
#define _FG_GEODESY_H
/* fgGeocToGeod(lat_geoc, radius, *lat_geod, *alt, *sea_level_r)
* INPUTS:
* lat_geoc Geocentric latitude, radians, + = North
* radius C.G. radius to earth center, ft
*
* OUTPUTS:
* lat_geod Geodetic latitude, radians, + = North
* alt C.G. altitude above mean sea level, ft
* sea_level_r radius from earth center to sea level at
* local vertical (surface normal) of C.G.
*/
void fgGeocToGeod( double lat_geoc, double radius, double
*lat_geod, double *alt, double *sea_level_r );
/* fgGeodToGeoc( lat_geod, alt, *sl_radius, *lat_geoc )
* INPUTS:
* lat_geod Geodetic latitude, radians, + = North
* alt C.G. altitude above mean sea level, ft
*
* OUTPUTS:
* sl_radius SEA LEVEL radius to earth center, ft (add Altitude to
* get true distance from earth center.
* lat_geoc Geocentric latitude, radians, + = North
*
*/
void fgGeodToGeoc( double lat_geod, double alt, double *sl_radius,
double *lat_geoc );
/***************************************************************************
TITLE: ls_geodesy
----------------------------------------------------------------------------
FUNCTION: Converts geocentric coordinates to geodetic positions
----------------------------------------------------------------------------
MODULE STATUS: developmental
----------------------------------------------------------------------------
GENEALOGY: Written as part of LaRCSim project by E. B. Jackson
----------------------------------------------------------------------------
DESIGNED BY: E. B. Jackson
CODED BY: E. B. Jackson
MAINTAINED BY: E. B. Jackson
----------------------------------------------------------------------------
MODIFICATION HISTORY:
DATE PURPOSE BY
930208 Modified to avoid singularity near polar region. EBJ
930602 Moved backwards calcs here from ls_step. EBJ
931214 Changed erroneous Latitude and Altitude variables to
*lat_geod and *alt in routine ls_geoc_to_geod. EBJ
940111 Changed header files from old ls_eom.h style to ls_types,
and ls_constants. Also replaced old DATA type with new
SCALAR type. EBJ
CURRENT RCS HEADER:
$Header$
$Log$
Revision 1.1 1998/04/08 23:22:15 curt
Adopted Gnu automake/autoconf system.
Revision 1.2 1998/01/22 02:59:38 curt
Changed #ifdef FILE_H to #ifdef _FILE_H
Revision 1.1 1997/07/31 23:13:14 curt
Initial revision.
Revision 1.1 1997/05/29 00:09:56 curt
Initial Flight Gear revision.
* Revision 1.5 1994/01/11 18:47:05 bjax
* Changed include files to use types and constants, not ls_eom.h
* Also changed DATA type to SCALAR type.
*
* Revision 1.4 1993/12/14 21:06:47 bjax
* Removed global variable references Altitude and Latitude. EBJ
*
* Revision 1.3 1993/06/02 15:03:40 bjax
* Made new subroutine for calculating geodetic to geocentric; changed name
* of forward conversion routine from ls_geodesy to ls_geoc_to_geod.
*
----------------------------------------------------------------------------
REFERENCES:
[ 1] Stevens, Brian L.; and Lewis, Frank L.: "Aircraft
Control and Simulation", Wiley and Sons, 1992.
ISBN 0-471-61397-5
----------------------------------------------------------------------------
CALLED BY: ls_aux
----------------------------------------------------------------------------
CALLS TO:
----------------------------------------------------------------------------
INPUTS:
lat_geoc Geocentric latitude, radians, + = North
radius C.G. radius to earth center, ft
----------------------------------------------------------------------------
OUTPUTS:
lat_geod Geodetic latitude, radians, + = North
alt C.G. altitude above mean sea level, ft
sea_level_r radius from earth center to sea level at
local vertical (surface normal) of C.G.
--------------------------------------------------------------------------*/
#endif /* _FG_GEODESY_H */
/* $Log$
/* Revision 1.1 1998/04/08 23:22:15 curt
/* Adopted Gnu automake/autoconf system.
/*
* Revision 1.2 1998/01/22 02:59:38 curt
* Changed #ifdef FILE_H to #ifdef _FILE_H
*
* Revision 1.1 1997/07/31 23:13:14 curt
* Initial revision.
*
*/

View file

@ -1,147 +0,0 @@
/* Copyright 1988, Brown Computer Graphics Group. All Rights Reserved. */
/* -------------------------------------------------------------------------
Public MAT3 include file
------------------------------------------------------------------------- */
#ifndef MAT3_HAS_BEEN_INCLUDED
#define MAT3_HAS_BEEN_INCLUDED
/* ----------------------------- Constants ------------------------------ */
/*
* Make sure the math library .h file is included, in case it wasn't.
*/
#ifndef HUGE
#include <math.h>
#endif
#include <stdio.h>
#define MAT3_DET0 -1 /* Indicates singular mat */
#define MAT3_EPSILON 1e-12 /* Close enough to zero */
#define MAT3_PI 3.141592653589793 /* Pi */
/* ------------------------------ Types --------------------------------- */
typedef double MAT3mat[4][4]; /* 4x4 matrix */
typedef double MAT3vec[3]; /* Vector */
typedef double MAT3hvec[4]; /* Vector with homogeneous coord */
/* ------------------------------ Macros -------------------------------- */
/* Tests if a number is within EPSILON of zero */
#define MAT3_IS_ZERO(N) ((N) < MAT3_EPSILON && (N) > -MAT3_EPSILON)
/* Sets a vector to the three given values */
#define MAT3_SET_VEC(V,X,Y,Z) ((V)[0]=(X), (V)[1]=(Y), (V)[2]=(Z))
/* Tests a vector for all components close to zero */
#define MAT3_IS_ZERO_VEC(V) (MAT3_IS_ZERO((V)[0]) && \
MAT3_IS_ZERO((V)[1]) && \
MAT3_IS_ZERO((V)[2]))
/* Dot product of two vectors */
#define MAT3_DOT_PRODUCT(V1,V2) \
((V1)[0]*(V2)[0] + (V1)[1]*(V2)[1] + (V1)[2]*(V2)[2])
/* Copy one vector to other */
#define MAT3_COPY_VEC(TO,FROM) ((TO)[0] = (FROM)[0], \
(TO)[1] = (FROM)[1], \
(TO)[2] = (FROM)[2])
/* Normalize vector to unit length, using TEMP as temporary variable.
* TEMP will be zero if vector has zero length */
#define MAT3_NORMALIZE_VEC(V,TEMP) \
if ((TEMP = sqrt(MAT3_DOT_PRODUCT(V,V))) > MAT3_EPSILON) { \
TEMP = 1.0 / TEMP; \
MAT3_SCALE_VEC(V,V,TEMP); \
} else TEMP = 0.0
/* Scale vector by given factor, storing result vector in RESULT_V */
#define MAT3_SCALE_VEC(RESULT_V,V,SCALE) \
MAT3_SET_VEC(RESULT_V, (V)[0]*(SCALE), (V)[1]*(SCALE), (V)[2]*(SCALE))
/* Adds vectors V1 and V2, storing result in RESULT_V */
#define MAT3_ADD_VEC(RESULT_V,V1,V2) \
MAT3_SET_VEC(RESULT_V, (V1)[0]+(V2)[0], (V1)[1]+(V2)[1], \
(V1)[2]+(V2)[2])
/* Subtracts vector V2 from V1, storing result in RESULT_V */
#define MAT3_SUB_VEC(RESULT_V,V1,V2) \
MAT3_SET_VEC(RESULT_V, (V1)[0]-(V2)[0], (V1)[1]-(V2)[1], \
(V1)[2]-(V2)[2])
/* Multiplies vectors V1 and V2, storing result in RESULT_V */
#define MAT3_MULT_VEC(RESULT_V,V1,V2) \
MAT3_SET_VEC(RESULT_V, (V1)[0]*(V2)[0], (V1)[1]*(V2)[1], \
(V1)[2]*(V2)[2])
/* Sets RESULT_V to the linear combination of V1 and V2, scaled by
* SCALE1 and SCALE2, respectively */
#define MAT3_LINEAR_COMB(RESULT_V,SCALE1,V1,SCALE2,V2) \
MAT3_SET_VEC(RESULT_V, (SCALE1)*(V1)[0] + (SCALE2)*(V2)[0], \
(SCALE1)*(V1)[1] + (SCALE2)*(V2)[1], \
(SCALE1)*(V1)[2] + (SCALE2)*(V2)[2])
/* Several of the vector macros are useful for homogeneous-coord vectors */
#define MAT3_SET_HVEC(V,X,Y,Z,W) ((V)[0]=(X), (V)[1]=(Y), \
(V)[2]=(Z), (V)[3]=(W))
#define MAT3_COPY_HVEC(TO,FROM) ((TO)[0] = (FROM)[0], \
(TO)[1] = (FROM)[1], \
(TO)[2] = (FROM)[2], \
(TO)[3] = (FROM)[3])
#define MAT3_SCALE_HVEC(RESULT_V,V,SCALE) \
MAT3_SET_HVEC(RESULT_V, (V)[0]*(SCALE), (V)[1]*(SCALE), \
(V)[2]*(SCALE), (V)[3]*(SCALE))
#define MAT3_ADD_HVEC(RESULT_V,V1,V2) \
MAT3_SET_HVEC(RESULT_V, (V1)[0]+(V2)[0], (V1)[1]+(V2)[1], \
(V1)[2]+(V2)[2], (V1)[3]+(V2)[3])
#define MAT3_SUB_HVEC(RESULT_V,V1,V2) \
MAT3_SET_HVEC(RESULT_V, (V1)[0]-(V2)[0], (V1)[1]-(V2)[1], \
(V1)[2]-(V2)[2], (V1)[3]-(V2)[3])
#define MAT3_MULT_HVEC(RESULT_V,V1,V2) \
MAT3_SET_HVEC(RESULT_V, (V1)[0]*(V2)[0], (V1)[1]*(V2)[1], \
(V1)[2]*(V2)[2], (V1)[3]*(V2)[3])
/* ------------------------------ Entries ------------------------------- */
/* In MAT3geom.c */
void MAT3direction_matrix (MAT3mat result_mat, MAT3mat mat);
int MAT3normal_matrix (MAT3mat result_mat, MAT3mat mat);
void MAT3rotate (MAT3mat result_mat, MAT3vec axis, double angle_in_radians);
void MAT3translate (MAT3mat result_mat, MAT3vec trans);
void MAT3scale (MAT3mat result_mat, MAT3vec scale);
void MAT3shear(MAT3mat result_mat, double xshear, double yshear);
/* In MAT3mat.c */
void MAT3identity(MAT3mat);
void MAT3zero(MAT3mat);
void MAT3copy (MAT3mat to, MAT3mat from);
void MAT3mult (MAT3mat result, MAT3mat, MAT3mat);
void MAT3transpose (MAT3mat result, MAT3mat);
int MAT3invert (MAT3mat result, MAT3mat);
void MAT3print (MAT3mat, FILE *fp);
void MAT3print_formatted (MAT3mat, FILE *fp,
char *title, char *head, char *format, char *tail);
extern int MAT3equal( void );
extern double MAT3trace( void );
extern int MAT3power( void );
extern int MAT3column_reduce( void );
extern int MAT3kernel_basis( void );
/* In MAT3vec.c */
void MAT3mult_vec(MAT3vec result_vec, MAT3vec vec, MAT3mat mat);
int MAT3mult_hvec (MAT3hvec result_vec, MAT3hvec vec, MAT3mat mat, int normalize);
void MAT3cross_product(MAT3vec result,MAT3vec,MAT3vec);
void MAT3perp_vec(MAT3vec result_vec, MAT3vec vec, int is_unit);
#endif /* MAT3_HAS_BEEN_INCLUDED */

View file

@ -1,128 +0,0 @@
/**************************************************************************
* polar.c -- routines to deal with polar math and transformations
*
* Written by Curtis Olson, started June 1997.
*
* Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id$
* (Log is kept at end of this file)
**************************************************************************/
#include <math.h>
#include <stdio.h>
#include <Include/fg_constants.h>
#include "polar.h"
/* we can save these values between calls for efficiency */
static double st, ct, sp, cp;
/* Convert a polar coordinate to a cartesian coordinate. Lon and Lat
* must be specified in radians. The FG convention is for distances
* to be specified in meters */
struct fgCartesianPoint fgPolarToCart(double lon, double lat, double radius) {
struct fgCartesianPoint pnew;
pnew.x = cos(lon) * cos(lat) * radius;
pnew.y = sin(lon) * cos(lat) * radius;
pnew.z = sin(lat) * radius;
return(pnew);
}
/* Precalculate as much as possible so we can do a batch of transforms
* through the same angles, will rotates a cartesian point about the
* center of the earth by Theta (longitude axis) and Phi (latitude
* axis) */
/* Here are the unoptimized transformation equations
x' = cos(Phi) * cos(Theta) * x + cos(Phi) * sin(Theta) * y +
sin(Phi) * z
y' = -sin(Theta) * x + cos(Theta) * y
z' = -sin(Phi) * sin(Theta) * y - sin(Phi) * cos(Theta) * x +
cos(Phi) * z;
*/
void fgRotateBatchInit(double Theta, double Phi) {
printf("Theta = %.3f, Phi = %.3f\n", Theta, Phi);
st = sin(Theta);
ct = cos(Theta);
sp = sin(-Phi);
cp = cos(-Phi);
}
/* Rotates a cartesian point about the center of the earth by Theta
* (longitude axis) and Phi (latitude axis) */
struct fgCartesianPoint fgRotateCartesianPoint(struct fgCartesianPoint p) {
struct fgCartesianPoint p1, p2;
/* printf("start = %.3f %.3f %.3f\n", p.x, p.y, p.z); */
/* rotate about the z axis */
p1.x = ct * p.x - st * p.y;
p1.y = st * p.x + ct * p.y;
p1.z = p.z;
/* printf("step 1 = %.3f %.3f %.3f\n", p1.x, p1.y, p1.z); */
/* rotate new point about y axis */
p2.x = cp * p1.x + sp * p1.z;
p2.y = p1.y;
p2.z = cp * p1.z - sp * p1.x;
/* printf("cp = %.5f, sp = %.5f\n", cp, sp); */
/* printf("(1) = %.5f, (2) = %.5f\n", cp * p1.z, sp * p1.x); */
/* printf("step 2 = %.3f %.3f %.3f\n", p2.x, p2.y, p2.z); */
return(p2);
}
/* $Log$
/* Revision 1.2 1998/04/14 02:26:10 curt
/* Code reorganizations. Added a Lib/ directory for more general libraries.
/*
* Revision 1.1 1998/04/08 23:22:16 curt
* Adopted Gnu automake/autoconf system.
*
* Revision 1.5 1998/01/27 00:48:00 curt
* Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
* system and commandline/config file processing code.
*
* Revision 1.4 1998/01/19 19:27:12 curt
* Merged in make system changes from Bob Kuehne <rpk@sgi.com>
* This should simplify things tremendously.
*
* Revision 1.3 1997/12/15 23:54:54 curt
* Add xgl wrappers for debugging.
* Generate terrain normals on the fly.
*
* Revision 1.2 1997/07/31 22:52:27 curt
* Working on redoing internal coordinate systems & scenery transformations.
*
* Revision 1.1 1997/07/07 21:02:36 curt
* Initial revision.
* */

View file

@ -1,93 +0,0 @@
/**************************************************************************
* polar.h -- routines to deal with polar math and transformations
*
* Written by Curtis Olson, started June 1997.
*
* Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id$
* (Log is kept at end of this file)
**************************************************************************/
#ifndef _POLAR_H
#define _POLAR_H
#include <Include/fg_types.h>
/* Convert a polar coordinate to a cartesian coordinate. Lon and Lat
* must be specified in radians. The FG convention is for distances
* to be specified in meters */
struct fgCartesianPoint fgPolarToCart(double lon, double lat, double radius);
/* Precalculate as much as possible so we can do a batch of transforms
* through the same angles, will rotates a cartesian point about the
* center of the earth by Theta (longitude axis) and Phi (latitude
* axis) */
/* Here are the unoptimized transformation equations
x' = cos(Phi) * cos(Theta) * x + cos(Phi) * sin(Theta) * y +
sin(Phi) * z
y' = -sin(Theta) * x + cos(Theta) * y
z' = -sin(Phi) * sin(Theta) * y - sin(Phi) * cos(Theta) * x +
cos(Phi) * z;
*/
void fgRotateBatchInit(double Theta, double Phi);
/* Rotates a cartesian point about the center of the earth by Theta
* (longitude axis) and Phi (latitude axis) */
struct fgCartesianPoint fgRotateCartesianPoint(struct fgCartesianPoint p);
#endif /* _POLAR_H */
/* $Log$
/* Revision 1.1 1998/04/08 23:22:17 curt
/* Adopted Gnu automake/autoconf system.
/*
* Revision 1.7 1998/01/27 00:48:00 curt
* Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
* system and commandline/config file processing code.
*
* Revision 1.6 1998/01/22 02:59:39 curt
* Changed #ifdef FILE_H to #ifdef _FILE_H
*
* Revision 1.5 1998/01/19 19:27:13 curt
* Merged in make system changes from Bob Kuehne <rpk@sgi.com>
* This should simplify things tremendously.
*
* Revision 1.4 1997/12/15 23:54:55 curt
* Add xgl wrappers for debugging.
* Generate terrain normals on the fly.
*
* Revision 1.3 1997/07/31 22:52:28 curt
* Working on redoing internal coordinate systems & scenery transformations.
*
* Revision 1.2 1997/07/23 21:52:21 curt
* Put comments around the text after an #endif for increased portability.
*
* Revision 1.1 1997/07/07 21:02:37 curt
* Initial revision.
*
*/

View file

@ -36,9 +36,9 @@
#include <Include/fg_types.h>
#include <Bucket/bucketutils.h>
#include "fg_geodesy.h"
#include "mat3.h"
#include "polar.h"
#include <Math/fg_geodesy.h>
#include <Math/mat3.h>
#include <Math/polar.h>
int nodecount, tricount;
@ -640,9 +640,12 @@ int main(int argc, char **argv) {
/* $Log$
/* Revision 1.13 1998/04/14 02:26:11 curt
/* Code reorganizations. Added a Lib/ directory for more general libraries.
/* Revision 1.14 1998/04/18 04:01:32 curt
/* Now use libMath rather than having local copies of math routines.
/*
* Revision 1.13 1998/04/14 02:26:11 curt
* Code reorganizations. Added a Lib/ directory for more general libraries.
*
* Revision 1.12 1998/04/08 23:22:18 curt
* Adopted Gnu automake/autoconf system.
*