How to use the @jscad/modeling.translate function in @jscad/modeling

To help you get started, we’ve selected a few @jscad/modeling examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jscad / OpenJSCAD.org / packages / examples / core / hulls / hullChain.js View on Github external
shell.push(
      translate([x, y, 0], scale(6 - i / 2, circle())) // { center: true }
    )
  }

  const n = 6
  for (let i = 0; i < n; i++) { // -- hexagon chain hulled
    const x = sin(i / n * 360) * 10
    const y = cos(i / n * 360) * 10
    hexagon.push(
      translate([x, y, 0], circle())// { center: true }
    )
  }

  return [
    translate([-20, 0, 0],
      extrudeLinear({ height: 5 }, hullChain(shell))
    ),
    hullChain(shell),
    translate([20, 0, 0],
      union(shell)
    ),

    translate([-25, 40, 0],
      extrudeLinear({ height: 5 }, hullChain({ closed: true }, hexagon))
    ),
    translate([0, 40, 0],
      hullChain({ closed: true }, hexagon)
    ),
    translate([25, 40, 0],
      union(hexagon)
    )
github jscad / OpenJSCAD.org / packages / examples / core / transforms / transformations.js View on Github external
const main = () => {
  const testCube = cube()

  return [
    translate([0, 10, 0], testCube), // simple translation
    translate([10, 0, 0], rotate([10, 5, 0], testCube)), // translate + rotate
    translate([-10, 0, 0], scale([0.5, 0.5, 5], testCube)), // translate + scale
    transform([ // matrix transform
      cos(15), -sin(15), 0, 0,
      sin(15), cos(15), 0, 0,
      0, 0, 1, 1,
      0, 0, 0, 1
    ], testCube)
  ]
}
github jscad / OpenJSCAD.org / packages / examples / parameters / stepper-motor.js View on Github external
resolution: 50
    })
  )

  const mountinghole = color([0.2, 0.2, 0.2],
    cylinder({
      start: [-depth, 0, 0],
      end: [0, 0, 0],
      radius: parameters.mountingholes_radius,
      resolution: 20
    })
  )

  let motor = union([cube, cube2, cube3, ring, shaft])
  motor = motor.subtract(
    translate([length, offset, offset], mountinghole),
    translate([length, offset, -offset], mountinghole),
    translate([length, -offset, offset], mountinghole),
    translate([length, -offset, -offset], mountinghole)
  )

  return translate([0, 0, width], motor)
}
github jscad / OpenJSCAD.org / packages / examples / core / hulls / hullChain.js View on Github external
)
  }

  return [
    translate([-20, 0, 0],
      extrudeLinear({ height: 5 }, hullChain(shell))
    ),
    hullChain(shell),
    translate([20, 0, 0],
      union(shell)
    ),

    translate([-25, 40, 0],
      extrudeLinear({ height: 5 }, hullChain({ closed: true }, hexagon))
    ),
    translate([0, 40, 0],
      hullChain({ closed: true }, hexagon)
    ),
    translate([25, 40, 0],
      union(hexagon)
    )
  ]
}
github jscad / OpenJSCAD.org / packages / examples / parameters / stepper-motor.js View on Github external
const mountinghole = color([0.2, 0.2, 0.2],
    cylinder({
      start: [-depth, 0, 0],
      end: [0, 0, 0],
      radius: parameters.mountingholes_radius,
      resolution: 20
    })
  )

  let motor = union([cube, cube2, cube3, ring, shaft])
  motor = motor.subtract(
    translate([length, offset, offset], mountinghole),
    translate([length, offset, -offset], mountinghole),
    translate([length, -offset, offset], mountinghole),
    translate([length, -offset, -offset], mountinghole)
  )

  return translate([0, 0, width], motor)
}
github jscad / OpenJSCAD.org / packages / examples / parameters / stepper-motor.js View on Github external
start: [-depth, 0, 0],
      end: [0, 0, 0],
      radius: parameters.mountingholes_radius,
      resolution: 20
    })
  )

  let motor = union([cube, cube2, cube3, ring, shaft])
  motor = motor.subtract(
    translate([length, offset, offset], mountinghole),
    translate([length, offset, -offset], mountinghole),
    translate([length, -offset, offset], mountinghole),
    translate([length, -offset, -offset], mountinghole)
  )

  return translate([0, 0, width], motor)
}
github jscad / OpenJSCAD.org / packages / examples / core / primitives / primitives.js View on Github external
return allPrimitives.map((primitive, index) => {
    translate([(index % 4 - 2) * 6, Math.floor(index / 4 - 2) * 6, 0], primitive)
  })
}