Blender  V3.3
math_rotation.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include "BLI_math_base.h"
8 #include "BLI_math_rotation.hh"
9 #include "BLI_math_vector.h"
10 #include "BLI_math_vector.hh"
11 
12 namespace blender::math {
13 
14 float3 rotate_direction_around_axis(const float3 &direction, const float3 &axis, const float angle)
15 {
16  BLI_ASSERT_UNIT_V3(direction);
17  BLI_ASSERT_UNIT_V3(axis);
18 
19  const float3 axis_scaled = axis * math::dot(direction, axis);
20  const float3 diff = direction - axis_scaled;
21  const float3 cross = math::cross(axis, diff);
22 
23  return axis_scaled + diff * std::cos(angle) + cross * std::sin(angle);
24 }
25 
27  const float3 &center,
28  const float3 &axis,
29  const float angle)
30 
31 {
33  float mat[3][3];
35  mul_m3_v3(mat, result);
36  return result + center;
37 }
38 
39 } // namespace blender::math
#define BLI_ASSERT_UNIT_V3(v)
void mul_m3_v3(const float M[3][3], float r[3])
Definition: math_matrix.c:926
void axis_angle_normalized_to_mat3(float R[3][3], const float axis[3], float angle)
NSNotificationCenter * center
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition: btVector3.h:356
IMETHOD Vector diff(const Vector &a, const Vector &b, double dt=1)
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:319
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:311
T dot(const vec_base< T, Size > &a, const vec_base< T, Size > &b)
vec_base< T, 3 > cross(const vec_base< T, 3 > &a, const vec_base< T, 3 > &b)
float3 rotate_direction_around_axis(const float3 &direction, const float3 &axis, float angle)
float3 rotate_around_axis(const float3 &vector, const float3 &center, const float3 &axis, float angle)