diff options
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_math_vector.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_vector.c | 21 |
2 files changed, 23 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h index de712cbaa12..9c8a9f54379 100644 --- a/source/blender/blenlib/BLI_math_vector.h +++ b/source/blender/blenlib/BLI_math_vector.h @@ -271,6 +271,8 @@ void angle_poly_v3(float *angles, const float *verts[3], int len); void project_v2_v2v2(float c[2], const float v1[2], const float v2[2]); void project_v3_v3v3(float r[3], const float p[3], const float n[3]); +void project_plane_v3_v3v3(float c[3], const float v[3], const float v_plane[3]); +void project_plane_v2_v2v2(float c[2], const float v[2], const float v_plane[2]); void project_v3_plane(float v[3], const float n[3], const float p[3]); void reflect_v3_v3v3(float r[3], const float v[3], const float n[3]); void ortho_basis_v3v3_v3(float r_n1[3], float r_n2[3], const float n[3]); 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]) { |