// Lug Nut
// lug Nuts are essential components used to create secure connections, whether for electrical purposes, like terminating wires or grounding, or for mechanical purposes, such as providing mounting points or reinforcing structural joints.

// Set units
@settings(defaultLengthUnit = in, kclVersion = 1.0)

// Import parameters
import lugDiameter, lugHeadLength, lugThreadDiameter, lugLength, lugThreadDepth, lugSpacing from "parameters.kcl"

customPlane = {
  origin = { x = lugSpacing / 2, y = -30mm, z = 0 },
  xAxis = { x = 1, y = 0, z = 0 },
  yAxis = { x = 0, y = -1, z = 0 },
  zAxis = { x = 0, y = 0, z = 1 }
}

fn lug(plane, length, diameter) {
  lugSketch = startSketchOn(customPlane)
    |> startProfile(at = [0 + diameter / 2, 0])
    |> angledLine(angle = 70, lengthY = lugHeadLength)
    |> xLine(endAbsolute = lugDiameter / 2)
    |> yLine(endAbsolute = lugLength)
    |> tangentialArc(angle = 90, radius = 3mm)
    |> xLine(endAbsolute = 0 + .001, tag = $c1)
    |> yLine(endAbsolute = lugThreadDepth)
    |> xLine(endAbsolute = lugThreadDiameter)
    |> yLine(endAbsolute = 0)
    |> close()
    |> revolve(axis = Y)
    |> appearance(color = "#dbcd70", roughness = 90, metalness = 90)
  return lugSketch
}

lugNut = lug(plane = customPlane, length = lugLength, diameter = lugDiameter)
