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/blender/blenlib | |
parent | 6cba2b8d73d80be30205aede15e6f1a0f787623a (diff) |
modify closest_to_plane_v3 not to use point-normal form.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_math_geom.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_geom.c | 28 |
2 files changed, 13 insertions, 17 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 */ |