diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-08-23 09:15:12 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-08-23 09:15:12 +0400 |
commit | 77fa1aaab58c3adfad9a508cea6811cea6cd10b6 (patch) | |
tree | 08950db24c01de2275c35a08db2b765c7ce6291b /source | |
parent | 6cba2b8d73d80be30205aede15e6f1a0f787623a (diff) |
modify closest_to_plane_v3 not to use point-normal form.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenlib/BLI_math_geom.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_geom.c | 28 | ||||
-rw-r--r-- | source/blender/bmesh/tools/bmesh_bevel.c | 8 | ||||
-rw-r--r-- | source/blender/editors/object/object_vgroup.c | 7 |
4 files changed, 22 insertions, 23 deletions
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h index 51b89df0e4e..4a43873f070 100644 --- a/source/blender/blenlib/BLI_math_geom.h +++ b/source/blender/blenlib/BLI_math_geom.h @@ -89,7 +89,7 @@ float dist_to_line_v3(const float p[3], const float l1[3], const float l2[3]); 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]); diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index 11b50802a22..2b5b0c5d0d2 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -305,24 +305,20 @@ void closest_to_line_segment_v3(float close_r[3], const float v1[3], const float 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 */ diff --git a/source/blender/bmesh/tools/bmesh_bevel.c b/source/blender/bmesh/tools/bmesh_bevel.c index 04c20dd9052..adeb3fdc630 100644 --- a/source/blender/bmesh/tools/bmesh_bevel.c +++ b/source/blender/bmesh/tools/bmesh_bevel.c @@ -734,14 +734,14 @@ static void snap_to_edge_profile(EdgeHalf *e, const float va[3], const float vb[ 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. diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 294b0632015..b68fa150777 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -1561,9 +1561,12 @@ static void getVerticalAndHorizontalChange(const float norm[3], float d, const f /* 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; |