Hull and enclosing shapes
Three measurements in planex.measurements find what encloses a part:
Measurement |
Gives |
|---|---|
|
The convex hull as a face, exact with arcs; a spline by its approximation |
|
The smallest circle around the part, with its |
|
The rectangle of least area around the part, at any angle, with its |
A measurement is a function of a part, and part.Measure(f) evaluates it (see Part analysis). The radius of the enclosing circle is the round stock that a turned part needs, part.Measure(px.measurements.EnclosingCircle())["radius"], and the length and width of the enclosing rectangle are the blank that a flat part is cut from. Unlike the bounding box, the rectangle may lie at any angle.
[1]:
import math
import planex as px
import planex.measurements as pm
An L-shaped bracket
The example is an L-shaped bracket with legs of 60 and 40, each 10 wide and with its outer corner rounded to a radius of 10, turned by 30° on the sheet (Figure 1a).
[3]:
outline = px.QuickSketch().Line(60).Turn(90).Line(10).Turn(90).Line(50).Turn(-90).Line(30).Turn(90).Line(10).Close()
bracket = outline.Face().Filleted((0, 0), 10).Rotated((0, 0), 30)
hull = bracket.Measure(pm.ConvexHull())
circle = bracket.Measure(pm.EnclosingCircle())
blank = bracket.Measure(pm.EnclosingRectangle())
The hull bridges the inside of the L with a straight line from the end of one leg to the end of the other and keeps the rounded corner (Figure 1b). Before the turn, it is the polygon through (0, 0), (60, 0), (60, 10), (10, 40) and (0, 40), of area 1650, less what the fillet takes off the corner:
[4]:
print("hull area", hull.mass, "exact", 1650 - (1 - math.pi / 4) * 10**2)
hull area 1628.5398163397447 exact 1628.539816339745
The smallest circle passes through the ends of the two legs, and the line between them is its diameter, \(\sqrt{60^2 + 40^2}\) (Figure 1c). The rectangle of least area lies along the legs, 60 by 40, at the bracket’s angle of 30° (Figure 1d):
[5]:
print("circle radius", circle["radius"], "exact", math.hypot(60, 40) / 2)
print("blank", round(blank["length"], 9), "by", round(blank["width"], 9), "at", round(blank["angle"], 9), "degrees")
circle radius 36.05551275463989 exact 36.05551275463989
blank 60.0 by 40.0 at 30.0 degrees
(a) The bracket, turned by 30°
(b) The convex hull
(c) The smallest circle
(d) The rectangle of least area
See Boxes, crossings and open ends for the bounding box along the axes.