Blender  V3.3
Classes | Typedefs | Functions | Variables
math_rotation.c File Reference
#include "BLI_math.h"
#include "BLI_strict_flags.h"

Go to the source code of this file.

Classes

struct  RotOrderInfo
 

Typedefs

typedef struct RotOrderInfo RotOrderInfo
 

Functions

void unit_axis_angle (float axis[3], float *angle)
 
void unit_qt (float q[4])
 
void copy_qt_qt (float q[4], const float a[4])
 
bool is_zero_qt (const float q[4])
 
void mul_qt_qtqt (float q[4], const float a[4], const float b[4])
 
void mul_qt_v3 (const float q[4], float r[3])
 
void conjugate_qt_qt (float q1[4], const float q2[4])
 
void conjugate_qt (float q[4])
 
float dot_qtqt (const float a[4], const float b[4])
 
void invert_qt (float q[4])
 
void invert_qt_qt (float q1[4], const float q2[4])
 
void invert_qt_normalized (float q[4])
 
void invert_qt_qt_normalized (float q1[4], const float q2[4])
 
void mul_qt_fl (float q[4], const float f)
 
void sub_qt_qtqt (float q[4], const float a[4], const float b[4])
 
void pow_qt_fl_normalized (float q[4], const float fac)
 
void quat_to_compatible_quat (float q[4], const float a[4], const float old[4])
 
static void quat_to_mat3_no_error (float m[3][3], const float q[4])
 
void quat_to_mat3 (float m[3][3], const float q[4])
 
void quat_to_mat4 (float m[4][4], const float q[4])
 
void mat3_normalized_to_quat (float q[4], const float mat[3][3])
 
void mat3_to_quat (float q[4], const float m[3][3])
 
void mat4_normalized_to_quat (float q[4], const float m[4][4])
 
void mat4_to_quat (float q[4], const float m[4][4])
 
void mat3_to_quat_is_ok (float q[4], const float wmat[3][3])
 
float normalize_qt (float q[4])
 
float normalize_qt_qt (float r[4], const float q[4])
 
void rotation_between_vecs_to_mat3 (float m[3][3], const float v1[3], const float v2[3])
 
void rotation_between_vecs_to_quat (float q[4], const float v1[3], const float v2[3])
 
void rotation_between_quats_to_quat (float q[4], const float q1[4], const float q2[4])
 
float quat_split_swing_and_twist (const float q_in[4], int axis, float r_swing[4], float r_twist[4])
 
void vec_to_quat (float q[4], const float vec[3], short axis, const short upflag)
 
void interp_dot_slerp (const float t, const float cosom, float r_w[2])
 
void interp_qt_qtqt (float q[4], const float a[4], const float b[4], const float t)
 
void add_qt_qtqt (float q[4], const float a[4], const float b[4], const float t)
 
void tri_to_quat_ex (float quat[4], const float v1[3], const float v2[3], const float v3[3], const float no_orig[3])
 
float tri_to_quat (float q[4], const float a[3], const float b[3], const float c[3])
 
void sin_cos_from_fraction (int numerator, const int denominator, float *r_sin, float *r_cos)
 
void print_qt (const char *str, const float q[4])
 
void axis_angle_normalized_to_quat (float r[4], const float axis[3], const float angle)
 
void axis_angle_to_quat (float r[4], const float axis[3], const float angle)
 
void quat_to_axis_angle (float axis[3], float *angle, const float q[4])
 
void axis_angle_to_eulO (float eul[3], const short order, const float axis[3], const float angle)
 
void eulO_to_axis_angle (float axis[3], float *angle, const float eul[3], const short order)
 
void axis_angle_normalized_to_mat3_ex (float mat[3][3], const float axis[3], const float angle_sin, const float angle_cos)
 
void axis_angle_normalized_to_mat3 (float R[3][3], const float axis[3], const float angle)
 
void axis_angle_to_mat3 (float R[3][3], const float axis[3], const float angle)
 
void axis_angle_to_mat4 (float R[4][4], const float axis[3], const float angle)
 
void mat3_normalized_to_axis_angle (float axis[3], float *angle, const float mat[3][3])
 
void mat3_to_axis_angle (float axis[3], float *angle, const float mat[3][3])
 
void mat4_normalized_to_axis_angle (float axis[3], float *angle, const float mat[4][4])
 
void mat4_to_axis_angle (float axis[3], float *angle, const float mat[4][4])
 
void axis_angle_to_mat4_single (float R[4][4], const char axis, const float angle)
 
void axis_angle_to_mat3_single (float R[3][3], const char axis, const float angle)
 
void angle_to_mat2 (float R[2][2], const float angle)
 
void axis_angle_to_quat_single (float q[4], const char axis, const float angle)
 
void quat_normalized_to_expmap (float expmap[3], const float q[4])
 
void quat_to_expmap (float expmap[3], const float q[4])
 
void expmap_to_quat (float r[4], const float expmap[3])
 
void eul_to_mat3 (float mat[3][3], const float eul[3])
 
void eul_to_mat4 (float mat[4][4], const float eul[3])
 
static void mat3_normalized_to_eul2 (const float mat[3][3], float eul1[3], float eul2[3])
 
void mat3_normalized_to_eul (float eul[3], const float mat[3][3])
 
void mat3_to_eul (float eul[3], const float mat[3][3])
 
void mat4_normalized_to_eul (float eul[3], const float m[4][4])
 
void mat4_to_eul (float eul[3], const float m[4][4])
 
void quat_to_eul (float eul[3], const float quat[4])
 
void eul_to_quat (float quat[4], const float eul[3])
 
void rotate_eul (float beul[3], const char axis, const float ang)
 
void compatible_eul (float eul[3], const float oldrot[3])
 
void mat3_normalized_to_compatible_eul (float eul[3], const float oldrot[3], float mat[3][3])
 
void mat3_to_compatible_eul (float eul[3], const float oldrot[3], float mat[3][3])
 
void quat_to_compatible_eul (float eul[3], const float oldrot[3], const float quat[4])
 
static const RotOrderInfoget_rotation_order_info (const short order)
 
void eulO_to_quat (float q[4], const float e[3], const short order)
 
void quat_to_eulO (float e[3], short const order, const float q[4])
 
void eulO_to_mat3 (float M[3][3], const float e[3], const short order)
 
static void mat3_normalized_to_eulo2 (const float mat[3][3], float eul1[3], float eul2[3], const short order)
 
void eulO_to_mat4 (float mat[4][4], const float e[3], const short order)
 
void mat3_normalized_to_eulO (float eul[3], const short order, const float m[3][3])
 
void mat3_to_eulO (float eul[3], const short order, const float m[3][3])
 
void mat4_normalized_to_eulO (float eul[3], const short order, const float m[4][4])
 
void mat4_to_eulO (float eul[3], const short order, const float m[4][4])
 
void mat3_normalized_to_compatible_eulO (float eul[3], const float oldrot[3], const short order, const float mat[3][3])
 
void mat3_to_compatible_eulO (float eul[3], const float oldrot[3], const short order, const float mat[3][3])
 
void mat4_normalized_to_compatible_eulO (float eul[3], const float oldrot[3], const short order, const float m[4][4])
 
void mat4_to_compatible_eulO (float eul[3], const float oldrot[3], const short order, const float m[4][4])
 
void quat_to_compatible_eulO (float eul[3], const float oldrot[3], const short order, const float quat[4])
 
void rotate_eulO (float beul[3], const short order, char axis, float ang)
 
void eulO_to_gimbal_axis (float gmat[3][3], const float eul[3], const short order)
 
void add_eul_euleul (float r_eul[3], float a[3], float b[3], const short order)
 
void sub_eul_euleul (float r_eul[3], float a[3], float b[3], const short order)
 
void mat4_to_dquat (DualQuat *dq, const float basemat[4][4], const float mat[4][4])
 
void dquat_to_mat4 (float R[4][4], const DualQuat *dq)
 
void add_weighted_dq_dq (DualQuat *dq_sum, const DualQuat *dq, float weight)
 
void normalize_dq (DualQuat *dq, float totweight)
 
void mul_v3m3_dq (float r[3], float R[3][3], DualQuat *dq)
 
void copy_dq_dq (DualQuat *r, const DualQuat *dq)
 
void quat_apply_track (float quat[4], short axis, short upflag)
 
void vec_apply_track (float vec[3], short axis)
 
float focallength_to_fov (float focal_length, float sensor)
 
float fov_to_focallength (float hfov, float sensor)
 
static float mod_inline (float a, float b)
 
float angle_wrap_rad (float angle)
 
float angle_wrap_deg (float angle)
 
float angle_compat_rad (float angle, float angle_compat)
 
BLI_INLINE int _axis_signed (const int axis)
 
bool mat3_from_axis_conversion (int src_forward, int src_up, int dst_forward, int dst_up, float r_mat[3][3])
 
bool mat3_from_axis_conversion_single (int src_axis, int dst_axis, float r_mat[3][3])
 
Quaternion Angle

Unlike the angle between vectors, this does NOT return the shortest angle. See signed functions below for this.

float angle_normalized_qt (const float q[4])
 
float angle_qt (const float q[4])
 
float angle_normalized_qtqt (const float q1[4], const float q2[4])
 
float angle_qtqt (const float q1[4], const float q2[4])
 
Quaternion Angle (Signed)

Angles with quaternion calculation can exceed 180d, Having signed versions of these functions allows 'fabsf(angle_signed_qtqt(...))' to give us the shortest angle between quaternions. With higher precision than subtracting pi afterwards.

float angle_signed_normalized_qt (const float q[4])
 
float angle_signed_normalized_qtqt (const float q1[4], const float q2[4])
 
float angle_signed_qt (const float q[4])
 
float angle_signed_qtqt (const float q1[4], const float q2[4])
 

Variables

static const RotOrderInfo rotOrders []
 
static float _axis_convert_matrix [23][3][3]
 
static int _axis_convert_lut [23][24]
 

Typedef Documentation

◆ RotOrderInfo

typedef struct RotOrderInfo RotOrderInfo

Function Documentation

◆ _axis_signed()

BLI_INLINE int _axis_signed ( const int  axis)

Definition at line 2357 of file math_rotation.c.

Referenced by mat3_from_axis_conversion().

◆ add_eul_euleul()

void add_eul_euleul ( float  r_eul[3],
float  a[3],
float  b[3],
const short  order 
)

Definition at line 1919 of file math_rotation.c.

References Freestyle::a, usdtokens::b(), eulO_to_quat(), mul_qt_qtqt(), order, and quat_to_eulO().

Referenced by ElementRotation_ex().

◆ add_qt_qtqt()

void add_qt_qtqt ( float  q[4],
const float  a[4],
const float  b[4],
const float  t 
)

Definition at line 849 of file math_rotation.c.

References Freestyle::a, usdtokens::b(), and t.

Referenced by Quaternion_add().

◆ add_weighted_dq_dq()

void add_weighted_dq_dq ( DualQuat dq_sum,
const DualQuat dq,
float  weight 
)

◆ angle_compat_rad()

float angle_compat_rad ( float  angle,
float  angle_compat 
)

Returns an angle compatible with angle_compat.

Definition at line 2274 of file math_rotation.c.

References angle(), and angle_wrap_rad().

Referenced by gizmo_bisect_prop_angle_set(), gizmo_spin_prop_axis_angle_set(), gpencil_guide_event_handling(), gpencil_guide_rotate(), and recalcData_edit_armature().

◆ angle_normalized_qt()

float angle_normalized_qt ( const float  q[4])

◆ angle_normalized_qtqt()

float angle_normalized_qtqt ( const float  q1[4],
const float  q2[4] 
)

◆ angle_qt()

float angle_qt ( const float  q[4])

Definition at line 559 of file math_rotation.c.

References angle_normalized_qt(), and normalize_qt_qt().

◆ angle_qtqt()

float angle_qtqt ( const float  q1[4],
const float  q2[4] 
)

Definition at line 580 of file math_rotation.c.

References angle_normalized_qtqt(), normalize_qt_qt(), and q1.

Referenced by angle_signed_qtqt().

◆ angle_signed_normalized_qt()

float angle_signed_normalized_qt ( const float  q[4])

Definition at line 602 of file math_rotation.c.

References BLI_ASSERT_UNIT_QUAT, and saacos().

Referenced by angle_signed_qt().

◆ angle_signed_normalized_qtqt()

float angle_signed_normalized_qtqt ( const float  q1[4],
const float  q2[4] 
)

Definition at line 612 of file math_rotation.c.

References angle_normalized_qtqt(), dot_qtqt(), negate_v4_v4(), and q1.

Referenced by ED_view3d_smooth_view_ex().

◆ angle_signed_qt()

float angle_signed_qt ( const float  q[4])

Definition at line 623 of file math_rotation.c.

References angle_signed_normalized_qt(), and normalize_qt_qt().

◆ angle_signed_qtqt()

float angle_signed_qtqt ( const float  q1[4],
const float  q2[4] 
)

Definition at line 632 of file math_rotation.c.

References angle_qtqt(), dot_qtqt(), negate_v4_v4(), and q1.

Referenced by ED_view3d_quat_to_axis_view(), and view_axis_exec().

◆ angle_to_mat2()

void angle_to_mat2 ( float  R[2][2],
const float  angle 
)

◆ angle_wrap_deg()

float angle_wrap_deg ( float  angle)

Definition at line 2269 of file math_rotation.c.

References angle(), and mod_inline().

◆ angle_wrap_rad()

float angle_wrap_rad ( float  angle)

◆ axis_angle_normalized_to_mat3()

void axis_angle_normalized_to_mat3 ( float  R[3][3],
const float  axis[3],
const float  angle 
)

◆ axis_angle_normalized_to_mat3_ex()

void axis_angle_normalized_to_mat3_ex ( float  mat[3][3],
const float  axis[3],
float  angle_sin,
float  angle_cos 
)

axis angle to 3x3 matrix

This takes the angle with sin/cos applied so we can avoid calculating it in some cases.

Parameters
axisrotation axis (must be normalized).
angle_sinsin(angle)
angle_coscos(angle)

Definition at line 1101 of file math_rotation.c.

References BLI_ASSERT_UNIT_V3.

Referenced by axis_angle_normalized_to_mat3(), and rotation_between_vecs_to_mat3().

◆ axis_angle_normalized_to_quat()

void axis_angle_normalized_to_quat ( float  r[4],
const float  axis[3],
const float  angle 
)

◆ axis_angle_to_eulO()

void axis_angle_to_eulO ( float  eul[3],
short  order,
const float  axis[3],
float  angle 
)

◆ axis_angle_to_mat3()

void axis_angle_to_mat3 ( float  R[3][3],
const float  axis[3],
float  angle 
)

◆ axis_angle_to_mat3_single()

void axis_angle_to_mat3_single ( float  R[3][3],
char  axis,
float  angle 
)

◆ axis_angle_to_mat4()

void axis_angle_to_mat4 ( float  R[4][4],
const float  axis[3],
float  angle 
)

Axis angle to 4x4 matrix - safer version (normalization of axis performed).

Definition at line 1154 of file math_rotation.c.

References angle(), axis_angle_to_mat3(), copy_m4_m3(), R, and unit_m4().

Referenced by constraintob_from_transdata(), TransformReader::dae_rotate_to_mat4(), AnimationImporter::evaluate_animation(), and GPU_matrix_rotate_3fv().

◆ axis_angle_to_mat4_single()

void axis_angle_to_mat4_single ( float  R[4][4],
char  axis,
float  angle 
)

◆ axis_angle_to_quat()

void axis_angle_to_quat ( float  r[4],
const float  axis[3],
const float  angle 
)

◆ axis_angle_to_quat_single()

void axis_angle_to_quat_single ( float  q[4],
const char  axis,
const float  angle 
)

◆ compatible_eul()

void compatible_eul ( float  eul[3],
const float  oldrot[3] 
)

◆ conjugate_qt()

void conjugate_qt ( float  q[4])

Definition at line 85 of file math_rotation.c.

Referenced by invert_qt(), invert_qt_normalized(), and Quaternion_conjugate().

◆ conjugate_qt_qt()

void conjugate_qt_qt ( float  q1[4],
const float  q2[4] 
)

Definition at line 77 of file math_rotation.c.

References q1.

Referenced by rotation_between_quats_to_quat().

◆ copy_dq_dq()

void copy_dq_dq ( DualQuat r,
const DualQuat dq 
)

Definition at line 2163 of file math_rotation.c.

References r.

◆ copy_qt_qt()

void copy_qt_qt ( float  q[4],
const float  a[4] 
)

Definition at line 33 of file math_rotation.c.

References Freestyle::a.

Referenced by add_pose_transdata(), bevel_list_smooth(), BKE_object_tfm_backup(), BKE_object_tfm_restore(), BKE_pose_copy_pchan_result(), BKE_scene_cursor_quat_to_rot(), BKE_screen_view3d_do_versions_250(), BKE_where_on_path(), bm_edgering_pair_interpolate(), boid_body(), calc_curve_deform(), createTransCursor_view3d(), createTransMBallVerts(), createTransSculpt(), do_path_effectors(), dquat_to_mat4(), ED_object_rotation_from_view(), ED_view3d_cameracontrol_acquire(), ED_view3d_cameracontrol_release(), ED_view3d_cursor3d_position_rotation(), ED_view3d_cursor3d_update(), ED_view3d_lastview_store(), ED_view3d_quat_from_axis_view(), ED_view3d_smooth_view_ex(), fcurves_to_pchan_links_get(), interp_qt_qtqt(), interpolate_pathcache(), invert_qt_qt(), invert_qt_qt_normalized(), metaball_coords_and_quats_apply_with_mat4(), metaball_coords_and_quats_get(), minimum_twist_between_two_points(), modifyMesh(), normalize_qt_qt(), object_clear_rot(), ObjectToTransData(), offset_child(), pose_bone_do_paste(), pose_mirror_info_init(), pose_mirror_info_restore(), pose_slide_apply_quat(), poseAnim_mapping_reset(), psys_cache_edit_paths_iter(), psys_get_birth_coords(), psys_get_from_key(), psys_get_particle_on_path(), psys_path_iter_get(), psys_thread_create_path(), quat_mul_float(), quat_to_compatible_quat(), Quaternion_CreatePyObject(), Quaternion_imatmul(), restoreElement(), rotateBevelPiece(), SCULPT_do_pose_brush(), sculpt_rake_rotate(), transform_data_ext_rotate(), view3d_localview_update_rv3d(), view3d_smooth_view_state_backup(), view3d_smooth_view_state_restore(), viewops_data_create(), viewroll_modal(), viewrotate_apply(), viewrotate_apply_snap(), WM_xr_action_binding_create(), WM_xr_action_state_get(), wm_xr_draw_matrices_create(), wm_xr_navigation_fly_modal(), wm_xr_session_event_create(), WM_xr_session_state_controller_aim_rotation_get(), WM_xr_session_state_controller_grip_rotation_get(), WM_xr_session_state_nav_rotation_get(), WM_xr_session_state_nav_rotation_set(), and wm_xr_session_state_update().

◆ dot_qtqt()

float dot_qtqt ( const float  a[4],
const float  b[4] 
)

◆ dquat_to_mat4()

void dquat_to_mat4 ( float  R[4][4],
const DualQuat dq 
)

◆ eul_to_mat3()

void eul_to_mat3 ( float  mat[3][3],
const float  eul[3] 
)

◆ eul_to_mat4()

void eul_to_mat4 ( float  mat[4][4],
const float  eul[3] 
)

Definition at line 1343 of file math_rotation.c.

References KDL::cos(), float(), sh, and KDL::sin().

Referenced by BKE_texture_mapping_init().

◆ eul_to_quat()

void eul_to_quat ( float  quat[4],
const float  eul[3] 
)

◆ eulO_to_axis_angle()

void eulO_to_axis_angle ( float  axis[3],
float angle,
const float  eul[3],
short  order 
)

◆ eulO_to_gimbal_axis()

void eulO_to_gimbal_axis ( float  gmat[3][3],
const float  eul[3],
short  order 
)

The matrix is written to as 3 axis vectors.

Definition at line 1897 of file math_rotation.c.

References copy_v3_v3(), eulO_to_mat3(), get_rotation_order_info(), order, R, and zero_v3().

Referenced by gimbal_axis_object(), and gimbal_axis_pose().

◆ eulO_to_mat3()

void eulO_to_mat3 ( float  mat[3][3],
const float  eul[3],
short  order 
)

◆ eulO_to_mat4()

void eulO_to_mat4 ( float  mat[4][4],
const float  eul[3],
short  order 
)

Construct 4x4 matrix from Euler angles (in radians).

Definition at line 1747 of file math_rotation.c.

References copy_m4_m3(), e, eulO_to_mat3(), and order.

Referenced by BKE_pchan_minmax(), C_Matrix_LocRotScale(), and constraintob_from_transdata().

◆ eulO_to_quat()

void eulO_to_quat ( float  quat[4],
const float  eul[3],
short  order 
)

◆ expmap_to_quat()

void expmap_to_quat ( float  r[4],
const float  expmap[3] 
)

◆ focallength_to_fov()

float focallength_to_fov ( float  focal_length,
float  sensor 
)

◆ fov_to_focallength()

float fov_to_focallength ( float  hfov,
float  sensor 
)

◆ get_rotation_order_info()

static const RotOrderInfo* get_rotation_order_info ( const short  order)
static

◆ interp_dot_slerp()

void interp_dot_slerp ( float  t,
float  cosom,
float  r_w[2] 
)

Generic function for implementing slerp (quaternions and spherical vector coords).

Parameters
tfactor in [0..1]
cosomdot product from normalized vectors/quats.
r_wcalculated weights.

Definition at line 801 of file math_rotation.c.

References acosf, BLI_assert, eps, fabsf, IN_RANGE_INCL, LIKELY, sinf, and t.

Referenced by interp_qt_qtqt(), interp_v2_v2v2_slerp(), interp_v3_v3v3_slerp(), and Vector_slerp().

◆ interp_qt_qtqt()

void interp_qt_qtqt ( float  q[4],
const float  a[4],
const float  b[4],
const float  t 
)

◆ invert_qt()

void invert_qt ( float  q[4])

Definition at line 97 of file math_rotation.c.

References conjugate_qt(), dot_qtqt(), and mul_qt_fl().

Referenced by invert_qt_qt(), and Quaternion_invert().

◆ invert_qt_normalized()

void invert_qt_normalized ( float  q[4])

This is just conjugate_qt for cases we know q is unit-length. we could use conjugate_qt directly, but use this function to show intent, and assert if its ever becomes non-unit-length.

Definition at line 115 of file math_rotation.c.

References BLI_ASSERT_UNIT_QUAT, and conjugate_qt().

Referenced by BKE_object_mat3_to_rot(), dvar_eval_rotDiff(), ED_view3d_from_m4(), invert_qt_qt_normalized(), nla_combine_quaternion_get_inverted_lower_values(), nla_combine_quaternion_get_inverted_strip_values(), sub_eul_euleul(), view3d_boxview_sync_axis(), view3d_orbit_apply_dyn_ofs(), view_axis_exec(), and viewrotate_apply_snap().

◆ invert_qt_qt()

void invert_qt_qt ( float  q1[4],
const float  q2[4] 
)

Definition at line 109 of file math_rotation.c.

References copy_qt_qt(), invert_qt(), and q1.

◆ invert_qt_qt_normalized()

void invert_qt_qt_normalized ( float  q1[4],
const float  q2[4] 
)

◆ is_zero_qt()

bool is_zero_qt ( const float  q[4])

Definition at line 41 of file math_rotation.c.

◆ mat3_from_axis_conversion()

bool mat3_from_axis_conversion ( int  src_forward,
int  src_up,
int  dst_forward,
int  dst_up,
float  r_mat[3][3] 
)

Each argument us an axis in ['X', 'Y', 'Z', '-X', '-Y', '-Z'] where the first 2 are a source and the second 2 are the target.

Definition at line 2362 of file math_rotation.c.

References _axis_convert_lut, _axis_convert_matrix, _axis_signed(), ARRAY_SIZE, copy_m3_m3(), and unit_m3().

Referenced by BCMatrix::BCMatrix(), blender::io::stl::importer_main(), mat3_from_axis_conversion_single(), meshcache_do(), and blender::io::obj::transform_object().

◆ mat3_from_axis_conversion_single()

bool mat3_from_axis_conversion_single ( int  src_axis,
int  dst_axis,
float  r_mat[3][3] 
)

Use when the second axis can be guessed.

Definition at line 2394 of file math_rotation.c.

References mat3_from_axis_conversion(), and unit_m3().

Referenced by single_axis_convert().

◆ mat3_normalized_to_axis_angle()

void mat3_normalized_to_axis_angle ( float  axis[3],
float angle,
const float  M[3][3] 
)

3x3 matrix to axis angle.

Definition at line 1163 of file math_rotation.c.

References angle(), mat3_normalized_to_quat(), and quat_to_axis_angle().

Referenced by BKE_pchan_mat3_to_rot(), and pivotcon_evaluate().

◆ mat3_normalized_to_compatible_eul()

void mat3_normalized_to_compatible_eul ( float  eul[3],
const float  oldrot[3],
float  mat[3][3] 
)

◆ mat3_normalized_to_compatible_eulO()

void mat3_normalized_to_compatible_eulO ( float  eul[3],
const float  oldrot[3],
const short  order,
const float  mat[3][3] 
)

◆ mat3_normalized_to_eul()

void mat3_normalized_to_eul ( float  eul[3],
const float  mat[3][3] 
)

◆ mat3_normalized_to_eul2()

static void mat3_normalized_to_eul2 ( const float  mat[3][3],
float  eul1[3],
float  eul2[3] 
)
static

◆ mat3_normalized_to_eulO()

void mat3_normalized_to_eulO ( float  eul[3],
short  order,
const float  mat[3][3] 
)

Convert 3x3 matrix to Euler angles (in radians).

Definition at line 1756 of file math_rotation.c.

References copy_v3_v3(), fabsf, mat3_normalized_to_eulo2(), and order.

Referenced by BKE_pchan_mat3_to_rot(), mat3_to_eulO(), mat4_normalized_to_eulO(), mat4_to_eulO(), Matrix_to_euler(), and quat_to_eulO().

◆ mat3_normalized_to_eulo2()

static void mat3_normalized_to_eulo2 ( const float  mat[3][3],
float  eul1[3],
float  eul2[3],
const short  order 
)
static

◆ mat3_normalized_to_quat()

void mat3_normalized_to_quat ( float  q[4],
const float  mat[3][3] 
)

◆ mat3_to_axis_angle()

void mat3_to_axis_angle ( float  axis[3],
float angle,
const float  mat[3][3] 
)

◆ mat3_to_compatible_eul()

void mat3_to_compatible_eul ( float  eul[3],
const float  oldrot[3],
float  mat[3][3] 
)

Definition at line 1564 of file math_rotation.c.

References mat3_normalized_to_compatible_eul(), and normalize_m3_m3().

◆ mat3_to_compatible_eulO()

void mat3_to_compatible_eulO ( float  eul[3],
const float  oldrot[3],
const short  order,
const float  mat[3][3] 
)

◆ mat3_to_eul()

void mat3_to_eul ( float  eul[3],
const float  mat[3][3] 
)

◆ mat3_to_eulO()

void mat3_to_eulO ( float  eul[3],
const short  order,
const float  m[3][3] 
)

◆ mat3_to_quat()

void mat3_to_quat ( float  q[4],
const float  m[3][3] 
)

◆ mat3_to_quat_is_ok()

void mat3_to_quat_is_ok ( float  q[4],
const float  mat[3][3] 
)

◆ mat4_normalized_to_axis_angle()

void mat4_normalized_to_axis_angle ( float  axis[3],
float angle,
const float  M[4][4] 
)

4x4 matrix to axis angle.

Definition at line 1182 of file math_rotation.c.

References angle(), mat4_normalized_to_quat(), and quat_to_axis_angle().

◆ mat4_normalized_to_compatible_eulO()

void mat4_normalized_to_compatible_eulO ( float  eul[3],
const float  oldrot[3],
const short  order,
const float  m[4][4] 
)

Definition at line 1833 of file math_rotation.c.

References copy_m3_m4(), mat3_normalized_to_compatible_eulO(), and order.

◆ mat4_normalized_to_eul()

void mat4_normalized_to_eul ( float  eul[3],
const float  m[4][4] 
)

Definition at line 1422 of file math_rotation.c.

References copy_m3_m4(), and mat3_normalized_to_eul().

◆ mat4_normalized_to_eulO()

void mat4_normalized_to_eulO ( float  eul[3],
short  order,
const float  mat[4][4] 
)

Convert 4x4 matrix to Euler angles (in radians).

Definition at line 1781 of file math_rotation.c.

References copy_m3_m4(), mat3_normalized_to_eulO(), and order.

◆ mat4_normalized_to_quat()

void mat4_normalized_to_quat ( float  q[4],
const float  m[4][4] 
)

Definition at line 345 of file math_rotation.c.

References copy_m3_m4(), and mat3_normalized_to_quat().

Referenced by mat4_normalized_to_axis_angle(), and obmat_to_viewmat().

◆ mat4_to_axis_angle()

void mat4_to_axis_angle ( float  axis[3],
float angle,
const float  M[4][4] 
)

4x4 matrix to axis angle.

Definition at line 1192 of file math_rotation.c.

References angle(), mat4_to_quat(), and quat_to_axis_angle().

Referenced by constraintRotLim(), and visualkey_get_values().

◆ mat4_to_compatible_eulO()

void mat4_to_compatible_eulO ( float  eul[3],
const float  oldrot[3],
const short  order,
const float  m[4][4] 
)

Definition at line 1844 of file math_rotation.c.

References copy_m3_m4(), mat3_normalized_to_compatible_eulO(), normalize_m3(), and order.

Referenced by rotlike_evaluate().

◆ mat4_to_dquat()

void mat4_to_dquat ( DualQuat dq,
const float  basemat[4][4],
const float  mat[4][4] 
)

◆ mat4_to_eul()

void mat4_to_eul ( float  eul[3],
const float  m[4][4] 
)

Definition at line 1428 of file math_rotation.c.

References copy_m3_m4(), and mat3_to_eul().

Referenced by actcon_get_tarmat(), bc_decompose(), and blender::float4x4::to_euler().

◆ mat4_to_eulO()

void mat4_to_eulO ( float  eul[3],
const short  order,
const float  m[4][4] 
)

◆ mat4_to_quat()

void mat4_to_quat ( float  q[4],
const float  m[4][4] 
)

◆ mod_inline()

static float mod_inline ( float  a,
float  b 
)
static

Definition at line 2259 of file math_rotation.c.

References Freestyle::a, usdtokens::b(), and floorf.

Referenced by angle_wrap_deg(), and angle_wrap_rad().

◆ mul_qt_fl()

void mul_qt_fl ( float  q[4],
float  f 
)

◆ mul_qt_qtqt()

void mul_qt_qtqt ( float  q[4],
const float  a[4],
const float  b[4] 
)

◆ mul_qt_v3()

void mul_qt_v3 ( const float  q[4],
float  r[3] 
)
Note
Assumes a unit quaternion?

in fact not, but you may want to use a unit quaternion read on...

Shortcut for 'q v q*' when v is actually a quaternion. This removes the need for converting a vector to a quaternion, calculating q's conjugate and converting back to a vector. It also happens to be faster (17+,24* vs * 24+,32*). If q is not a unit quaternion, then v will be both rotated by the same amount as if q was a unit quaternion, and scaled by the square of the length of q.

For people used to python mathutils, its like: def mul_qt_v3(q, v): (q * Quaternion((0.0, v[0], v[1], v[2])) * q.conjugated())[1:]

Note
Multiplying by 3x3 matrix is ~25% faster.

Definition at line 59 of file math_rotation.c.

References r.

Referenced by axis_angle_to_gimbal_axis(), bevel_list_smooth(), BKE_gpencil_stroke_stretch(), bm_edgering_pair_interpolate(), boid_body(), calc_curve_deform(), curve_create_edit_curves_nor(), do_guides(), do_kink(), do_physical_effector(), draw_view_axis(), DRW_draw_cursor(), ED_view3d_cursor3d_position_rotation(), ED_view3d_distance_set(), ED_view3d_distance_set_from_location(), explodeMesh(), get_effector_data(), gizmo_ruler_draw(), knifetool_draw_angle(), make_bevel_list_3D_minimum_twist(), mball_select_similar_type(), mball_select_similar_type_get(), modifyMesh(), offset_child(), psys_get_birth_coords(), psys_get_dupli_path_transform(), psys_thread_create_path(), Quaternion_matmul(), recalcData_edit_armature(), rotateBevelPiece(), rule_average_speed(), sculpt_rake_rotate(), view3d_boxview_sync_axis(), view3d_orbit_apply_dyn_ofs(), viewrotate_apply_snap(), wm_xr_navigation_reset_exec(), and wm_xr_raycast_update().

◆ mul_v3m3_dq()

void mul_v3m3_dq ( float  r[3],
float  R[3][3],
DualQuat dq 
)

◆ normalize_dq()

void normalize_dq ( DualQuat dq,
float  totweight 
)

◆ normalize_qt()

float normalize_qt ( float  q[4])

◆ normalize_qt_qt()

float normalize_qt_qt ( float  r[4],
const float  q[4] 
)

◆ pow_qt_fl_normalized()

void pow_qt_fl_normalized ( float  q[4],
float  f 
)

◆ print_qt()

void print_qt ( const char *  str,
const float  q[4] 
)

Definition at line 1021 of file math_rotation.c.

References str.

◆ quat_apply_track()

void quat_apply_track ( float  quat[4],
short  axis,
short  upflag 
)

Axis matches eTrackToAxis_Modes.

Definition at line 2168 of file math_rotation.c.

References BLI_assert, float(), M_SQRT1_2, and mul_qt_qtqt().

Referenced by calc_curve_deform(), followpath_get_tarmat(), and ob_parcurve().

◆ quat_normalized_to_expmap()

void quat_normalized_to_expmap ( float  expmap[3],
const float  q[4] 
)

Definition at line 1282 of file math_rotation.c.

References angle(), BLI_ASSERT_UNIT_QUAT, mul_v3_fl(), and quat_to_axis_angle().

Referenced by quat_to_expmap().

◆ quat_split_swing_and_twist()

float quat_split_swing_and_twist ( const float  q[4],
int  axis,
float  r_swing[4],
float  r_twist[4] 
)

Decompose a quaternion into a swing rotation (quaternion with the selected axis component locked at zero), followed by a twist rotation around the axis.

Parameters
qinput quaternion.
axistwist axis in [0,1,2]
r_swingif not NULL, receives the swing quaternion.
r_twistif not NULL, receives the twist quaternion.
Returns
twist angle.

Definition at line 501 of file math_rotation.c.

References atan2f, BLI_assert, BLI_ASSERT_UNIT_EPSILON, copy_v4_v4(), cosf, fabsf, mul_qt_qtqt(), negate_v4_v4(), sinf, t, and zero_v3().

Referenced by BKE_driver_target_matrix_to_rot_channels(), mat3_vec_to_roll(), Quaternion_to_swing_twist(), and TEST().

◆ quat_to_axis_angle()

void quat_to_axis_angle ( float  axis[3],
float angle,
const float  q[4] 
)

◆ quat_to_compatible_eul()

void quat_to_compatible_eul ( float  eul[3],
const float  oldrot[3],
const float  quat[4] 
)

◆ quat_to_compatible_eulO()

void quat_to_compatible_eulO ( float  eul[3],
const float  oldrot[3],
const short  order,
const float  quat[4] 
)

◆ quat_to_compatible_quat()

void quat_to_compatible_quat ( float  q[4],
const float  a[4],
const float  old[4] 
)

Apply the rotation of a to q keeping the values compatible with old. Avoid axis flipping for animated f-curves for eg.

Definition at line 158 of file math_rotation.c.

References Freestyle::a, BLI_ASSERT_UNIT_QUAT, copy_qt_qt(), eps, len_squared_v4v4(), mul_qt_qtqt(), negate_v4_v4(), normalize_qt_qt(), and rotation_between_quats_to_quat().

Referenced by BKE_scene_cursor_mat3_to_rot(), BKE_scene_cursor_quat_to_rot(), pose_slide_apply_quat(), and Quaternion_make_compatible().

◆ quat_to_eul()

void quat_to_eul ( float  eul[3],
const float  quat[4] 
)

◆ quat_to_eulO()

void quat_to_eulO ( float  eul[3],
short  order,
const float  quat[4] 
)

◆ quat_to_expmap()

void quat_to_expmap ( float  expmap[3],
const float  q[4] 
)

Definition at line 1294 of file math_rotation.c.

References normalize_qt_qt(), and quat_normalized_to_expmap().

Referenced by Quaternion_to_exponential_map().

◆ quat_to_mat3()

void quat_to_mat3 ( float  m[3][3],
const float  q[4] 
)

◆ quat_to_mat3_no_error()

static void quat_to_mat3_no_error ( float  m[3][3],
const float  q[4] 
)
static

Definition at line 180 of file math_rotation.c.

References double(), float(), M_SQRT2, and q1.

Referenced by mat3_to_quat_is_ok(), and quat_to_mat3().

◆ quat_to_mat4()

void quat_to_mat4 ( float  m[4][4],
const float  q[4] 
)

◆ rotate_eul()

void rotate_eul ( float  beul[3],
const char  axis,
const float  ang 
)

Definition at line 1466 of file math_rotation.c.

References BLI_assert, eul_to_mat3(), mat3_to_eul(), and mul_m3_m3m3().

◆ rotate_eulO()

void rotate_eulO ( float  beul[3],
const short  order,
char  axis,
float  ang 
)

◆ rotation_between_quats_to_quat()

void rotation_between_quats_to_quat ( float  q[4],
const float  q1[4],
const float  q2[4] 
)

◆ rotation_between_vecs_to_mat3()

void rotation_between_vecs_to_mat3 ( float  m[3][3],
const float  v1[3],
const float  v2[3] 
)

◆ rotation_between_vecs_to_quat()

void rotation_between_vecs_to_quat ( float  q[4],
const float  v1[3],
const float  v2[3] 
)

◆ sin_cos_from_fraction()

void sin_cos_from_fraction ( int  numerator,
int  denominator,
float r_sin,
float r_cos 
)

Utility that performs sinf & cosf intended for plotting a 2D circle, where the values of the coordinates with are exactly symmetrical although this favors even numbers as odd numbers can only be symmetrical on a single axis.

Besides adjustments to precision, this function is the equivalent of:

float phi = (2 * M_PI) * (float)i / (float)denominator;
*r_sin = sinf(phi);
*r_cos = cosf(phi);
typedef float(TangentPoint)[2]
#define M_PI
Definition: BLI_math_base.h:20
#define sinf(x)
Definition: cuda/compat.h:102
#define cosf(x)
Definition: cuda/compat.h:101
Parameters
numeratorAn integer factor in [0..denominator] (inclusive).
denominatorThe faction denominator (typically the number of segments of the circle).
r_sinThe resulting sine.
r_cosThe resulting cosine.

Definition at line 918 of file math_rotation.c.

References BLI_assert, cosf, float(), M_PI, and sinf.

Referenced by bmo_create_circle_exec(), bmo_create_cone_exec(), bmo_create_uvsphere_exec(), test_sin_cos_from_fraction_accuracy(), and test_sin_cos_from_fraction_symmetry().

◆ sub_eul_euleul()

void sub_eul_euleul ( float  r_eul[3],
float  a[3],
float  b[3],
const short  order 
)

◆ sub_qt_qtqt()

void sub_qt_qtqt ( float  q[4],
const float  a[4],
const float  b[4] 
)

◆ tri_to_quat()

float tri_to_quat ( float  q[4],
const float  a[3],
const float  b[3],
const float  c[3] 
)
Returns
the length of the normal, use to test for degenerate triangles.

Definition at line 909 of file math_rotation.c.

References Freestyle::a, usdtokens::b(), Freestyle::c, len, normal_tri_v3(), and tri_to_quat_ex().

Referenced by make_bevel_list_3D_tangent(), and ob_parvert3().

◆ tri_to_quat_ex()

void tri_to_quat_ex ( float  quat[4],
const float  v1[3],
const float  v2[3],
const float  v3[3],
const float  no_orig[3] 
)

Same as tri_to_quat() but takes pre-computed normal from the triangle used for ngons when we know their normal.

Definition at line 857 of file math_rotation.c.

References angle(), atan2f, copy_v3_v3(), cosf, invert_m3_m3(), mul_m3_v3(), mul_qt_qtqt(), normal_tri_v3(), normalize_v3(), q1, quat_to_mat3(), saacos(), sinf, sub_v3_v3v3(), v1, v2, and void.

Referenced by get_dupliface_transform_from_coords(), tan_calc_quat_v3(), and tri_to_quat().

◆ unit_axis_angle()

void unit_axis_angle ( float  axis[3],
float angle 
)

◆ unit_qt()

void unit_qt ( float  q[4])

◆ vec_apply_track()

void vec_apply_track ( float  vec[3],
short  axis 
)

Definition at line 2206 of file math_rotation.c.

References BLI_assert, and copy_v3_v3().

Referenced by calc_curve_deform().

◆ vec_to_quat()

void vec_to_quat ( float  q[4],
const float  vec[3],
short  axis,
const short  upflag 
)

Variable Documentation

◆ _axis_convert_lut

int _axis_convert_lut[23][24]
static

Definition at line 2306 of file math_rotation.c.

Referenced by mat3_from_axis_conversion().

◆ _axis_convert_matrix

float _axis_convert_matrix[23][3][3]
static
Initial value:
= {
{{-1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}},
{{-1.0, 0.0, 0.0}, {0.0, 0.0, -1.0}, {0.0, -1.0, 0.0}},
{{-1.0, 0.0, 0.0}, {0.0, 0.0, 1.0}, {0.0, 1.0, 0.0}},
{{-1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, -1.0}},
{{0.0, -1.0, 0.0}, {-1.0, 0.0, 0.0}, {0.0, 0.0, -1.0}},
{{0.0, 0.0, 1.0}, {-1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}},
{{0.0, 0.0, -1.0}, {-1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}},
{{0.0, 1.0, 0.0}, {-1.0, 0.0, 0.0}, {0.0, 0.0, 1.0}},
{{0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}, {-1.0, 0.0, 0.0}},
{{0.0, 0.0, -1.0}, {0.0, -1.0, 0.0}, {-1.0, 0.0, 0.0}},
{{0.0, 0.0, 1.0}, {0.0, 1.0, 0.0}, {-1.0, 0.0, 0.0}},
{{0.0, 1.0, 0.0}, {0.0, 0.0, -1.0}, {-1.0, 0.0, 0.0}},
{{0.0, -1.0, 0.0}, {0.0, 0.0, -1.0}, {1.0, 0.0, 0.0}},
{{0.0, 0.0, 1.0}, {0.0, -1.0, 0.0}, {1.0, 0.0, 0.0}},
{{0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}},
{{0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}, {1.0, 0.0, 0.0}},
{{0.0, -1.0, 0.0}, {1.0, 0.0, 0.0}, {0.0, 0.0, 1.0}},
{{0.0, 0.0, -1.0}, {1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}},
{{0.0, 0.0, 1.0}, {1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}},
{{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {0.0, 0.0, -1.0}},
{{1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, -1.0}},
{{1.0, 0.0, 0.0}, {0.0, 0.0, 1.0}, {0.0, -1.0, 0.0}},
{{1.0, 0.0, 0.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}},
}

Definition at line 2280 of file math_rotation.c.

Referenced by mat3_from_axis_conversion().

◆ rotOrders

const RotOrderInfo rotOrders[]
static
Initial value:
= {
{{0, 1, 2}, 0},
{{0, 2, 1}, 1},
{{1, 0, 2}, 1},
{{1, 2, 0}, 0},
{{2, 0, 1}, 0},
{{2, 1, 0}, 1}
}

Definition at line 1598 of file math_rotation.c.

Referenced by get_rotation_order_info().