From 01b1eb445ceb7200d9ac4d00eb624d92713024c7 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 8 Apr 2015 22:49:07 +1000 Subject: Math Lib: add project_plane_v3_v3v3 Useful for projecting one vector onto another (as a plane). This is a rather common operation, doing inline isn't always obvious whats happening. --- source/blender/blenlib/intern/math_vector.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'source/blender/blenlib/intern/math_vector.c') diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c index 814180bba24..e9909cef29d 100644 --- a/source/blender/blenlib/intern/math_vector.c +++ b/source/blender/blenlib/intern/math_vector.c @@ -572,6 +572,27 @@ void project_v3_v3v3(float c[3], const float v1[3], const float v2[3]) c[2] = mul * v2[2]; } +/** + * In this case plane is a 3D vector only (no 4th component). + * + * Projecting will make \a c a copy of \a v orthogonal to \a v_plane. + * + * \note If \a v is exactly perpendicular to \a v_plane, \a c will just be a copy of \a v. + */ +void project_plane_v3_v3v3(float c[3], const float v[3], const float v_plane[3]) +{ + float delta[3]; + project_v3_v3v3(delta, v, v_plane); + sub_v3_v3v3(c, v, delta); +} + +void project_plane_v2_v2v2(float c[2], const float v[2], const float v_plane[2]) +{ + float delta[2]; + project_v2_v2v2(delta, v, v_plane); + sub_v2_v2v2(c, v, delta); +} + /* project a vector on a plane defined by normal and a plane point p */ void project_v3_plane(float v[3], const float n[3], const float p[3]) { -- cgit v1.2.3