From 48d3a8b54bf53a1562ceadc32af4cf0b8b1fc4b1 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 3 May 2016 13:30:16 +1000 Subject: Math Lib: inline project_plane_v3_v3v3 --- source/blender/blenlib/intern/math_vector.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (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 72a3da265c7..3e464327b2e 100644 --- a/source/blender/blenlib/intern/math_vector.c +++ b/source/blender/blenlib/intern/math_vector.c @@ -591,19 +591,28 @@ void project_v3_v3v3(float c[3], const float v1[3], const float v2[3]) * 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. + * + * \note This function is a convenience to call: + * \code{.c} + * project_v3_v3v3(c, v, v_plane); + * sub_v3_v3v3(c, v, c); + * \endcode */ 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); + const float mul = dot_v3v3(v, v_plane) / dot_v3v3(v_plane, v_plane); + + c[0] = v[0] - (mul * v_plane[0]); + c[1] = v[1] - (mul * v_plane[1]); + c[2] = v[2] - (mul * v_plane[2]); } 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); + const float mul = dot_v2v2(v, v_plane) / dot_v2v2(v_plane, v_plane); + + c[0] = v[0] - (mul * v_plane[0]); + c[1] = v[1] - (mul * v_plane[1]); } /* project a vector on a plane defined by normal and a plane point p */ -- cgit v1.2.3