jscad / OpenJSCAD.org

JSCAD is an open source set of modular, browser and command line tools for creating parametric 2D and 3D designs with JavaScript code. It provides a quick, precise and reproducible method for generating 3D models, and is especially useful for 3D printing applications.
https://openjscad.xyz/
MIT License
2.58k stars 505 forks source link

subtracting extrudeHelical object (like threads) from a cube does not work as expected #1309

Closed tsdexter closed 7 months ago

tsdexter commented 7 months ago

Expected Behavior

Extracting the thread shape from the cube should make a clean cut

Actual Behavior

The cut is very messy and missing faces all over the cube

image

Steps to Reproduce the Problem

const jscad = require('@jscad/modeling')
const { cube, cuboid, cylinder, triangle } = jscad.primitives
const { translate, rotate } = jscad.transforms
const { extrudeHelical } = jscad.extrusions
const { subtract, union } = jscad.booleans
const { degToRad } = jscad.utils

console.log(jscad);

const main = () => {
  const thread = union(
        cylinder({height: 55, radius: 10, center: [0,0,27.5], segments: 64}),
        translate(
          [0,0,0],
          extrudeHelical(
            {
              angle: degToRad(3600),
              pitch: 5,
              segmentsPerRotation: 64,
              startAngle: 0,
            },
            translate([10,0,0],
              rotate(
                [degToRad(0),degToRad(0),degToRad(270)],
                triangle({
                  type: 'SSS',
                  values: [5*Math.sqrt(2), 5, 5]
                })
              )
            )
          )
        )
      )
  const allPrimitives = [
    subtract(
      cuboid({size: [40,40,20], center: [0,0,20]}),
      thread
    ),
    translate([0,40,0], thread)
  ]
  console.log({allPrimitives})
  return allPrimitives
}

module.exports = { main }

Specifications

https://openjscad.xyz/#

tsdexter commented 7 months ago

@hrgdavor any ideas as to why this isn't working or tips for creating/working with threads?

hrgdavor commented 7 months ago

@tsdexter I think main issue is in the extruded helical. It is likely messed up, but does not look like messed up upon visual inspection.

@platypii has a nice bolts nuts example on https://jscad.app image

I also have a long standing project creating procedural screw, that can make bolts and nuts without booleans... that one is not that relevant to you, but I just am using this opportunity to share it :D :D http://3d.hrg.hr/jscad/three/threejscad2.html?uri=#model.screw.js

image

tsdexter commented 7 months ago

thanks a lot, just the info I was looking for. I'll take a closer look at the links provided and have another go at it.

z3dev commented 7 months ago

@tsdexter theres a Bolts and Nuts example in V2, as part of the website. You can probably look at that.

There are probably a few different ways to make threads. :)

let us know how things go