diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-08-31 13:05:49 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-08-31 13:10:36 +0300 |
commit | 96fa58e22cde8329bfc5639f9a68c85be9473b1d (patch) | |
tree | e08ee7ba170837de7b6171d3553b043667dfeeae /source | |
parent | 489a5d34b7bf84141696e99274a4cbd7425a9b7b (diff) |
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
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenlib/BLI_math_geom.h | 3 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_geom.c | 21 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_planar_faces.c | 2 | ||||
-rw-r--r-- | source/blender/bmesh/tools/bmesh_bevel.c | 2 | ||||
-rw-r--r-- | source/blender/editors/object/object_vgroup.c | 4 |
5 files changed, 28 insertions, 4 deletions
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h index 1a25f9f897f..c4bb3cc7778 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 379c8524601..f7c2ad72d00 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 4e3ac58a813..8849e498bc0 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 e20d4e61d01..c7f77a7604f 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 d52031ecc03..d7de3db5e5d 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; |