---
source: kcl-lib/src/simulation_tests.rs
description: Result of unparsing bad_units_in_annotation.kcl
---
@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)
