diff options
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_math_geom.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_geom.c | 19 |
2 files changed, 20 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h index 7cb91a45118..448396811d3 100644 --- a/source/blender/blenlib/BLI_math_geom.h +++ b/source/blender/blenlib/BLI_math_geom.h @@ -53,6 +53,7 @@ float area_tri_signed_v2(const float v1[2], const float v2[2], const float v3[2] float area_tri_v3(const float a[3], const float b[3], const float c[3]); float area_quad_v3(const float a[3], const float b[3], const float c[3], const float d[3]); float area_poly_v3(int nr, float verts[][3], const float normal[3]); +float area_poly_v2(int nr, float verts[][2]); int is_quad_convex_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3]); int is_quad_convex_v2(const float v1[2], const float v2[2], const float v3[2], const float v4[2]); diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index 5f1047d054e..fc1d0e99a30 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -149,6 +149,25 @@ float area_poly_v3(int nr, float verts[][3], const float normal[3]) return fabsf(0.5f * area / max); } +float area_poly_v2(int nr, float verts[][2]) +{ + int a; + float area; + float *co_curr, *co_prev; + + /* The Trapezium Area Rule */ + co_prev = verts[nr - 1]; + co_curr = verts[0]; + area = 0.0f; + for (a = 0; a < nr; a++) { + area += (co_curr[0] - co_prev[0]) * (co_curr[1] + co_prev[1]); + co_prev = verts[a]; + co_curr = verts[a + 1]; + } + + return fabsf(0.5f * area); +} + /********************************* Distance **********************************/ /* distance p to line v1-v2 |