[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59397] trunk/blender/source/blender: modify closest_to_plane_v3 not to use point-normal form.

Campbell Barton ideasman42 at gmail.com
Fri Aug 23 07:15:12 CEST 2013


Revision: 59397
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59397
Author:   campbellbarton
Date:     2013-08-23 05:15:12 +0000 (Fri, 23 Aug 2013)
Log Message:
-----------
modify closest_to_plane_v3 not to use point-normal form.

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_math_geom.h
    trunk/blender/source/blender/blenlib/intern/math_geom.c
    trunk/blender/source/blender/bmesh/tools/bmesh_bevel.c
    trunk/blender/source/blender/editors/object/object_vgroup.c

Modified: trunk/blender/source/blender/blenlib/BLI_math_geom.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_geom.h	2013-08-23 05:04:08 UTC (rev 59396)
+++ trunk/blender/source/blender/blenlib/BLI_math_geom.h	2013-08-23 05:15:12 UTC (rev 59397)
@@ -89,7 +89,7 @@
 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[3], const float p[3], const float l1[3], const float l2[3]);
-void closest_to_plane_v3(float r[3], const float plane_co[3], const float plane_no_unit[3], const float pt[3]);
+void closest_to_plane_v3(float close_r[3], const float plane[4], 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]);

Modified: trunk/blender/source/blender/blenlib/intern/math_geom.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_geom.c	2013-08-23 05:04:08 UTC (rev 59396)
+++ trunk/blender/source/blender/blenlib/intern/math_geom.c	2013-08-23 05:15:12 UTC (rev 59397)
@@ -305,24 +305,20 @@
 		copy_v3_v3(close_r, cp);
 }
 
-/* find the closest point on a plane to another point and store it in close_r
- * close_r:       return coordinate
- * plane_co:      a point on the plane
- * plane_no_unit: the plane's normal, and d is the last number in the plane equation 0 = ax + by + cz + d
- * pt:            the point that you want the nearest of
+/**
+ * Find the closest point on a plane.
+ *
+ * \param close_r  Return coordinate
+ * \param plane  The plane to test against.
+ * \param pt  The point to find the nearest of
+ *
+ * \note non-unit-length planes are supported.
  */
-
-void closest_to_plane_v3(float close_r[3], const float plane_co[3], const float plane_no_unit[3], const float pt[3])
+void closest_to_plane_v3(float close_r[3], const float plane[4], const float pt[3])
 {
-	float temp[3];
-	float dotprod;
-
-	sub_v3_v3v3(temp, pt, plane_co);
-	dotprod = dot_v3v3(temp, plane_no_unit);
-
-	close_r[0] = pt[0] - (plane_no_unit[0] * dotprod);
-	close_r[1] = pt[1] - (plane_no_unit[1] * dotprod);
-	close_r[2] = pt[2] - (plane_no_unit[2] * dotprod);
+	const float length = len_squared_v3(plane);
+	const float side = plane_point_side_v3(plane, pt);
+	madd_v3_v3v3fl(close_r, pt, plane, -side / length);
 }
 
 /* signed distance from the point to the plane in 3D */

Modified: trunk/blender/source/blender/bmesh/tools/bmesh_bevel.c
===================================================================
--- trunk/blender/source/blender/bmesh/tools/bmesh_bevel.c	2013-08-23 05:04:08 UTC (rev 59396)
+++ trunk/blender/source/blender/bmesh/tools/bmesh_bevel.c	2013-08-23 05:15:12 UTC (rev 59397)
@@ -734,14 +734,14 @@
                                  float co[3])
 {
 	float m[4][4], minv[4][4];
-	float edir[3], va0[3], vb0[3], vmid0[3], p[3], snap[3];
+	float edir[3], va0[3], vb0[3], vmid0[3], p[3], snap[3], plane[4];
 
 	sub_v3_v3v3(edir, e->e->v1->co, e->e->v2->co);
-	normalize_v3(edir);
 
 	/* project va and vb onto plane P, with normal edir and containing co */
-	closest_to_plane_v3(va0, co, edir, va);
-	closest_to_plane_v3(vb0, co, edir, vb);
+	plane_from_point_normal_v3(plane, co, edir);
+	closest_to_plane_v3(va0, plane, va);
+	closest_to_plane_v3(vb0, plane, vb);
 	project_to_edge(e->e, va0, vb0, vmid0);
 	if (make_unit_square_map(va0, vmid0, vb0, m)) {
 		/* Transform co and project it onto the unit circle.

Modified: trunk/blender/source/blender/editors/object/object_vgroup.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_vgroup.c	2013-08-23 05:04:08 UTC (rev 59396)
+++ trunk/blender/source/blender/editors/object/object_vgroup.c	2013-08-23 05:15:12 UTC (rev 59397)
@@ -1561,9 +1561,12 @@
 	/* A = Q - ((Q - P).N)N
 	 * D = (a * x0 + b * y0 +c * z0 + d) */
 	float projA[3], projB[3];
+	float plane[4];
 
-	closest_to_plane_v3(projA, coord, norm, start);
-	closest_to_plane_v3(projB, coord, norm, end);
+	plane_from_point_normal_v3(plane, coord, norm);
+
+	closest_to_plane_v3(projA, plane, start);
+	closest_to_plane_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