Simpatico  v1.10
Bend.h
1 #ifndef SIMP_BEND_H
2 #define SIMP_BEND_H
3 
4 /*
5 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
6 *
7 * Copyright 2010 - 2017, The Regents of the University of Minnesota
8 * Distributed under the terms of the GNU General Public License.
9 */
10 
11 #include <util/space/Vector.h>
12 
13 #include <cmath>
14 
15 namespace Simp
16 {
17 
18  using namespace Util;
19 
30  struct Bend
31  {
32 
33  public:
34 
38  double cosTheta;
39 
46  void computeAngle(const Vector& b1, const Vector& b2);
47 
51  double sinTheta() const;
52 
58  double theta() const;
59 
60  };
61 
62  // Inline method definitions
63 
64  /*
65  * Calculate unit bond vectors and cosTheta.
66  */
67  inline
68  void Bend::computeAngle(const Vector& b1, const Vector& b2)
69  {
70  double d = sqrt(b1.square()*b2.square());
71  cosTheta = b1.dot(b2)/d;
72  if (cosTheta > 1.0) cosTheta = 1.0;
73  if (cosTheta < -1.0) cosTheta = -1.0;
74  }
75 
76  /*
77  * Return value sin(theta) for precomputed cos(theta).
78  */
79  inline
80  double Bend::sinTheta() const
81  { return sqrt(1.0 - cosTheta*cosTheta); }
82 
83  /*
84  * Return theta in radians for precomputed cos(theta).
85  */
86  inline
87  double Bend::theta() const
88  { return std::acos(cosTheta); }
89 
90 }
91 #endif
A Vector is a Cartesian vector.
Definition: Vector.h:75
A Bend calculates the angle between two vectors.
Definition: Bend.h:30
double dot(const Vector &v) const
Return dot product of this vector and vector v.
Definition: Vector.h:632
Classes used by all simpatico molecular simulations.
Utility classes for scientific computation.
Definition: accumulators.mod:1
double sinTheta() const
Return value of sin(theta) for precomputed cos(theta).
Definition: Bend.h:80
void computeAngle(const Vector &b1, const Vector &b2)
Compute cosTheta.
Definition: Bend.h:68
double cosTheta
Cosine of angle between vectors b1 and b2.
Definition: Bend.h:38
double square() const
Return square magnitude of this vector.
Definition: Vector.h:616
double theta() const
Return value of theta in radians for precomputed cos(theta).
Definition: Bend.h:87