Skip to content

Commit 9f72d6c

Browse files
committed
wip
1 parent d5f7bc5 commit 9f72d6c

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

freecad/gridfinity_workbench/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
MAGNET_HOLE_DISTANCE_FROM_EDGE = 8
2020

21-
HOLE_SHAPES = ["Round", "Hex"]
21+
HOLE_SHAPES = ["Round", "Crush ribs", "Hex"]
2222

2323
## Bins
2424
# General Bin Parameters

freecad/gridfinity_workbench/magnet_hole.py

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,55 @@
1010
from . import utils
1111

1212

13+
def _crush_ribs(
14+
radius: fc.Units.Quantity,
15+
depth: fc.Units.Quantity,
16+
*,
17+
n: int,
18+
beta: float,
19+
) -> Part.Shape:
20+
"""Make crush ribs inner shape.
21+
22+
Args:
23+
radius (fc.Units.Quantity): Inner radius.
24+
depth (fc.Units.Quantity): Depth.
25+
n (int): Number of ribs.
26+
beta (float): Waviness of the ribs. It is the angle at wich inner at outer arcs meet.
27+
A value of 0 would result in a perfect circle.
28+
29+
"""
30+
alpha = math.pi / n / 2
31+
32+
def get_midpoint(beta: float) -> float:
33+
return (math.sin(beta) - math.sin(alpha)) / math.sin(beta - alpha)
34+
35+
r1 = radius.Value
36+
r2 = radius.Value / get_midpoint(beta)
37+
r3 = r2 * get_midpoint(-beta)
38+
39+
p1 = fc.Vector(r2, 0)
40+
p2 = fc.Vector(r2 * math.cos(2 * alpha), r2 * math.sin(2 * alpha))
41+
q = r1 * fc.Vector(math.cos(alpha), math.sin(alpha))
42+
r = r3 * fc.Vector(math.cos(alpha), math.sin(alpha))
43+
44+
lines = []
45+
for _ in range(n):
46+
lines.append(Part.Arc(p1, q, p2))
47+
lines.append(Part.Arc(p1, r, p2))
48+
for i, arc in enumerate(lines):
49+
placement = fc.Placement(
50+
fc.Vector(0, 0, 0),
51+
fc.Vector(0, 0, 1),
52+
math.degrees((i + 0.5) / len(lines) * 2 * math.pi),
53+
)
54+
arc.rotate(placement)
55+
wire = utils.curve_to_wire(lines)
56+
face = Part.Face(wire)
57+
shape = face.extrude(fc.Vector(0, 0, depth))
58+
59+
return shape
60+
61+
1362
def _hex_shape(radius: fc.Units.Quantity, depth: fc.Units.Quantity) -> Part.Shape:
1463
# Ratio of 2/sqrt(3) converts from inscribed circle radius to circumscribed
1564
# circle radius
@@ -37,6 +86,8 @@ def from_obj(obj: fc.DocumentObject) -> Part.Shape:
3786

3887
if hole_shape == "Hex":
3988
shape = _hex_shape(radius, depth)
89+
elif hole_shape == "Crush ribs":
90+
shape = _crush_ribs(radius, depth, n=8, beta=0.5 * math.pi / 2)
4091
elif hole_shape == "Round":
4192
shape = Part.makeCylinder(radius, depth)
4293
if obj.Baseplate:
@@ -48,7 +99,6 @@ def from_obj(obj: fc.DocumentObject) -> Part.Shape:
4899
pPnt=fc.Vector(0, 0, depth - chamfer),
49100
)
50101
shape = shape.fuse(chamfer_shape)
51-
return shape
52102
else:
53103
raise ValueError(f"Unrecognised magnet hole shape {hole_shape:!r}")
54104

@@ -59,10 +109,11 @@ def relief(obj: fc.DocumentObject) -> Part.Shape:
59109
"""Create a magnet relief shape for four magnets from object properties."""
60110
x_hole_pos = obj.xGridSize / 2 - obj.MagnetHoleDistanceFromEdge
61111
y_hole_pos = obj.yGridSize / 2 - obj.MagnetHoleDistanceFromEdge
112+
alpha = math.pi / 8
62113

63114
r = obj.MagnetHoleDiameter / 2
64-
x1 = r * math.cos(math.pi / 8)
65-
y1 = r * math.sin(math.pi / 8)
115+
x1 = r * math.cos(alpha)
116+
y1 = r * math.sin(alpha)
66117
p1 = fc.Vector(x1, y1)
67118
p2 = fc.Vector(x1 + 2 * y1, y1)
68119
p3 = fc.Vector(x1 + 3 * y1, 0)

0 commit comments

Comments
 (0)