OpenJSCAD.org
OpenJSCAD.org copied to clipboard
Offset inner corner behavior
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'
:
corners: 'round'
OR corners: 'chamfer'
:
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.