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
This commit is contained in:
@@ -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]);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user