diff options
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_math_geom.h | 3 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_geom.c | 21 |
2 files changed, 24 insertions, 0 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); |