Molassembler  3.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  return std::acos(ratio);
67 }
68 
77 template<typename T>
78 T lawOfSinesAngle(
79  const T a,
80  const T alphaRadians,
81  const T b
82 ) {
83  return std::asin(
84  b * std::sin(alphaRadians) / a
85  );
86 }
87 
97 double dihedralLength(
98  double a,
99  double b,
100  double c,
101  double alpha,
102  double beta,
103  double dihedral
104 );
105 
120 ValueBounds dihedralLengthBounds(
121  const ValueBounds& aBounds,
122  const ValueBounds& bBounds,
123  const ValueBounds& cBounds,
124  const ValueBounds& alphaBounds,
125  const ValueBounds& betaBounds,
126  const ValueBounds& dihedralBounds
127 );
128 
129 } // namespace CommonTrig
130 } // namespace Molassembler
131 } // namespace Scine
132 
133 #endif
Bond distance modelling functions.
Data struct for storing a numeric interval.