Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
Signed-off-by: Jess Frazelle <github@jessfraz.com>
  • Loading branch information
jessfraz committed Feb 11, 2025
1 parent 2854088 commit d922c97
Show file tree
Hide file tree
Showing 18 changed files with 79,347 additions and 79,221 deletions.
12 changes: 6 additions & 6 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ access-control-allow-credentials: """#
"--material-density-unit".to_string(),
"lb-ft3".to_string(),
],
want_out: r#"0.004174"#.to_string(),
want_out: r#"68.458"#.to_string(),
want_err: "".to_string(),
want_code: 0,
..Default::default()
Expand All @@ -487,7 +487,7 @@ access-control-allow-credentials: """#
"--material-density-unit".to_string(),
"lb-ft3".to_string(),
],
want_out: r#"0.0015198"#.to_string(),
want_out: r#"68.4585"#.to_string(),
want_err: "".to_string(),
want_code: 0,
..Default::default()
Expand All @@ -507,7 +507,7 @@ access-control-allow-credentials: """#
"--material-density-unit".to_string(),
"lb-ft3".to_string(),
],
want_out: r#"0.0015198"#.to_string(),
want_out: r#"68.4585"#.to_string(),
want_err: "".to_string(),
want_code: 0,
..Default::default()
Expand All @@ -526,7 +526,7 @@ access-control-allow-credentials: """#
"--material-mass".to_string(),
"1.0".to_string(),
],
want_out: r#"239.56"#.to_string(),
want_out: r#"0.0146"#.to_string(),
want_err: "".to_string(),
want_code: 0,
..Default::default()
Expand All @@ -541,7 +541,7 @@ access-control-allow-credentials: """#
"--output-unit".to_string(),
"cm3".to_string(),
],
want_out: r#"0.26"#.to_string(),
want_out: r#"4273.72"#.to_string(),
want_err: "".to_string(),
want_code: 0,
..Default::default()
Expand All @@ -556,7 +556,7 @@ access-control-allow-credentials: """#
"--output-unit".to_string(),
"cm2".to_string(),
],
want_out: r#"surface_area | 4.88"#.to_string(),
want_out: r#"surface_area | 3155.89"#.to_string(),
want_err: "".to_string(),
want_code: 0,
..Default::default()
Expand Down
Binary file modified tests/gear.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
178 changes: 112 additions & 66 deletions tests/nested-settings/subdir/gear.kcl
Original file line number Diff line number Diff line change
@@ -1,66 +1,112 @@
const part001 = startSketchAt([0.0000000000, 5.0000000000])
|> line([0.4900857016, -0.0240763666], %)
|> line([0.6804562304, 0.9087880491], %)
|> line([0.5711661314, -0.1430696680], %)
|> line([0.1717090983, -1.1222443518], %)
|> line([0.4435665223, -0.2097913408], %)
|> line([0.9764377140, 0.5792113521], %)
|> line([0.4729383069, -0.3507549536], %)
|> line([-0.2708257990, -1.1025288142], %)
|> line([0.3295183609, -0.3635674851], %)
|> line([1.1237654070, 0.1614549773], %)
|> line([0.3027099123, -0.5050409772], %)
|> line([-0.6721299235, -0.9149632591], %)
|> line([0.1653040161, -0.4619937756], %)
|> line([1.1000100038, -0.2808814542], %)
|> line([0.0863966776, -0.5824390901], %)
|> line([-0.9711083600, -0.5881028420], %)
|> line([-0.0240763666, -0.4900857016], %)
|> line([0.9087880491, -0.6804562304], %)
|> line([-0.1430696680, -0.5711661314], %)
|> line([-1.1222443518, -0.1717090983], %)
|> line([-0.2097913408, -0.4435665223], %)
|> line([0.5792113521, -0.9764377140], %)
|> line([-0.3507549536, -0.4729383069], %)
|> line([-1.1025288142, 0.2708257990], %)
|> line([-0.3635674851, -0.3295183609], %)
|> line([0.1614549773, -1.1237654070], %)
|> line([-0.5050409772, -0.3027099123], %)
|> line([-0.9149632591, 0.6721299235], %)
|> line([-0.4619937756, -0.1653040161], %)
|> line([-0.2808814542, -1.1000100038], %)
|> line([-0.5824390901, -0.0863966776], %)
|> line([-0.5881028420, 0.9711083600], %)
|> line([-0.4900857016, 0.0240763666], %)
|> line([-0.6804562304, -0.9087880491], %)
|> line([-0.5711661314, 0.1430696680], %)
|> line([-0.1717090983, 1.1222443518], %)
|> line([-0.4435665223, 0.2097913408], %)
|> line([-0.9764377140, -0.5792113521], %)
|> line([-0.4729383069, 0.3507549536], %)
|> line([0.2708257990, 1.1025288142], %)
|> line([-0.3295183609, 0.3635674851], %)
|> line([-1.1237654070, -0.1614549773], %)
|> line([-0.3027099123, 0.5050409772], %)
|> line([0.6721299235, 0.9149632591], %)
|> line([-0.1653040161, 0.4619937756], %)
|> line([-1.1000100038, 0.2808814542], %)
|> line([-0.0863966776, 0.5824390901], %)
|> line([0.9711083600, 0.5881028420], %)
|> line([0.0240763666, 0.4900857016], %)
|> line([-0.9087880491, 0.6804562304], %)
|> line([0.1430696680, 0.5711661314], %)
|> line([1.1222443518, 0.1717090983], %)
|> line([0.2097913408, 0.4435665223], %)
|> line([-0.5792113521, 0.9764377140], %)
|> line([0.3507549536, 0.4729383069], %)
|> line([1.1025288142, -0.2708257990], %)
|> line([0.3635674851, 0.3295183609], %)
|> line([-0.1614549773, 1.1237654070], %)
|> line([0.5050409772, 0.3027099123], %)
|> line([0.9149632591, -0.6721299235], %)
|> line([0.4619937756, 0.1653040161], %)
|> line([0.2808814542, 1.1000100038], %)
|> line([0.5824390901, 0.0863966776], %)
|> close(%)
|> extrude(1, %)
// Spur Gear
// 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.

// Set Units
@settings(defaultLengthUnit = in)

// Define constants
nTeeth = 21
module = 0.5
pitchDiameter = module * nTeeth
pressureAngle = 20
addendum = module
deddendum = 1.25 * module
baseDiameter = pitchDiameter * cos(toRadians(pressureAngle))
tipDiameter = pitchDiameter + 2 * module
gearHeight = 3

// Interpolate points along the involute curve
cmo = 101
rs = map([0..cmo], fn (i) {
return baseDiameter / 2 + i / cmo * (tipDiameter - baseDiameter) / 2
})

// Calculate operating pressure angle
angles = map(rs, fn (r) {
return toDegrees( acos(baseDiameter / 2 / r))
})

// Calculate the involute function
invas = map(angles, fn (a) {
return tan(toRadians(a)) - toRadians(a)
})

// Map the involute curve
xs = map([0..cmo], fn (i) {
return rs[i] * cos(invas[i])
})

ys = map([0..cmo], fn (i) {
return rs[i] * sin(invas[i])
})

// Extrude the gear body
body = startSketchOn('XY')
|> circle({
center = [0, 0],
radius = baseDiameter / 2
}, %)
|> extrude(length = gearHeight)

toothAngle = 360 / nTeeth / 1.5

// Plot the involute curve
fn leftInvolute(i, sg) {
j = 100 - i // iterate backwards
return line(sg, endAbsolute = [xs[j], ys[j]])
}

fn rightInvolute(i, sg) {
x = rs[i] * cos(toRadians(-toothAngle + toDegrees(atan(ys[i] / xs[i]))))
y = -rs[i] * sin(toRadians(-toothAngle + toDegrees(atan(ys[i] / xs[i]))))
return line(sg, endAbsolute = [x, y])
}

// Draw gear teeth
start = startSketchOn('XY')
|> startProfileAt([xs[101], ys[101]], %)
teeth = reduce([0..100], start, leftInvolute)
|> arc({
angleStart = 0,
angleEnd = toothAngle,
radius = baseDiameter / 2
}, %)
|> reduce([1..101], %, rightInvolute)
|> close()
|> extrude(length = gearHeight)
|> patternCircular3d({
axis = [0, 0, 1],
center = [0, 0, 0],
instances = nTeeth,
arcDegrees = 360,
rotateDuplicates = true
}, %)

// Define the constants of the keyway and the bore hole
keywayWidth = 0.250
keywayDepth = keywayWidth / 2
holeDiam = 2
holeRadius = 1
startAngle = asin(keywayWidth / 2 / holeRadius)

// Sketch the keyway and center hole and extrude
keyWay = startSketchOn(body, 'END')
|> startProfileAt([
holeRadius * cos(startAngle),
holeRadius * sin(startAngle)
], %)
|> xLine(keywayDepth, %)
|> yLine(-keywayWidth, %)
|> xLine(-keywayDepth, %)
|> arc({
angleEnd = 180,
angleStart = -1 * 180 / pi() * startAngle + 360,
radius = holeRadius
}, %)
|> arc({
angleEnd = 180 / pi() * startAngle,
angleStart = 180,
radius = holeRadius
}, %)
|> close()
|> extrude(length = -gearHeight)
Binary file modified tests/nested-settings/subdir/gear.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit d922c97

Please sign in to comment.