[Bf-blender-cvs] [01b1eb4] master: Math Lib: add project_plane_v3_v3v3

Campbell Barton noreply at git.blender.org
Wed Apr 8 15:05:17 CEST 2015


Commit: 01b1eb445ceb7200d9ac4d00eb624d92713024c7
Author: Campbell Barton
Date:   Wed Apr 8 22:49:07 2015 +1000
Branches: master
https://developer.blender.org/rB01b1eb445ceb7200d9ac4d00eb624d92713024c7

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.

===================================================================

M	source/blender/blenlib/BLI_math_vector.h
M	source/blender/blenlib/intern/math_vector.c

===================================================================

diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h
index de712cb..9c8a9f5 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 814180b..e9909ce 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])
 {




More information about the Bf-blender-cvs mailing list