kcl-samplesmug

mug

mug

KCL

// Mug
// A cup with straight sides and a handle, typically used for hot drinks

// Set units
@settings(defaultLengthUnit = mm)

// Define parameters
mugDiameter = 80
mugHeight = 95
wallThickness = 6
handleWidth = 18
handleThickness = 5

// Revolve the outer perimeter of the mug body. This will be used to subtract material from the handle, so that it fits snug to the body
tools = startSketchOn(XZ)
  |> startProfile(at = [0, mugDiameter * 0.04])
  |> xLine(length = mugDiameter * 0.1)
  |> tangentialArc(endAbsolute = [mugDiameter * 0.3, mugDiameter * 0.01])
  |> arc(angleStart = -180, angleEnd = -90, radius = mugDiameter * 0.01)
  |> xLine(length = mugDiameter * 0.025)
  |> arc(angleStart = -90, angleEnd = 0, radius = mugDiameter * 0.01)
  |> xLine(endAbsolute = mugDiameter * 0.35)
  |> tangentialArc(angle = 90, radius = mugDiameter * 0.15)
  |> yLine(endAbsolute = mugHeight - (wallThickness / 2))
  |> tangentialArc(angle = 90, diameter = wallThickness)
  |> xLine(endAbsolute = profileStartX())
  |> yLine(endAbsolute = profileStartY())
  |> close()
  |> revolve(axis = Y)

// Draw the path of the mug handle
handlePath = startSketchOn(XZ)
  |> startProfile(at = [mugDiameter / 3, mugHeight * 0.25])
  |> angledLine(angle = -5, length = mugDiameter / 3)
  |> tangentialArc(angle = 90, radius = mugHeight * 0.15)
  |> tangentialArc(end = [0, mugHeight * 0.425])
  |> tangentialArc(angle = 90, radius = mugHeight * 0.15, tag = $seg02)
  |> angledLine(angle = tangentToEnd(seg02), endAbsoluteX = profileStartX())

// Sweep the handle profile along the path
handle = startSketchOn(offsetPlane(YZ, offset = mugDiameter / 3))
  |> startProfile(at = [
       -handleWidth / 2,
       mugHeight * 0.25 + handleThickness / 2
     ])
  |> arc(
       interiorAbsolute = [
         0,
         profileStartY() + handleThickness / 4
       ],
       endAbsolute = [handleWidth / 2, profileStartY()],
     )
  |> tangentialArc(end = [0, -handleThickness])
  |> tangentialArc(end = [-handleWidth, 0])
  |> tangentialArc(endAbsolute = profileStart())
  |> close()
  |> sweep(path = handlePath)
  |> subtract(tools)

// Create the body of the mug
mug = startSketchOn(XZ)
  |> startProfile(at = [0, mugDiameter * 0.04])
  |> xLine(length = mugDiameter * 0.1)
  |> tangentialArc(endAbsolute = [mugDiameter * 0.3, mugDiameter * 0.01])
  |> arc(angleStart = -180, angleEnd = -90, radius = mugDiameter * 0.01)
  |> xLine(length = mugDiameter * 0.025)
  |> arc(angleStart = -90, angleEnd = 0, radius = mugDiameter * 0.01)
  |> xLine(endAbsolute = mugDiameter * 0.35)
  |> tangentialArc(angle = 90, radius = mugDiameter * 0.15)
  |> yLine(endAbsolute = mugHeight - (wallThickness / 2))
  |> tangentialArc(angle = 180, diameter = wallThickness)
  |> yLine(endAbsolute = mugDiameter * 0.15)
  |> tangentialArc(angle = -90, radius = lastSegX() * 0.2)
  |> xLine(endAbsolute = profileStartX())
  |> yLine(endAbsolute = profileStartY())
  |> close()
  |> revolve(axis = Y)

// Join the mug and handle, then add an appearance
[handle, mug]
  |> appearance(color = "#9b1212", metalness = 40, roughness = 30)