How to use the @jscad/modeling.transforms 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
/* title      : Chain Hull
// author     : Rene K. Mueller, Moissette Mark
// license    : MIT License
// date       : 2013/04/18
// description: Whosa whatsis suggested "Chain Hull" as described at
//    https://plus.google.com/u/0/105535247347788377245/posts/aZGXKFX1ACN
*/

const { sin, cos } = Math
const { circle } = require('@jscad/modeling').primitives
const { translate, scale } = require('@jscad/modeling').transforms
const { union } = require('@jscad/modeling').booleans
const { hullChain } = require('@jscad/modeling').hulls
const { extrudeLinear } = require('@jscad/modeling').extrusions

const main = () => {
  const shell = []
  const hexagon = []

  for (let i = 0; i < 12; i++) { // -- shell like
    const x = sin(i / 12 * 180) * 10
    const y = cos(i / 12 * 180) * 10
    shell.push(
      translate([x, y, 0], scale(6 - i / 2, circle())) // { center: true }
    )
  }
github jscad / OpenJSCAD.org / packages / examples / core / extrusions / extrudeRotate.js View on Github external
/* title      : Rotate Extrude
// author     : Rene K. Mueller
// license    : MIT License
// description: testing extrudeRotate() function
// tags: extrusion, rotate, extrudeRotate
*/

const { rectangle, circle, polygon } = require('@jscad/modeling').primitives
const { translate } = require('@jscad/modeling').transforms
const { extrudeRotate } = require('@jscad/modeling').extrusions

const main = () => {
  return [
    extrudeRotate(translate([4, 0, 0], circle({ r: 1, segments: 30, center: true }))),
    extrudeRotate({ segments: 5 },
      translate([4, 0, 0], circle({ r: 1, segments: 30, center: true }))).translate([0, 10, 0]),
    extrudeRotate({ segments: 30 },
      translate([4, 0, 0], circle({ r: 1, segments: 5, center: true }))).translate([0, 20, 0]),

    extrudeRotate({ segments: 4 }, translate([4, 0, 0], rectangle({ size: [1, 1], center: true })))
      .translate([-10, 0, 0]),
    extrudeRotate({ segments: 4 }, rectangle({ size: [1, 3], center: true }).translate([4, 0, 0]))
      .translate([-20, 0, 0]),
    extrudeRotate({ segments: 3 }, rectangle({ size: [2, 0.5], center: true }).translate([4, 0, 0]))
      .translate([-20, 10, 0]),
github jscad / OpenJSCAD.org / packages / examples / parameters / stepper-motor.js View on Github external
/* title      : Stepper Motor
// author     : Derrick Oswald
// license    : MIT License
// description: a simple stepper motor design
// tags: extrusion, extrudeFromSlices, slices
*/

const { circle, cube, cylinder } = require('@jscad/modeling').primitives
const { color } = require('@jscad/modeling').color
const { translate, rotateX } = require('@jscad/modeling').transforms
const { extrudeFromSlices, slice } = require('@jscad/modeling').extrusions
const { mat4 } = require('@jscad/modeling').math
const { union, intersect } = require('@jscad/modeling').booleans
const { sqrt } = Math
const { degToRad } = require('@jscad/modeling').math

const getParameterDefinitions = () => {
  return ([
    { name: 'motorBody_len', type: 'float', initial: 47.5, step: 0.5, caption: 'Motor length' },
    { name: 'motorBody_width', type: 'float', initial: 42.0, step: 0.5, caption: 'Motor width' },
    { name: 'motorBody_chamfer', type: 'float', initial: 5.0, step: 0.1, caption: 'Motor chamfer' },

    { name: 'motorCap_len', type: 'float', initial: 8.0, step: 0.1, caption: 'Motor cap length' },
    { name: 'motorCap_thickness', type: 'float', initial: 1.0, step: 0.1, caption: 'Motor cap thickness' },
    { name: 'motorCap_chamfer', type: 'float', initial: 2.5, step: 0.1, caption: 'Motor cap chamfer' },
github jscad / OpenJSCAD.org / packages / examples / core / extrusions / extrudeLinear.js View on Github external
/* title      : Linear Extrude
// author     : Rene K. Mueller
// license    : MIT License
// description: testing extrudeLinear() function
// tags: extrusion, linear, extrudeLinear
*/

const { rectangle, circle, polygon } = require('@jscad/modeling').primitives
const { translate, scale } = require('@jscad/modeling').transforms
const { extrudeLinear } = require('@jscad/modeling').extrusions

const main = () => {
  return [
    scale(3, extrudeLinear({ height: 10 }, circle({ r: 1, fn: 5, center: true }))),
    scale(3, extrudeLinear({ height: 10, twist: 90 }, rectangle({ size: [1, 2], center: true }))
      .translate([0, 5, 0])),
    scale(3, extrudeLinear({ height: 10, twist: -500, slices: 50 }, translate([2, 0, 0], circle({ r: 1, fn: 8, center: true })))
      .translate([0, -6, 0])),
    scale(3, extrudeLinear({ height: 20, twist: -90, center: true }, polygon([[0, 0], [4, 1], [1, 1], [1, 4]]))
      .translate([0, -13, 0]))
  ]
}

module.exports = { main }
github jscad / OpenJSCAD.org / packages / examples / core / extrusions / extrudeFromSlices.js View on Github external
/* title      : extrudeFromSlices
// author     : Jeff Gay, Moissette Mark
// license    : MIT License
// description: testing extrudeRotate() function
// tags: extrusion, extrudeFromSlices, slices
*/

const { circle } = require('@jscad/modeling').primitives
const { geom2 } = require('@jscad/modeling').geometry
const { translate } = require('@jscad/modeling').transforms
const { extrudeFromSlices, slice } = require('@jscad/modeling').extrusions
const { mat4 } = require('@jscad/modeling').math

const main = () => {
  const base = circle({ radius: 4, segments: 4 })
  let geometry3 = extrudeFromSlices(
    {
      numberOfSlices: 5,
      callback: (progress, count, base) => {
        let newshape = circle({ radius: 5 + count, segments: 4 + count })
        let newslice = slice.fromSides(geom2.toSides(newshape))
        newslice = slice.transform(mat4.fromTranslation([0, 0, count * 10]), newslice)
        return newslice
      }
    }, base
  )
github jscad / OpenJSCAD.org / packages / examples / core / transforms / transformations.js View on Github external
/* title      : transformations
// author     : Mark Moissette
// license    : MIT License
// description: all the different transforms operations
// tags: transforms, translate, rotate, scale, transform matrix
*/

const { cube } = require('@jscad/modeling').primitives
const { translate, rotate, scale, transform } = require('@jscad/modeling').transforms
const { sin, cos } = Math

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 / core / extrusions / extrudeRectangular.js View on Github external
/* title      : Rectangular Extrude
// authors     : Rene K. Mueller
// license    : MIT License
// description: testing extrudeRectangular() function
// tags: extrusion, rectangular, extrudeRectangular
*/

const { rectangle, circle, polygon } = require('@jscad/modeling').primitives
const { translate } = require('@jscad/modeling').transforms
const { extrudeRectangular } = require('@jscad/modeling').extrusions

const main = () => {
  return [
    extrudeRectangular([[0, 0], [10, 0], [5, 10], [0, 10]], { corners: 'chamfer' }),
    translate([0, 15, 0],
      extrudeRectangular([[0, 0], [10, 0], [5, 10], [0, 10]], { segments: 8, corners: 'round' })
    )
  ]
}

module.exports = { main }
github jscad / OpenJSCAD.org / packages / examples / core / expansions / expand.js View on Github external
/* title      : Expand
// author     : OpenSCAD.org, adapted by Rene K. Mueller
// license    : MIT License
// description: expand() function
*/

const { geom2, geom3, line2, path2 } = require('@jscad/modeling').geometry
const { cuboid, cylinder } = require('@jscad/modeling').primitives
const { translate, scale } = require('@jscad/modeling').transforms
const { union, difference } = require('@jscad/modeling').booleans
const { expand } = require('@jscad/modeling').expansions
const { color } = require('@jscad/modeling').color

const main = () => {
  // you can expand 2d paths
  const points = [
    [10, 0],
    [9.510565162951535, 3.090169943749474],
    [8.090169943749475, 5.877852522924732],
    [5.877852522924732, 8.090169943749475],
    [3.0901699437494745, 9.510565162951535],
    [6.123233995736766e-16, 10]
  ]
  const path2Example = color('black',
    path2.fromPoints({ }, points) // it also works with ccw points ie points.reverse()
github jscad / OpenJSCAD.org / packages / examples / core / primitives / primitives.js View on Github external
/* title      : Primitives
// authors     : Rene K. Mueller, Moissette Mark
// license    : MIT License
// description: testing primitives function
// tags: primitives, cube, sphere, cylinder, torus
*/

const { cube, sphere, cylinder, torus } = require('@jscad/modeling').primitives
const { translate } = require('@jscad/modeling').transforms

const main = () => {
  const allPrimitives = [
    cube(),
    cube({ size: [1, 2, 3] }),
    cube({ round: true }),
    cube({ size: [1, 2, 3], round: true }),
    sphere(),
    sphere({ segments: 8 }),
    cylinder({ radius: 1, height: 10 }),
    cylinder({ radius: 1, height: 10, round: true }),
    cylinder({ r1: 3, r2: 0, height: 10 }),
    cylinder({ start: [0, 0, 0], end: [3, 3, 10], radius: 1 }),
    torus({ ri: 0.5, ro: 2 }),
    torus({ ri: 0.1, ro: 2 })
  ]