diff options
-rw-r--r-- | source/blender/blenlib/BLI_math_geom.h | 4 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_geom.c | 16 |
2 files changed, 15 insertions, 5 deletions
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h index 9023cdd17bf..4f7a3310ee6 100644 --- a/source/blender/blenlib/BLI_math_geom.h +++ b/source/blender/blenlib/BLI_math_geom.h @@ -74,7 +74,9 @@ float cross_poly_v2(const float verts[][2], unsigned int nr); /********************************* Planes **********************************/ void plane_from_point_normal_v3(float r_plane[4], const float plane_co[3], const float plane_no[3]); -void plane_to_point_normal_v3(const float plane[4], float r_plane_co[3], float r_plane_no[3]); +void plane_to_point_vector_v3(const float plane[4], float r_plane_co[3], float r_plane_no[3]); +void plane_to_point_vector_v3_normalized(const float plane[4], float r_plane_co[3], float r_plane_no[3]); + MINLINE float plane_point_side_v3(const float plane[4], const float co[3]); /********************************* Volume **********************************/ diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index eee78297106..ba1f4480659 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -257,14 +257,22 @@ void plane_from_point_normal_v3(float r_plane[4], const float plane_co[3], const } /** - * Get a point and a normal from a plane. + * Get a point and a direction from a plane. */ -void plane_to_point_normal_v3(const float plane[4], float r_plane_co[3], float r_plane_no[3]) +void plane_to_point_vector_v3(const float plane[4], float r_plane_co[3], float r_plane_no[3]) { - const float length = normalize_v3_v3(r_plane_no, plane); - madd_v3_v3v3fl(r_plane_co, r_plane_no, r_plane_no, (-plane[3] / length) - 1.0f); + mul_v3_v3fl(r_plane_co, plane, (-plane[3] / len_squared_v3(plane))); + copy_v3_v3(r_plane_no, plane); } +/** + * version of #plane_to_point_vector_v3 that gets a unit length vector. + */ +void plane_to_point_vector_v3_normalized(const float plane[4], float r_plane_co[3], float r_plane_no[3]) +{ + const float length = normalize_v3_v3(r_plane_no, plane); + mul_v3_v3fl(r_plane_co, r_plane_no, (-plane[3] / length)); +} /********************************* Volume **********************************/ |