diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-06-15 18:25:08 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-06-15 18:27:58 +0300 |
commit | 1d966ca7a145155b594146667244131bc5b12a36 (patch) | |
tree | 87b09dec5381ac455114352ef324d857d62d62c0 /source/blender/blenlib/intern/math_vector.c | |
parent | 3d03616772b760f968bd4d4791c6073817c10586 (diff) |
Math Lib: add angle_on_axis_v3v3_v3
Use for calculating the angle between 2 directions on an axis.
Also signed version and normalized plane projection,
use when input is normalized.
Diffstat (limited to 'source/blender/blenlib/intern/math_vector.c')
-rw-r--r-- | source/blender/blenlib/intern/math_vector.c | 71 |
1 files changed, 51 insertions, 20 deletions
diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c index 37897e2cd32..c6e9b8229ba 100644 --- a/source/blender/blenlib/intern/math_vector.c +++ b/source/blender/blenlib/intern/math_vector.c @@ -518,38 +518,27 @@ float angle_normalized_v2v2(const float v1[2], const float v2[2]) } /** - * angle between 2 vectors defined by 3 coords, about an axis. */ -float angle_on_axis_v3v3v3_v3(const float v1[3], const float v2[3], const float v3[3], const float axis[3]) + * Angle between 2 vectors, about an axis (axis can be considered a plane). + */ +float angle_on_axis_v3v3_v3(const float v1[3], const float v2[3], const float axis[3]) { - float v1_proj[3], v2_proj[3], tproj[3]; - - sub_v3_v3v3(v1_proj, v1, v2); - sub_v3_v3v3(v2_proj, v3, v2); + float v1_proj[3], v2_proj[3]; /* project the vectors onto the axis */ - project_v3_v3v3(tproj, v1_proj, axis); - sub_v3_v3(v1_proj, tproj); - - project_v3_v3v3(tproj, v2_proj, axis); - sub_v3_v3(v2_proj, tproj); + project_plane_normalized_v3_v3v3(v1_proj, v1, axis); + project_plane_normalized_v3_v3v3(v2_proj, v2, axis); return angle_v3v3(v1_proj, v2_proj); } -float angle_signed_on_axis_v3v3v3_v3(const float v1[3], const float v2[3], const float v3[3], const float axis[3]) +float angle_signed_on_axis_v3v3_v3(const float v1[3], const float v2[3], const float axis[3]) { float v1_proj[3], v2_proj[3], tproj[3]; float angle; - sub_v3_v3v3(v1_proj, v1, v2); - sub_v3_v3v3(v2_proj, v3, v2); - /* project the vectors onto the axis */ - project_v3_v3v3(tproj, v1_proj, axis); - sub_v3_v3(v1_proj, tproj); - - project_v3_v3v3(tproj, v2_proj, axis); - sub_v3_v3(v2_proj, tproj); + project_plane_normalized_v3_v3v3(v1_proj, v1, axis); + project_plane_normalized_v3_v3v3(v2_proj, v2, axis); angle = angle_v3v3(v1_proj, v2_proj); @@ -562,6 +551,29 @@ float angle_signed_on_axis_v3v3v3_v3(const float v1[3], const float v2[3], const return angle; } +/** + * Angle between 2 vectors defined by 3 coords, about an axis (axis can be considered a plane). + */ +float angle_on_axis_v3v3v3_v3(const float v1[3], const float v2[3], const float v3[3], const float axis[3]) +{ + float vec1[3], vec2[3]; + + sub_v3_v3v3(vec1, v1, v2); + sub_v3_v3v3(vec2, v3, v2); + + return angle_on_axis_v3v3_v3(vec1, vec2, axis); +} + +float angle_signed_on_axis_v3v3v3_v3(const float v1[3], const float v2[3], const float v3[3], const float axis[3]) +{ + float vec1[3], vec2[3]; + + sub_v3_v3v3(vec1, v1, v2); + sub_v3_v3v3(vec2, v3, v2); + + return angle_signed_on_axis_v3v3_v3(vec1, vec2, axis); +} + void angle_tri_v3(float angles[3], const float v1[3], const float v2[3], const float v3[3]) { float ed1[3], ed2[3], ed3[3]; @@ -669,6 +681,25 @@ void project_plane_v2_v2v2(float out[2], const float p[2], const float v_plane[2 out[1] = p[1] - (mul * v_plane[1]); } +void project_plane_normalized_v3_v3v3(float out[3], const float p[3], const float v_plane[3]) +{ + BLI_ASSERT_UNIT_V3(v_plane); + const float mul = dot_v3v3(p, v_plane); + + out[0] = p[0] - (mul * v_plane[0]); + out[1] = p[1] - (mul * v_plane[1]); + out[2] = p[2] - (mul * v_plane[2]); +} + +void project_plane_normalized_v2_v2v2(float out[2], const float p[2], const float v_plane[2]) +{ + BLI_ASSERT_UNIT_V2(v_plane); + const float mul = dot_v2v2(p, v_plane); + + out[0] = p[0] - (mul * v_plane[0]); + out[1] = p[1] - (mul * v_plane[1]); +} + /* project a vector on a plane defined by normal and a plane point p */ void project_v3_plane(float out[3], const float plane_no[3], const float plane_co[3]) { |