43 value_type x, y, z, w;
48 value{0.0, 0.0, 0.0, 1.0} {}
49 constexpr t_quat(
const t_quat& v) :
50 value{v.x, v.y, v.z, v.w} {}
51 constexpr t_quat(value_type in_x, value_type in_y, value_type in_z, value_type in_w) :
52 value{in_x, in_y, in_z, in_w} {}
55 set(angle_radians, axis);
63 constexpr explicit t_quat(
const t_quat<R>& v) :
64 value{
static_cast<T
>(v.x),
static_cast<T
>(v.y),
static_cast<T
>(v.z),
static_cast<T
>(v.w)} {}
66 constexpr t_quat& operator=(
const t_quat&) =
default;
68 constexpr std::size_t size()
const {
return 4; }
70 value_type& operator[](std::size_t i) {
return value[i]; }
71 value_type operator[](std::size_t i)
const {
return value[i]; }
74 t_quat& operator=(
const t_quat<R>& rhs)
76 value[0] =
static_cast<value_type
>(rhs[0]);
77 value[1] =
static_cast<value_type
>(rhs[1]);
78 value[2] =
static_cast<value_type
>(rhs[2]);
79 value[3] =
static_cast<value_type
>(rhs[3]);
83 T* data() {
return value; }
84 const T* data()
const {
return value; }
86 void set(value_type in_x, value_type in_y, value_type in_z, value_type in_w)
96 const value_type epsilon = 1e-7;
97 value_type len = length(axis);
105 value_type inversenorm = 1.0 / len;
106 value_type coshalfangle = cos(0.5 * angle_radians);
107 value_type sinhalfangle = sin(0.5 * angle_radians);
109 x = axis.x * sinhalfangle * inversenorm;
110 y = axis.y * sinhalfangle * inversenorm;
111 z = axis.z * sinhalfangle * inversenorm;
117 const value_type epsilon = 1e-7;
119 value_type dot_pd = vsg::dot(from, to);
120 value_type div = std::sqrt(length2(from) * length2(to));
122 if (div - std::abs(dot_pd) < epsilon)
124 axis = orthogonal(from);
128 axis = cross(from, to);
131 value_type len = length(axis);
133 double angle_radians = acos(dot_pd / div);
135 value_type inversenorm = 1.0 / len;
136 value_type coshalfangle = cos(0.5 * angle_radians);
137 value_type sinhalfangle = sin(0.5 * angle_radians);
139 x = axis.x * sinhalfangle * inversenorm;
140 y = axis.y * sinhalfangle * inversenorm;
141 z = axis.z * sinhalfangle * inversenorm;
145 explicit operator bool()
const noexcept {
return value[0] != 0.0 || value[1] != 0.0 || value[2] != 0.0 || value[3] != 0.0; }