// Tire
// A tire is a critical component of a vehicle that provides the necessary traction and grip between the car and the road. It supports the vehicle's weight and absorbs shocks from road irregularities.

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

// Import parameters
import tireInnerDiameter, tireOuterDiameter, tireDepth, bendRadius, tireTreadWidth, tireTreadDepth, tireTreadOffset from "parameters.kcl"

// Create the sketch of the tire
tireSketch = startSketchOn(XY)
  |> startProfile(at = [tireInnerDiameter / 2, tireDepth / 2])
  |> line(
       endAbsolute = [
         tireOuterDiameter / 2 - bendRadius,
         tireDepth / 2
       ],
       tag = $edge1,
     )
  |> tangentialArc(angle = -90, radius = bendRadius)
  |> line(endAbsolute = [
       tireOuterDiameter / 2,
       tireDepth / 2 - tireTreadOffset
     ])
  |> line(end = [-tireTreadDepth, 0])
  |> line(end = [0, -tireTreadWidth])
  |> line(end = [tireTreadDepth, 0])
  |> line(endAbsolute = [
       tireOuterDiameter / 2,
       -tireDepth / 2 + tireTreadOffset + tireTreadWidth
     ])
  |> line(end = [-tireTreadDepth, 0])
  |> line(end = [0, -tireTreadWidth])
  |> line(end = [tireTreadDepth, 0])
  |> line(endAbsolute = [
       tireOuterDiameter / 2,
       -tireDepth / 2 + bendRadius
     ])
  |> tangentialArc(angle = -90, radius = bendRadius)
  |> line(endAbsolute = [tireInnerDiameter / 2, -tireDepth / 2], tag = $edge2)
  |> close()

// Revolve the sketch to create the tire
carTire = revolve(tireSketch, axis = Y)
  |> appearance(color = "#0f0f0f", roughness = 80)
