i6engine  1.0
i6eMath.h
Go to the documentation of this file.
1 /*
2  * i6engine
3  * Copyright (2016) Daniel Bonrath, Michael Baer, All rights reserved.
4  *
5  * This file is part of i6engine; i6engine is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
25 #ifndef __I6ENGINE_MATH_I6EMATH_H__
26 #define __I6ENGINE_MATH_I6EMATH_H__
27 
28 #include <cmath>
29 
31 
34 
38 const double PI = 4 * std::atan(1);
39 
40 namespace i6e {
41 namespace math {
42 
46  inline double disPointLine(const Vec3 & offset, const Vec3 & direction, const Vec3 & point) {
47  if (std::fabs(direction.length()) < 1e-15) {
48  ISIXE_THROW_API("disPointLine", "given direction vector is (0, 0, 0)");
49  }
50  Vec3 c = direction * (point - offset);
51  return c.length() / direction.length();
52  }
53 
58  inline uint64_t binom(uint32_t n, uint32_t k) {
59  uint64_t bin = 1;
60  if (k > n - k) {
61  k = n - k;
62  }
63  for (uint32_t i = 1; i <= k; ++i) {
64  bin *= n--;
65  bin /= i;
66  }
67  return bin;
68  }
69 
73  inline Vec3 rotateVector(const Vec3 & pos, const Quaternion & rot) {
74  return (rot * pos * rot.inverse()).toVector();
75  }
76 
77 } /* namespace math */
78 } /* namespace i6e */
79 
80 #endif /* __I6ENGINE_MATH_I6EMATH_H__ */
81 
Class describing a 3d rotation.
Definition: i6eQuaternion.h:58
const double PI
PI.
Definition: i6eMath.h:38
#define ISIXE_THROW_API(module, message)
Definition: Exceptions.h:45
i6eQuaternion inverse() const
return the inverted vector of the quaternion
Implements 3-dimensional vectors.
Definition: i6eVector.h:48
double disPointLine(const Vec3 &offset, const Vec3 &direction, const Vec3 &point)
returns the distance of a point to a line specified by offset and direction
Definition: i6eMath.h:46
Vec3 rotateVector(const Vec3 &pos, const Quaternion &rot)
returns the directional vector
Definition: i6eMath.h:73
double length() const
length of the Vector
uint64_t binom(uint32_t n, uint32_t k)
returns "n over k" keep in mind that this function is likely to overflow with relatively small values...
Definition: i6eMath.h:58