MPQC  2.3.1
localdef.h
1 //
2 // localdef.h
3 //
4 // Copyright (C) 1996 Limit Point Systems, Inc.
5 //
6 // Author: Edward Seidl <seidl@janed.com>
7 // Maintainer: LPS
8 //
9 // This file is part of the SC Toolkit.
10 //
11 // The SC Toolkit is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU Library General Public License as published by
13 // the Free Software Foundation; either version 2, or (at your option)
14 // any later version.
15 //
16 // The SC Toolkit is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU Library General Public License for more details.
20 //
21 // You should have received a copy of the GNU Library General Public License
22 // along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 //
25 // The U.S. Government is granted a limited license as per AL 91-7.
26 //
27 
28 // some inline functions for dealing with 3 dimensional vectors
29 
30 #ifndef _localdef_h
31 #define _localdef_h
32 
33 #include <math.h>
34 
35 namespace sc {
36 
37 static const double pi=M_PI;
38 static const double pih=M_PI_2;
39 static const double tpi=2.0*pi;
40 
41 static const double bohr = 0.52917706;
42 
43 // /////////////////////////////////////////////////////////
44 
45 static inline void
46 delta(double u[], const double a[], const double b[])
47 {
48  u[0]=a[0]-b[0];
49  u[1]=a[1]-b[1];
50  u[2]=a[2]-b[2];
51 }
52 
53 // /////////////////////////////////////////////////////////
54 
55 // returns the distance between two points
56 static inline double
57 dist(const double a[], const double b[])
58 {
59  double x,y,z;
60  return (sqrt((x=a[0]-b[0])*x + (y=a[1]-b[1])*y + (z=a[2]-b[2])*z));
61 }
62 
63 // /////////////////////////////////////////////////////////
64 
65 // given sin(x) returns cos(x)
66 static inline double
67 s2(double x)
68 {
69  double tmp = 1.0 - x*x;
70  if (tmp < 0.0) tmp = 0.0;
71  return sqrt(tmp);
72 }
73 
74 // /////////////////////////////////////////////////////////
75 
76 // returns the dot product for two vectors
77 static inline double
78 scalar(const double a[], const double b[])
79 {
80  double x = a[0]*b[0];
81  double x1 = a[1]*b[1];
82  x += a[2]*b[2];
83  return x+x1;
84 }
85 
86 // /////////////////////////////////////////////////////////
87 
88 // given vectors a and b, returns a unit vector directed along the difference
89 // of the two vectors
90 static inline void
91 norm(double u[], const double a[], const double b[])
92 {
93  delta(u,a,b);
94  double x = 1.0/sqrt(scalar(u,u));
95  u[0] *= x; u[1] *= x; u[2] *= x;
96 }
97 
98 // /////////////////////////////////////////////////////////
99 
100 // given two vectors, returns the normalized cross product of those vectors
101 static inline void
102 normal(const double a[], const double b[], double w[])
103 {
104  w[0] = a[1]*b[2]-a[2]*b[1];
105  w[1] = a[2]*b[0]-a[0]*b[2];
106  w[2] = a[0]*b[1]-a[1]*b[0];
107  double x = 1.0/sqrt(scalar(w,w));
108  w[0] *= x; w[1] *= x; w[2] *= x;
109 }
110 
111 }
112 
113 #endif
114 
115 // Local Variables:
116 // mode: c++
117 // c-file-style: "ETS"
118 // End:

Generated at Sun Jan 26 2020 23:33:04 for MPQC 2.3.1 using the documentation package Doxygen 1.8.16.