Math Lib: Add closest_to_plane helper functions
authorCampbell Barton <ideasman42@gmail.com>
Mon, 31 Aug 2015 10:05:49 +0000 (20:05 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 31 Aug 2015 10:10:36 +0000 (20:10 +1000)
- 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

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

index 1a25f9f897f3dabe0b9567df98d8244bd1a6d4da..c4bb3cc7778531db5d473f7f3c25b9178634e4e5 100644 (file)
@@ -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]);
index 379c852460171aa18ed7b72d9c9fcdee78282ecb..f7c2ad72d00f511e6fa147e195429d9a389c9162 100644 (file)
@@ -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);
index 4e3ac58a8136478088de17f817d4ea9f21de00fb..8849e498bc0a02aa0924d5aba4dc5b47427e8ff3 100644 (file)
@@ -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);
index e20d4e61d010d04116fc790f4a77c89b069051a6..c7f77a7604fcbf478ddb4ff84cae5ea15d7dd99c 100644 (file)
@@ -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;
index d52031ecc0354f152b87867baeb06cf434e44772..d7de3db5e5dbf324ea3ca2c07ab2d5411341979d 100644 (file)
@@ -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;