Skip to content

Commit 7ab4594

Browse files
committed
Update test file
1 parent 29b5693 commit 7ab4594

File tree

6 files changed

+24689
-152262
lines changed

6 files changed

+24689
-152262
lines changed

src/tests.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ async fn test_main(ctx: &mut MainContext) {
469469
"--material-density-unit".to_string(),
470470
"lb-ft3".to_string(),
471471
],
472-
want_out: r#"68.458"#.to_string(),
472+
want_out: r#"1268.234"#.to_string(),
473473
want_err: "".to_string(),
474474
want_code: 0,
475475
..Default::default()
@@ -489,7 +489,7 @@ async fn test_main(ctx: &mut MainContext) {
489489
"--material-density-unit".to_string(),
490490
"lb-ft3".to_string(),
491491
],
492-
want_out: r#"68.458"#.to_string(),
492+
want_out: r#"74.053"#.to_string(),
493493
want_err: "".to_string(),
494494
want_code: 0,
495495
..Default::default()
@@ -509,7 +509,7 @@ async fn test_main(ctx: &mut MainContext) {
509509
"--material-density-unit".to_string(),
510510
"lb-ft3".to_string(),
511511
],
512-
want_out: r#"68.458"#.to_string(),
512+
want_out: r#"74.053"#.to_string(),
513513
want_err: "".to_string(),
514514
want_code: 0,
515515
..Default::default()
@@ -528,7 +528,7 @@ async fn test_main(ctx: &mut MainContext) {
528528
"--material-mass".to_string(),
529529
"1.0".to_string(),
530530
],
531-
want_out: r#"0.0146"#.to_string(),
531+
want_out: r#"0.0007"#.to_string(),
532532
want_err: "".to_string(),
533533
want_code: 0,
534534
..Default::default()
@@ -543,7 +543,7 @@ async fn test_main(ctx: &mut MainContext) {
543543
"--output-unit".to_string(),
544544
"cm3".to_string(),
545545
],
546-
want_out: r#"4273.7"#.to_string(),
546+
want_out: r#"79173.2958833619"#.to_string(),
547547
want_err: "".to_string(),
548548
want_code: 0,
549549
..Default::default()
@@ -558,7 +558,7 @@ async fn test_main(ctx: &mut MainContext) {
558558
"--output-unit".to_string(),
559559
"cm2".to_string(),
560560
],
561-
want_out: r#"surface_area | 3155.89"#.to_string(),
561+
want_out: r#"surface_area | 17351.484299764335"#.to_string(),
562562
want_err: "".to_string(),
563563
want_code: 0,
564564
..Default::default()
@@ -573,7 +573,8 @@ async fn test_main(ctx: &mut MainContext) {
573573
"--output-unit".to_string(),
574574
"cm".to_string(),
575575
],
576-
want_out: r#"mass | (-0.000"#.to_string(),
576+
want_out: r#"center_of_mass | (-0.015537803061306477, 7.619970321655273, -0.00008108330803224817)"#
577+
.to_string(),
577578
want_err: "".to_string(),
578579
want_code: 0,
579580
..Default::default()

tests/gear.kcl

Lines changed: 65 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -2,111 +2,76 @@
22
// A rotating machine part having cut teeth or, in the case of a cogwheel, inserted teeth (called cogs), which mesh with another toothed part to transmit torque. Geared devices can change the speed, torque, and direction of a power source. The two elements that define a gear are its circular shape and the teeth that are integrated into its outer edge, which are designed to fit into the teeth of another gear.
33

44
// Set units
5-
@settings(defaultLengthUnit = in, kclVersion = 1.0)
5+
@settings(defaultLengthUnit = in)
66

7-
// Define parameters
8-
nTeeth = 21
9-
module = 0.5
10-
pitchDiameter = module * nTeeth
11-
pressureAngle = 20
12-
addendum = module
13-
deddendum = 1.25 * module
14-
baseDiameter = pitchDiameter * cos(pressureAngle)
15-
tipDiameter = pitchDiameter + 2 * module
16-
gearHeight = 3
7+
// Define a function to create a spur gear
8+
fn spurGear(nTeeth, module, pressureAngle, gearHeight) {
9+
// Define gear parameters
10+
pitchDiameter = module * nTeeth
11+
addendum = module
12+
deddendum = 1.25 * module
13+
baseDiameter = pitchDiameter * cos(pressureAngle)
14+
tipDiameter = pitchDiameter + 2 * module
1715

18-
// Interpolate points along the involute curve
19-
cmo = 101
20-
rs = map(
21-
[0..cmo],
22-
f = fn(@i) {
23-
return baseDiameter / 2 + i / cmo * (tipDiameter - baseDiameter) / 2
24-
},
25-
)
26-
27-
// Calculate operating pressure angle
28-
angles = map(
29-
rs,
30-
f = fn(@r) {
31-
return units::toDegrees(acos(baseDiameter / 2 / r))
32-
},
33-
)
16+
// Define the constants of the keyway and the bore hole
17+
keywayWidth = 2
18+
keywayDepth = keywayWidth / 2
19+
holeDiam = 5
20+
holeRadius = holeDiam / 2
21+
startAngle = asin(keywayWidth / 2 / holeRadius)
3422

35-
// Calculate the involute function
36-
invas = map(
37-
angles,
38-
f = fn(@a) {
39-
return tan(a) - units::toRadians(a)
40-
},
41-
)
23+
// Sketch the keyway and center hole
24+
holeWithKeyway = startSketchOn(XY)
25+
|> startProfile(at = [
26+
holeRadius * cos(startAngle),
27+
holeRadius * sin(startAngle)
28+
])
29+
|> xLine(length = keywayDepth)
30+
|> yLine(length = -keywayWidth)
31+
|> xLine(length = -keywayDepth)
32+
|> arc(angleStart = -1 * startAngle + 360, angleEnd = 180, radius = holeRadius)
33+
|> arc(angleStart = 180, angleEnd = startAngle, radius = holeRadius)
34+
|> close()
4235

43-
// Map the involute curve
44-
xs = map(
45-
[0..cmo],
46-
f = fn(@i) {
47-
return rs[i] * cos(invas[i]: number(rad))
48-
},
49-
)
50-
51-
ys = map(
52-
[0..cmo],
53-
f = fn(@i) {
54-
return rs[i] * sin(invas[i]: number(rad))
55-
},
56-
)
36+
// Using the gear parameters, sketch an involute tooth spanning from the base diameter to the tip diameter
37+
gearSketch = startSketchOn(XY)
38+
|> startProfile(at = polar(angle = 0, length = baseDiameter / 2))
39+
|> involuteCircular(
40+
startRadius = baseDiameter / 2,
41+
endRadius = tipDiameter / 2,
42+
angle = 0,
43+
tag = $seg01,
44+
)
45+
|> line(endAbsolute = polar(angle = 160 / nTeeth, length = tipDiameter / 2))
46+
|> involuteCircular(
47+
startRadius = baseDiameter / 2,
48+
endRadius = tipDiameter / 2,
49+
angle = -atan(segEndY(seg01) / segEndX(seg01)) - (180 / nTeeth),
50+
reverse = true,
51+
)
52+
// Position the end line of the sketch at the start of the next tooth
53+
|> line(endAbsolute = polar(angle = 360 / nTeeth, length = baseDiameter / 2))
54+
// Pattern the sketch about the center by the specified number of teeth, then close the sketch
55+
|> patternCircular2d(
56+
%,
57+
instances = nTeeth,
58+
center = [0, 0],
59+
arcDegrees = 360,
60+
rotateDuplicates = true,
61+
)
62+
|> close()
63+
// Subtract the keyway sketch from the gear sketch
64+
|> subtract2d(tool = holeWithKeyway)
65+
// Extrude the gear to the specified height
66+
|> extrude(length = gearHeight)
5767

58-
// Extrude the gear body
59-
body = startSketchOn(XY)
60-
|> circle(center = [0, 0], radius = baseDiameter / 2)
61-
|> extrude(length = gearHeight)
62-
63-
toothAngle = 360 / nTeeth / 1.5
64-
65-
// Plot the involute curve
66-
fn leftInvolute(@i, accum) {
67-
j = 100 - i // iterate backwards
68-
return line(accum, endAbsolute = [xs[j], ys[j]])
69-
}
70-
71-
fn rightInvolute(@i, accum) {
72-
x = rs[i] * cos(-toothAngle + units::toDegrees(atan(ys[i] / xs[i])))
73-
y = -rs[i] * sin(-toothAngle + units::toDegrees(atan(ys[i] / xs[i])))
74-
return line(accum, endAbsolute = [x, y])
68+
return gearSketch
7569
}
7670

77-
// Draw gear teeth
78-
start = startSketchOn(XY)
79-
|> startProfile(at = [xs[101], ys[101]])
80-
teeth = reduce([0..100], initial = start, f = leftInvolute)
81-
|> arc(angleStart = 0, angleEnd = toothAngle, radius = baseDiameter / 2)
82-
|> reduce([1..101], initial = %, f = rightInvolute)
83-
|> close()
84-
|> extrude(length = gearHeight)
85-
|> patternCircular3d(
86-
axis = [0, 0, 1],
87-
center = [0, 0, 0],
88-
instances = nTeeth,
89-
arcDegrees = 360,
90-
rotateDuplicates = true,
91-
)
92-
93-
// Define the constants of the keyway and the bore hole
94-
keywayWidth = 0.250
95-
keywayDepth = keywayWidth / 2
96-
holeDiam = 2
97-
holeRadius = 1
98-
startAngle = asin(keywayWidth / 2 / holeRadius)
71+
spurGear(
72+
nTeeth = 21,
73+
module = 1.5,
74+
pressureAngle = 14,
75+
gearHeight = 6,
76+
)
9977

100-
// Sketch the keyway and center hole and extrude
101-
keyWay = startSketchOn(body, face = END)
102-
|> startProfile(at = [
103-
holeRadius * cos(startAngle),
104-
holeRadius * sin(startAngle)
105-
])
106-
|> xLine(length = keywayDepth)
107-
|> yLine(length = -keywayWidth)
108-
|> xLine(length = -keywayDepth)
109-
|> arc(angleStart = -1 * units::toDegrees(startAngle) + 360, angleEnd = 180, radius = holeRadius)
110-
|> arc(angleStart = 180, angleEnd = units::toDegrees(startAngle), radius = holeRadius)
111-
|> close()
112-
|> extrude(length = -gearHeight)

tests/gear.png

-13.9 KB
Loading

0 commit comments

Comments
 (0)