OpenJSCAD.org icon indicating copy to clipboard operation
OpenJSCAD.org copied to clipboard

Offset inner corner behavior

Open Loosetooth opened this issue 1 year ago • 0 comments

I noticed some broken geometries being generated using the offset and expand functions. It seems to generate wrong results for the offsets of inner corners:

corners: 'edge': image

corners: 'round' OR corners: 'chamfer': image

Try out the code:

const jscad = require('@jscad/modeling')
const { union } = jscad.booleans
const { square, circle } = jscad.primitives
const { translate, rotateZ } = jscad.transforms
const { offset } = jscad.expansions
const { colorize } = jscad.colors

const sizeFactor = (width) => 0.5 * width / (0.5 + 1 / (2 * Math.SQRT2))

const heart2D = (width) => {
  const size = sizeFactor(width)
  return union(
    rotateZ(Math.PI / 4, square({ size })),
    translate([-size / (2 * Math.SQRT2), size / (2 * Math.SQRT2), 0], circle({ radius: size / 2 })),
    translate([size / (2 * Math.SQRT2), size / (2 * Math.SQRT2), 0], circle({ radius: size / 2 }))
  )
}

const main = () => {
  const heart = heart2D(10)
  return [
    colorize([0.7, 0, 0], heart),
    offset({ corners: 'edge', delta: 5 }, heart)
  ]
}

module.exports = { main }

P.S. This is in JSCAD V2.

Loosetooth avatar Mar 24 '23 08:03 Loosetooth