cgv
geom.h
1 #pragma once
2 
3 #include "fmat.h"
4 
5 namespace cgv {
6  namespace math {
8 
9  template <typename T>
11  {
12  cgv::math::fvec<T, 3> vn = dot(n, v)*n;
13  return vn + cos(a)*(v - vn) + sin(a)*cross(n, v);
14  }
16 
17  template <typename T>
19  {
20  axis = cross(v0, v1);
21  T len = axis.length();
22  if (len > 2 * std::numeric_limits<T>::epsilon())
23  axis *= T(1) / len;
24  else
25  axis[1] = T(1);
26  angle = atan2(len, dot(v0, v1));
27  }
29 
36  template <typename T>
38  {
39  axis(0) = R(2, 1) - R(1, 2);
40  axis(1) = R(0, 2) - R(2, 0);
41  axis(2) = R(1, 0) - R(0, 1);
42  T len = axis.length();
43  T tra = R.trace();
44  if (len < 2 * std::numeric_limits<T>::epsilon()) {
45  if (tra < 0) {
46  for (unsigned c = 0; c<3; ++c)
47  if (R(c, c) > 0) {
48  axis(c) = T(1);
49  angle = M_PI;
50  break;
51  }
52  return 1;
53  }
54  else {
55  axis(1) = T(1);
56  angle = 0;
57  return 2;
58  }
59  }
60  else {
61  axis *= T(1) / len;
62  angle = atan2(len, tra - T(1));
63  return 0;
64  }
65  }
67 
75  template <typename T>
77  {
79 
83 
84  x = v0;
85  x.normalize();
86  z = cross(v0, v1);
87  z.normalize();
88  y = cross(z, x);
89 
90  return O;
91  }
92 
93  }
94 }
cgv::math::fvec::normalize
double normalize()
normalize the vector using the L2-Norm and return the length
Definition: fvec.h:260
cgv::math::fmat
matrix of fixed size dimensions
Definition: fmat.h:23
cgv::math::fvec::length
T length() const
length of the vector L2-Norm
Definition: fvec.h:219
cgv::math::cross
fvec< T, N > cross(const fvec< T, N > &v, const fvec< T, N > &w)
returns the cross product of vector v and w
Definition: fvec.h:338
cgv::math::fvec< T, 3 >
cgv::math::decompose_rotation_to_axis_and_angle
int decompose_rotation_to_axis_and_angle(const cgv::math::fmat< T, 3, 3 > &R, cgv::math::fvec< T, 3 > &axis, T &angle)
decompose a rotation matrix into axis angle representation
Definition: geom.h:37
cgv::math::dot
T dot(const fvec< T, N > &v, const fvec< T, N > &w)
returns the dot product of vector v and w
Definition: fvec.h:300
cgv::math::rotate
cgv::math::fvec< T, 3 > rotate(const cgv::math::fvec< T, 3 > &v, const cgv::math::fvec< T, 3 > &n, T a)
rotate vector v around axis n by angle a (given in radian)
Definition: geom.h:10
cgv::math::compute_rotation_axis_and_angle_from_vector_pair
void compute_rotation_axis_and_angle_from_vector_pair(const cgv::math::fvec< T, 3 > &v0, const cgv::math::fvec< T, 3 > &v1, cgv::math::fvec< T, 3 > &axis, T &angle)
compute a rotation axis and a rotation angle in radian that rotates v0 onto v1.
Definition: geom.h:18
cgv
the cgv namespace
Definition: vr_calib.cxx:9
cgv::math::build_orthogonal_frame
cgv::math::fmat< T, 3, 3 > build_orthogonal_frame(const cgv::math::fvec< T, 3 > &v0, const cgv::math::fvec< T, 3 > &v1)
Given two vectors v0 and v1 extend to orthonormal frame and return 3x3 matrix containing frame vector...
Definition: geom.h:76
cgv::math::fmat::trace
T trace() const
returns the trace
Definition: fmat.h:168