00001 //
00002 // localdef.h
00003 //
00004 // Copyright (C) 1996 Limit Point Systems, Inc.
00005 //
00006 // Author: Edward Seidl <seidl@janed.com>
00007 // Maintainer: LPS
00008 //
00009 // This file is part of the SC Toolkit.
00010 //
00011 // The SC Toolkit is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Library General Public License as published by
00013 // the Free Software Foundation; either version 2, or (at your option)
00014 // any later version.
00015 //
00016 // The SC Toolkit is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019 // GNU Library General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Library General Public License
00022 // along with the SC Toolkit; see the file COPYING.LIB. If not, write to
00023 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
00024 //
00025 // The U.S. Government is granted a limited license as per AL 91-7.
00026 //
00027
00028 // some inline functions for dealing with 3 dimensional vectors
00029
00030 #ifndef _localdef_h
00031 #define _localdef_h
00032
00033 #include <math.h>
00034
00035 static const double pi=3.14159265358979323846;
00036 static const double pih=1.57079632679489661923;
00037 static const double tpi=2.0*pi;
00038
00039 static const double bohr = 0.52917706;
00040
00041 // /////////////////////////////////////////////////////////
00042
00043 static inline void
00044 delta(double u[], const double a[], const double b[])
00045 {
00046 u[0]=a[0]-b[0];
00047 u[1]=a[1]-b[1];
00048 u[2]=a[2]-b[2];
00049 }
00050
00051 // /////////////////////////////////////////////////////////
00052
00053 // returns the distance between two points
00054 static inline double
00055 dist(const double a[], const double b[])
00056 {
00057 double x,y,z;
00058 return (sqrt((x=a[0]-b[0])*x + (y=a[1]-b[1])*y + (z=a[2]-b[2])*z));
00059 }
00060
00061 // /////////////////////////////////////////////////////////
00062
00063 // given sin(x) returns cos(x)
00064 static inline double
00065 s2(double x)
00066 {
00067 double tmp = 1.0 - x*x;
00068 if (tmp < 0.0) tmp = 0.0;
00069 return sqrt(tmp);
00070 }
00071
00072 // /////////////////////////////////////////////////////////
00073
00074 // returns the dot product for two vectors
00075 static inline double
00076 scalar(const double a[], const double b[])
00077 {
00078 double x = a[0]*b[0];
00079 double x1 = a[1]*b[1];
00080 x += a[2]*b[2];
00081 return x+x1;
00082 }
00083
00084 // /////////////////////////////////////////////////////////
00085
00086 // given vectors a and b, returns a unit vector directed along the difference
00087 // of the two vectors
00088 static inline void
00089 norm(double u[], const double a[], const double b[])
00090 {
00091 delta(u,a,b);
00092 double x = 1.0/sqrt(scalar(u,u));
00093 u[0] *= x; u[1] *= x; u[2] *= x;
00094 }
00095
00096 // /////////////////////////////////////////////////////////
00097
00098 // given two vectors, returns the normalized cross product of those vectors
00099 static inline void
00100 normal(const double a[], const double b[], double w[])
00101 {
00102 w[0] = a[1]*b[2]-a[2]*b[1];
00103 w[1] = a[2]*b[0]-a[0]*b[2];
00104 w[2] = a[0]*b[1]-a[1]*b[0];
00105 double x = 1.0/sqrt(scalar(w,w));
00106 w[0] *= x; w[1] *= x; w[2] *= x;
00107 }
00108
00109 #endif
00110
00111 // Local Variables:
00112 // mode: c++
00113 // c-file-style: "ETS"
00114 // End: