Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
265 changes: 141 additions & 124 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zoo"
version = "0.2.112"
version = "0.2.113"
edition = "2021"
build = "build.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -22,11 +22,11 @@ git_rev = "0.1.0"
heck = "0.5.0"
http = "1"
itertools = "0.12.1"
kcl-lib = { version = "=0.2.80", features = ["disable-println"] }
kcl-derive-docs = { version = "=0.1.80" }
kcl-test-server = "=0.1.80"
kcl-lib = { version = "=0.2.85", features = ["disable-println"] }
kcl-derive-docs = { version = "=0.1.85" }
kcl-test-server = "=0.1.85"
kittycad = { version = "0.3.34", features = ["clap", "tabled", "requests", "retry"] }
kittycad-modeling-cmds = { version = "=0.2.121", features = ["websocket", "convert_client_crate", "tabled"] }
kittycad-modeling-cmds = { version = "=0.2.126", features = ["websocket", "convert_client_crate", "tabled"] }
log = "0.4.27"
miette = { version = "7.5.0", features = ["fancy"] }
nu-ansi-term = "0.50.1"
Expand Down
17 changes: 9 additions & 8 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ async fn test_main(ctx: &mut MainContext) {
"--material-density-unit".to_string(),
"lb-ft3".to_string(),
],
want_out: r#"68.458"#.to_string(),
want_out: r#"1268.234"#.to_string(),
want_err: "".to_string(),
want_code: 0,
..Default::default()
Expand All @@ -489,7 +489,7 @@ async fn test_main(ctx: &mut MainContext) {
"--material-density-unit".to_string(),
"lb-ft3".to_string(),
],
want_out: r#"68.458"#.to_string(),
want_out: r#"74.053"#.to_string(),
want_err: "".to_string(),
want_code: 0,
..Default::default()
Expand All @@ -509,7 +509,7 @@ async fn test_main(ctx: &mut MainContext) {
"--material-density-unit".to_string(),
"lb-ft3".to_string(),
],
want_out: r#"68.458"#.to_string(),
want_out: r#"74.053"#.to_string(),
want_err: "".to_string(),
want_code: 0,
..Default::default()
Expand All @@ -528,7 +528,7 @@ async fn test_main(ctx: &mut MainContext) {
"--material-mass".to_string(),
"1.0".to_string(),
],
want_out: r#"0.0146"#.to_string(),
want_out: r#"0.0007"#.to_string(),
want_err: "".to_string(),
want_code: 0,
..Default::default()
Expand All @@ -543,7 +543,7 @@ async fn test_main(ctx: &mut MainContext) {
"--output-unit".to_string(),
"cm3".to_string(),
],
want_out: r#"4273.7"#.to_string(),
want_out: r#"79173.2958833619"#.to_string(),
want_err: "".to_string(),
want_code: 0,
..Default::default()
Expand All @@ -558,7 +558,7 @@ async fn test_main(ctx: &mut MainContext) {
"--output-unit".to_string(),
"cm2".to_string(),
],
want_out: r#"surface_area | 3155.89"#.to_string(),
want_out: r#"surface_area | 17351.484299764335"#.to_string(),
want_err: "".to_string(),
want_code: 0,
..Default::default()
Expand All @@ -573,7 +573,8 @@ async fn test_main(ctx: &mut MainContext) {
"--output-unit".to_string(),
"cm".to_string(),
],
want_out: r#"mass | (-0.000"#.to_string(),
want_out: r#"center_of_mass | (-0.015537803061306477, 7.619970321655273, -0.00008108330803224817)"#
.to_string(),
want_err: "".to_string(),
want_code: 0,
..Default::default()
Expand Down Expand Up @@ -632,7 +633,7 @@ async fn test_main(ctx: &mut MainContext) {
"fmt".to_string(),
"tests/gear.kcl".to_string(),
],
want_out: r#"startSketchOn(body, face = END)"#.to_string(),
want_out: r#"startSketchOn(XY)"#.to_string(),
want_err: "".to_string(),
want_code: 0,
..Default::default()
Expand Down
165 changes: 65 additions & 100 deletions tests/gear.kcl
Original file line number Diff line number Diff line change
Expand Up @@ -2,111 +2,76 @@
// 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, kclVersion = 1.0)
@settings(defaultLengthUnit = in)

// Define parameters
nTeeth = 21
module = 0.5
pitchDiameter = module * nTeeth
pressureAngle = 20
addendum = module
deddendum = 1.25 * module
baseDiameter = pitchDiameter * cos(pressureAngle)
tipDiameter = pitchDiameter + 2 * module
gearHeight = 3
// Define a function to create a spur gear
fn spurGear(nTeeth, module, pressureAngle, gearHeight) {
// Define gear parameters
pitchDiameter = module * nTeeth
addendum = module
deddendum = 1.25 * module
baseDiameter = pitchDiameter * cos(pressureAngle)
tipDiameter = pitchDiameter + 2 * module

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

// Calculate operating pressure angle
angles = map(
rs,
f = fn(@r) {
return units::toDegrees(acos(baseDiameter / 2 / r))
},
)
// Define the constants of the keyway and the bore hole
keywayWidth = 2
keywayDepth = keywayWidth / 2
holeDiam = 5
holeRadius = holeDiam / 2
startAngle = asin(keywayWidth / 2 / holeRadius)

// Calculate the involute function
invas = map(
angles,
f = fn(@a) {
return tan(a) - units::toRadians(a)
},
)
// Sketch the keyway and center hole
holeWithKeyway = startSketchOn(XY)
|> startProfile(at = [
holeRadius * cos(startAngle),
holeRadius * sin(startAngle)
])
|> xLine(length = keywayDepth)
|> yLine(length = -keywayWidth)
|> xLine(length = -keywayDepth)
|> arc(angleStart = -1 * startAngle + 360, angleEnd = 180, radius = holeRadius)
|> arc(angleStart = 180, angleEnd = startAngle, radius = holeRadius)
|> close()

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

ys = map(
[0..cmo],
f = fn(@i) {
return rs[i] * sin(invas[i]: number(rad))
},
)
// Using the gear parameters, sketch an involute tooth spanning from the base diameter to the tip diameter
gearSketch = startSketchOn(XY)
|> startProfile(at = polar(angle = 0, length = baseDiameter / 2))
|> involuteCircular(
startRadius = baseDiameter / 2,
endRadius = tipDiameter / 2,
angle = 0,
tag = $seg01,
)
|> line(endAbsolute = polar(angle = 160 / nTeeth, length = tipDiameter / 2))
|> involuteCircular(
startRadius = baseDiameter / 2,
endRadius = tipDiameter / 2,
angle = -atan(segEndY(seg01) / segEndX(seg01)) - (180 / nTeeth),
reverse = true,
)
// Position the end line of the sketch at the start of the next tooth
|> line(endAbsolute = polar(angle = 360 / nTeeth, length = baseDiameter / 2))
// Pattern the sketch about the center by the specified number of teeth, then close the sketch
|> patternCircular2d(
%,
instances = nTeeth,
center = [0, 0],
arcDegrees = 360,
rotateDuplicates = true,
)
|> close()
// Subtract the keyway sketch from the gear sketch
|> subtract2d(tool = holeWithKeyway)
// Extrude the gear to the specified height
|> extrude(length = gearHeight)

// 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, accum) {
j = 100 - i // iterate backwards
return line(accum, endAbsolute = [xs[j], ys[j]])
}

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

// Draw gear teeth
start = startSketchOn(XY)
|> startProfile(at = [xs[101], ys[101]])
teeth = reduce([0..100], initial = start, f = leftInvolute)
|> arc(angleStart = 0, angleEnd = toothAngle, radius = baseDiameter / 2)
|> reduce([1..101], initial = %, f = 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)
spurGear(
nTeeth = 21,
module = 1.5,
pressureAngle = 14,
gearHeight = 6,
)

// Sketch the keyway and center hole and extrude
keyWay = startSketchOn(body, face = END)
|> startProfile(at = [
holeRadius * cos(startAngle),
holeRadius * sin(startAngle)
])
|> xLine(length = keywayDepth)
|> yLine(length = -keywayWidth)
|> xLine(length = -keywayDepth)
|> arc(angleStart = -1 * units::toDegrees(startAngle) + 360, angleEnd = 180, radius = holeRadius)
|> arc(angleStart = 180, angleEnd = units::toDegrees(startAngle), radius = holeRadius)
|> close()
|> extrude(length = -gearHeight)
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.
Loading
Loading