Molassembler  1.0.0
Molecule graph and conformer library
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
CommonTrig.h
Go to the documentation of this file.
1 
12 #ifndef INCLUDE_MOLASSEMBLER_COMMON_TRIG_H
13 #define INCLUDE_MOLASSEMBLER_COMMON_TRIG_H
14 
17 
18 #include <cmath>
19 
20 namespace Scine {
21 namespace Molassembler {
22 namespace CommonTrig {
23 
24 using ValueBounds = DistanceGeometry::ValueBounds;
25 
33 template<typename T>
34 T lawOfCosines(const T a, const T b, const T phiRadians) {
35  return std::sqrt(
36  a * a
37  + b * b
38  - 2 * a * b * std::cos(phiRadians)
39  );
40 }
41 
46 template<typename T>
47 T lawOfCosinesAngle(
48  const T a,
49  const T b,
50  const T c
51 ) {
52  double ratio = (
53  a * a
54  + b * b
55  - c * c
56  ) / (
57  2 * a * b
58  );
59 
60  /* Accept ratios a little above one for the sake of numerical inaccuracies
61  * when the triangle almost doesn't exist
62  */
63  if(ratio > 1 && std::fabs(ratio - 1) <= 1e-10) {
64  return 0.0;
65  }
66 
67  return std::acos(ratio);
68 }
69 
78 template<typename T>
79 T lawOfSinesAngle(
80  const T a,
81  const T alphaRadians,
82  const T b
83 ) {
84  return std::asin(
85  b * std::sin(alphaRadians) / a
86  );
87 }
88 
98 double dihedralLength(
99  double a,
100  double b,
101  double c,
102  double alpha,
103  double beta,
104  double dihedral
105 );
106 
121 ValueBounds dihedralLengthBounds(
122  const ValueBounds& aBounds,
123  const ValueBounds& bBounds,
124  const ValueBounds& cBounds,
125  const ValueBounds& alphaBounds,
126  const ValueBounds& betaBounds,
127  const ValueBounds& dihedralBounds
128 );
129 
130 } // namespace CommonTrig
131 } // namespace Molassembler
132 } // namespace Scine
133 
134 #endif
Bond distance modelling functions.
Data struct for storing a numeric interval.