Preparing for the removal of positional functions from the language. The first big step is to change all our KCL code examples, test code, public samples etc to all use keyword functions. Apologies for how large this PR is. Most of it is: - Changing example KCL that defined its own functions, so the functions now use keyword arguments rather than positional arguments. E.g. change `cube([20, 20])` to be `cube(center = [20, 20])`. - Some parts of the code assumed positional code and didn't handle keyword calls, e.g. the linter would only check for positional calls to startSketchOn. Now they should work with either positional or keyword. - Update all the artifacts This does _not_ remove support for positional calls. That will be in a follow-up PR.
29 lines
1.1 KiB
Plaintext
29 lines
1.1 KiB
Plaintext
@settings(defaultLengthUnit = nm)
|
|
|
|
// Generated by Text-to-CAD: draw a water molecule
|
|
|
|
// Constants for the water molecule
|
|
oxygenRadius = 0.066 // Approximate radius of an oxygen atom
|
|
hydrogenRadius = 0.053 // Approximate radius of a hydrogen atom
|
|
oxygenHydrogenDistance = 0.096 // Approximate distance between oxygen and hydrogen atoms
|
|
bondAngle = 104.5 // Bond angle in degrees
|
|
|
|
|
|
// Function to create a sphere representing an atom
|
|
fn createAtom(center, radius) {
|
|
return startSketchOn(XY)
|
|
|> circle(center = center, radius = radius)
|
|
|> extrude(length = radius * 2)
|
|
}
|
|
|
|
// Create the oxygen atom at the origin
|
|
oxygenAtom = createAtom(center = [0, 0], radius = oxygenRadius)
|
|
|
|
// Calculate the positions of the hydrogen atoms
|
|
hydrogenOffsetX = oxygenHydrogenDistance * cos(toRadians(bondAngle / 2))
|
|
hydrogenOffsetY = oxygenHydrogenDistance * sin(toRadians(bondAngle / 2))
|
|
|
|
// Create the hydrogen atoms
|
|
hydrogenAtom1 = createAtom(center = [hydrogenOffsetX, hydrogenOffsetY], radius = hydrogenRadius)
|
|
hydrogenAtom2 = createAtom(center = [-hydrogenOffsetX, hydrogenOffsetY], radius = hydrogenRadius)
|