[Bf-blender-cvs] [96fa58e] master: Math Lib: Add closest_to_plane helper functions

Campbell Barton noreply at git.blender.org
Mon Aug 31 14:26:47 CEST 2015


Commit: 96fa58e22cde8329bfc5639f9a68c85be9473b1d
Author: Campbell Barton
Date:   Mon Aug 31 20:05:49 2015 +1000
Branches: master
https://developer.blender.org/rB96fa58e22cde8329bfc5639f9a68c85be9473b1d

Math Lib: Add closest_to_plane helper functions

- closest_to_plane3 (for float3 planes)
- closest_to_plane*_normalized_v3 (for unit length planes)

Use when the plane is known to be unit length

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

M	source/blender/blenlib/BLI_math_geom.h
M	source/blender/blenlib/intern/math_geom.c
M	source/blender/bmesh/operators/bmo_planar_faces.c
M	source/blender/bmesh/tools/bmesh_bevel.c
M	source/blender/editors/object/object_vgroup.c

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

diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h
index 1a25f9f..c4bb3cc 100644
--- a/source/blender/blenlib/BLI_math_geom.h
+++ b/source/blender/blenlib/BLI_math_geom.h
@@ -119,7 +119,10 @@ float dist_signed_squared_to_corner_v3v3v3(
 float closest_to_line_v3(float r[3], const float p[3], const float l1[3], const float l2[3]);
 float closest_to_line_v2(float r[2], const float p[2], const float l1[2], const float l2[2]);
 void closest_to_line_segment_v3(float r_close[3], const float p[3], const float l1[3], const float l2[3]);
+void closest_to_plane_normalized_v3(float r_close[3], const float plane[4], const float pt[3]);
 void closest_to_plane_v3(float r_close[3], const float plane[4], const float pt[3]);
+void closest_to_plane3_normalized_v3(float r_close[3], const float plane[3], const float pt[3]);
+void closest_to_plane3_v3(float r_close[3], const float plane[3], const float pt[3]);
 
 /* Set 'r' to the point in triangle (t1, t2, t3) closest to point 'p' */
 void closest_on_tri_to_point_v3(float r[3], const float p[3], const float t1[3], const float t2[3], const float t3[3]);
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index 379c852..f7c2ad7 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -380,6 +380,27 @@ void closest_to_plane_v3(float r_close[3], const float plane[4], const float pt[
 	madd_v3_v3v3fl(r_close, pt, plane, -side / len_sq);
 }
 
+void closest_to_plane_normalized_v3(float r_close[3], const float plane[4], const float pt[3])
+{
+	const float side = plane_point_side_v3(plane, pt);
+	BLI_ASSERT_UNIT_V3(plane);
+	madd_v3_v3v3fl(r_close, pt, plane, -side);
+}
+
+void closest_to_plane3_v3(float r_close[3], const float plane[3], const float pt[3])
+{
+	const float len_sq = len_squared_v3(plane);
+	const float side = dot_v3v3(plane, pt);
+	madd_v3_v3v3fl(r_close, pt, plane, -side / len_sq);
+}
+
+void closest_to_plane3_normalized_v3(float r_close[3], const float plane[3], const float pt[3])
+{
+	const float side = dot_v3v3(plane, pt);
+	BLI_ASSERT_UNIT_V3(plane);
+	madd_v3_v3v3fl(r_close, pt, plane, -side);
+}
+
 float dist_signed_squared_to_plane_v3(const float pt[3], const float plane[4])
 {
 	const float len_sq = len_squared_v3(plane);
diff --git a/source/blender/bmesh/operators/bmo_planar_faces.c b/source/blender/bmesh/operators/bmo_planar_faces.c
index 4e3ac58..8849e49 100644
--- a/source/blender/bmesh/operators/bmo_planar_faces.c
+++ b/source/blender/bmesh/operators/bmo_planar_faces.c
@@ -117,7 +117,7 @@ void bmo_planar_faces_exec(BMesh *bm, BMOperator *op)
 				}
 				va = *va_p;
 
-				closest_to_plane_v3(co, plane, l_iter->v->co);
+				closest_to_plane_normalized_v3(co, plane, l_iter->v->co);
 				va->co_tot += 1;
 
 				interp_v3_v3v3(va->co, va->co, co, 1.0f / (float)va->co_tot);
diff --git a/source/blender/bmesh/tools/bmesh_bevel.c b/source/blender/bmesh/tools/bmesh_bevel.c
index e20d4e6..c7f77a7 100644
--- a/source/blender/bmesh/tools/bmesh_bevel.c
+++ b/source/blender/bmesh/tools/bmesh_bevel.c
@@ -823,7 +823,7 @@ static void offset_meet(EdgeHalf *e1, EdgeHalf *e2, BMVert *v, BMFace *f, bool e
 					if (!ff)
 						continue;
 					plane_from_point_normal_v3(plane, v->co, ff->no);
-					closest_to_plane_v3(dropco, plane, meetco);
+					closest_to_plane_normalized_v3(dropco, plane, meetco);
 					if (point_between_edges(dropco, v, ff, e, e->next)) {
 						copy_v3_v3(meetco, dropco);
 						break;
diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c
index d52031e..d7de3db 100644
--- a/source/blender/editors/object/object_vgroup.c
+++ b/source/blender/editors/object/object_vgroup.c
@@ -1213,8 +1213,8 @@ static void getVerticalAndHorizontalChange(const float norm[3], float d, const f
 
 	plane_from_point_normal_v3(plane, coord, norm);
 
-	closest_to_plane_v3(projA, plane, start);
-	closest_to_plane_v3(projB, plane, end);
+	closest_to_plane_normalized_v3(projA, plane, start);
+	closest_to_plane_normalized_v3(projB, plane, end);
 	/* (vertical and horizontal refer to the plane's y and xz respectively)
 	 * vertical distance */
 	dists[index] = dot_v3v3(norm, end) + d;




More information about the Bf-blender-cvs mailing list