mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-29 08:19:43 +00:00
Added polygon_is_convex()
This commit is contained in:
parent
c1bc74b643
commit
90daf37a53
2 changed files with 20 additions and 1 deletions
|
@ -964,6 +964,25 @@ function polygon_area(vertices) =
|
|||
0.5*sum([for(i=[0:len(vertices)-1]) det2(select(vertices,i,i+1))]);
|
||||
|
||||
|
||||
// Function: polygon_is_convex()
|
||||
// Usage:
|
||||
// polygon_is_convex(poly);
|
||||
// Description:
|
||||
// Returns true if the given polygon is convex. Result is undefined if the polygon is self-intersecting.
|
||||
// Example:
|
||||
// polygon_is_convex(circle(d=50)); // Returns: true
|
||||
// Example:
|
||||
// spiral = [for (i=[0:36]) let(a=-i*10) (10+i)*[cos(a),sin(a)]];
|
||||
// polygon_is_convex(spiral); // Returns: false
|
||||
function polygon_is_convex(poly) =
|
||||
let(
|
||||
l = len(poly),
|
||||
c = [for (i=idx(poly)) cross(poly[(i+1)%l]-poly[i],poly[(i+2)%l]-poly[(i+1)%l])]
|
||||
)
|
||||
len([for (x=c) if(x>0) 1])==0 ||
|
||||
len([for (x=c) if(x<0) 1])==0;
|
||||
|
||||
|
||||
// Function: polygon_shift()
|
||||
// Usage:
|
||||
// polygon_shift(poly, i);
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
BOSL_VERSION = [2,0,107];
|
||||
BOSL_VERSION = [2,0,108];
|
||||
|
||||
|
||||
// Section: BOSL Library Version Functions
|
||||
|
|
Loading…
Reference in a new issue