libigl v2.5.0
Loading...
Searching...
No Matches
canonical_quaternions.h
Go to the documentation of this file.
1// This file is part of libigl, a simple c++ geometry processing library.
2//
3// Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
4//
5// This Source Code Form is subject to the terms of the Mozilla Public License
6// v. 2.0. If a copy of the MPL was not distributed with this file, You can
7// obtain one at http://mozilla.org/MPL/2.0/.
8#ifndef IGL_CANONICAL_QUATERNIONS_H
9#define IGL_CANONICAL_QUATERNIONS_H
10#include "igl_inline.h"
18namespace igl
19{
20 // Float versions
21 // This will get undef'd below
22#define SQRT_2_OVER_2 0.707106781f
23 // Identity quaternion
24 const float IDENTITY_QUAT_F[4] = {0,0,0,1};
25 // The following match the Matlab canonical views
26 // X point right, Y pointing up and Z point out
27 const float XY_PLANE_QUAT_F[4] = {0,0,0,1};
28 // X points right, Y points *in* and Z points up
30 // X points out, Y points right, and Z points up
31 const float YZ_PLANE_QUAT_F[4] = {-0.5,-0.5,-0.5,0.5};
32 const float CANONICAL_VIEW_QUAT_F[][4] =
33 {
34 { 0, 0, 0, 1}, // 0
35 { 0, 0, SQRT_2_OVER_2, SQRT_2_OVER_2}, // 1
36 { 0, 0, 1, 0}, // 2
37 { 0, 0, SQRT_2_OVER_2,-SQRT_2_OVER_2}, // 3
38
39 { 0, -1, 0, 0}, // 4
40 {-SQRT_2_OVER_2, SQRT_2_OVER_2, 0, 0}, // 5
41 { -1, 0, 0, 0}, // 6
42 {-SQRT_2_OVER_2,-SQRT_2_OVER_2, 0, 0}, // 7
43
44 { -0.5, -0.5, -0.5, 0.5}, // 8
45 { 0,-SQRT_2_OVER_2, 0, SQRT_2_OVER_2}, // 9
46 { 0.5, -0.5, 0.5, 0.5}, // 10
47 { SQRT_2_OVER_2, 0, SQRT_2_OVER_2, 0}, // 11
48
49 { SQRT_2_OVER_2, 0,-SQRT_2_OVER_2, 0}, // 12
50 { 0.5, 0.5, -0.5, 0.5}, // 13
51 { 0, SQRT_2_OVER_2, 0, SQRT_2_OVER_2}, // 14
52 { -0.5, 0.5, 0.5, 0.5}, // 15
53
54 { 0, SQRT_2_OVER_2, SQRT_2_OVER_2, 0}, // 16
55 { -0.5, 0.5, 0.5, -0.5}, // 17
56 {-SQRT_2_OVER_2, 0, 0,-SQRT_2_OVER_2}, // 18
57 { -0.5, -0.5, -0.5, -0.5}, // 19
58
59 {-SQRT_2_OVER_2, 0, 0, SQRT_2_OVER_2}, // 20
60 { -0.5, -0.5, 0.5, 0.5}, // 21
61 { 0,-SQRT_2_OVER_2, SQRT_2_OVER_2, 0}, // 22
62 { 0.5, -0.5, 0.5, -0.5} // 23
63 };
64#undef SQRT_2_OVER_2
65 // Double versions
66#define SQRT_2_OVER_2 0.70710678118654757
67 // Identity
68 const double IDENTITY_QUAT_D[4] = {0,0,0,1};
69 // The following match the Matlab canonical views
70 // X point right, Y pointing up and Z point out
71 const double XY_PLANE_QUAT_D[4] = {0,0,0,1};
72 // X points right, Y points *in* and Z points up
74 // X points out, Y points right, and Z points up
75 const double YZ_PLANE_QUAT_D[4] = {-0.5,-0.5,-0.5,0.5};
76 const double CANONICAL_VIEW_QUAT_D[][4] =
77 {
78 { 0, 0, 0, 1},
80 { 0, 0, 1, 0},
82
83 { 0, -1, 0, 0},
85 { -1, 0, 0, 0},
87
88 { -0.5, -0.5, -0.5, 0.5},
90 { 0.5, -0.5, 0.5, 0.5},
92
94 { 0.5, 0.5, -0.5, 0.5},
96 { -0.5, 0.5, 0.5, 0.5},
97
99 { -0.5, 0.5, 0.5, -0.5},
101 { -0.5, -0.5, -0.5, -0.5},
102
104 { -0.5, -0.5, 0.5, 0.5},
106 { 0.5, -0.5, 0.5, -0.5}
107 };
108#undef SQRT_2_OVER_2
109#define NUM_CANONICAL_VIEW_QUAT 24
110
111 // NOTE: I want to rather be able to return a Q_type[][] but C++ is not
112 // making it easy. So instead I've written a per-element accessor
113
114 // Return element [i][j] of the corresponding CANONICAL_VIEW_QUAT_* of the
115 // given templated type
116 // Inputs:
117 // i index of quaternion
118 // j index of coordinate in quaternion i
119 // Returns values of CANONICAL_VIEW_QUAT_*[i][j]
120 template <typename Q_type>
121 IGL_INLINE Q_type CANONICAL_VIEW_QUAT(int i, int j);
122 // Template specializations for float and double
123 template <>
125 template <>
127
128}
129
130#ifndef IGL_STATIC_LIBRARY
131# include "canonical_quaternions.cpp"
132#endif
133
134#endif
#define SQRT_2_OVER_2
Definition canonical_quaternions.h:22
#define IGL_INLINE
Definition igl_inline.h:15
Definition AABB.h:17
const double XY_PLANE_QUAT_D[4]
Definition canonical_quaternions.h:71
const float IDENTITY_QUAT_F[4]
Definition canonical_quaternions.h:24
const double IDENTITY_QUAT_D[4]
Definition canonical_quaternions.h:68
double CANONICAL_VIEW_QUAT< double >(int i, int j)
const double XZ_PLANE_QUAT_D[4]
Definition canonical_quaternions.h:73
float CANONICAL_VIEW_QUAT< float >(int i, int j)
Q_type CANONICAL_VIEW_QUAT(int i, int j)
const float CANONICAL_VIEW_QUAT_F[][4]
Definition canonical_quaternions.h:32
const double CANONICAL_VIEW_QUAT_D[][4]
Definition canonical_quaternions.h:76
const float YZ_PLANE_QUAT_F[4]
Definition canonical_quaternions.h:31
const float XZ_PLANE_QUAT_F[4]
Definition canonical_quaternions.h:29
const double YZ_PLANE_QUAT_D[4]
Definition canonical_quaternions.h:75
const float XY_PLANE_QUAT_F[4]
Definition canonical_quaternions.h:27