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

booleans.intersect fails for an extrude with rotation

Open paulftw opened this issue 2 years ago • 5 comments

Basically if a twist angle is large enough it breaks booleans.intersect.

Screen Shot 2022-03-03 at 8 53 48 PM

Demo: https://scriptcad.com/paulftw/playground

import {
  booleans,
  extrusions,
  geometries,
  maths,
  primitives,
  transforms,
} from '@jscad/modeling'

export const main = () => {
  const base = booleans.subtract(
    primitives.circle(5),
    transforms.translate([1, 0], primitives.circle(5)),
  )

  const xtr05 = transforms.translate(
    [0, 0, 0.7],
    extrusions.extrudeLinear(
      {
        height: 2,
        twistAngle: 0.5,
      },
      base,
    ),
  )

  const xtr10 = transforms.translate(
    [0, 0, 0.7],
    extrusions.extrudeLinear(
      {
        height: 2,
        twistAngle: 1,
      },
      base,
    ),
  )

  return [
    // Good intersection, 0.5rad
    transforms.translate(
      [0, 0, 0],
      booleans.intersect(xtr05, primitives.cube()),
    ),

    // Bad intersection, 1.0rad
    transforms.translate(
      [5, 0, 0],
      booleans.intersect(xtr10, primitives.cube()),
    ),
  ]
}

paulftw avatar Mar 03 '22 18:03 paulftw

Yeah. Extrusions are tricky sometimes. Have you tried increasing twistSteps ?

z3dev avatar Mar 03 '22 21:03 z3dev

This seems to me like a problem with intersect, not with extrusion.

Upon visual inspection the extrusion looks alright - no holes, no CW polygons, not self intersecting, etc. So basically I'm calling intersect on two seemingly correct 3d geometries, but it returns a messed up result.

If you think the bug is in the extrusion, How do I find it? What should I be looking for?

paulftw avatar Mar 03 '22 21:03 paulftw

Initially, you said…

Basically if a twist angle is large enough it breaks booleans.intersect.

If there are more steps then the walls of the extrusion are smoother and more contiguous. And I suspect that the booleans perform better as well.

I’m not sure there is a bug… if an extrusion is twisted beyond useable geometry then some adjustments should be made. All software has limitations.

z3dev avatar Mar 04 '22 09:03 z3dev

@paulftw I tried the example with twistSteps larger than 1. The results are far better.

const {
  booleans,
  extrusions,
  geometries,
  maths,
  primitives,
  transforms,
} = require('@jscad/modeling')

const main = () => {
  const base = booleans.subtract(
    primitives.circle(5),
    transforms.translate([1, 0], primitives.circle(5)),
  )

  const xtr05 = transforms.translate(
    [0, 0, 0.7],
    extrusions.extrudeLinear(
      {
        height: 2,
        twistAngle: 0.5,
        twistSteps: 10,
      },
      base,
    ),
  )

  const xtr10 = transforms.translate(
    [0, 0, 0.7],
    extrusions.extrudeLinear(
      {
        height: 2,
        twistAngle: 1,
        twistSteps: 10,
      },
      base,
    ),
  )

  return [
    // Good intersection, 0.5rad
    transforms.translate(
      [0, 0, 0],
      booleans.intersect(xtr05, primitives.cube()),
    ),

    // Bad intersection, 1.0rad
    transforms.translate(
      [5, 0, 0],
      booleans.intersect(xtr10, primitives.cube()),
    ),
  ]
}
module.exports = {main}

z3dev avatar Mar 13 '22 02:03 z3dev

@paulftw are you able to continue after making the suggested changes?

z3dev avatar Mar 26 '22 05:03 z3dev