diff options
author | Campbell Barton <ideasman42@gmail.com> | 2016-05-03 06:30:16 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2016-05-03 06:48:00 +0300 |
commit | 48d3a8b54bf53a1562ceadc32af4cf0b8b1fc4b1 (patch) | |
tree | 79c4399bd6e7fcd894a4e1010fcdc4181a46e002 /source/blender | |
parent | a58a8ebea70aa0834e5c029638e095f67e885246 (diff) |
Math Lib: inline project_plane_v3_v3v3
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenlib/intern/math_vector.c | 21 |
1 files changed, 15 insertions, 6 deletions
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 */ |