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

artifacts between rounded cuboid and extruded appendArc

Open Evgsurf opened this issue 6 months ago • 4 comments

There is some black magic. Arc from rounded cuboid and just arc from path with the same segments are not equal.

const jscad = require('@jscad/modeling')
const { arc, circle, ellipse, line, polygon, rectangle, roundedRectangle, square, star } = require('@jscad/modeling').primitives
const { translate } = require('@jscad/modeling').transforms
const { extrudeRectangular, extrudeLinear, extrudeRotate } = jscad.extrusions
const { path2, geom2 } = jscad.geometries
const { cube, cuboid, cylinder, cylinderElliptic, ellipsoid, geodesicSphere, roundedCuboid, roundedCylinder, sphere, torus, polyhedron } = jscad.primitives
const { union, subtract, intersect } = jscad.booleans

const main = () => {

  const SEGMENTS =  64;


  let path = path2.create([[0,0],[10,0]]);
  path = path2.appendArc({endpoint:[0,10],radius: [10,10],segments:SEGMENTS},path);
  path = path2.close(path);
      geom2.fromPoints(path2.toPoints(path2.close(path)))
                 )
               );
//  return cuboid({size:[10,10,10]});
  const cub = roundedCuboid({size: [40, 40, 40], roundRadius: 10, segments:SEGMENTS});

  return [translate([-20,-20,0],subtract(sec,cub)),
          translate([20,20,0],subtract(cub,sec))]
  ;

}

module.exports = { main }      geom2.fromPoints(path2.toPoints(path2.close(path)))
                 )
               );
//  return cuboid({size:[10,10,10]});
  const cub = roundedCuboid({size: [40, 40, 40], roundRadius: 10, segments:SEGMENTS});

  return [translate([-20,-20,0],subtract(sec,cub)),
          translate([20,20,0],subtract(cub,sec))]
  ;

}

module.exports = { main }

The result on the image

Evgsurf avatar Jun 04 '25 05:06 Evgsurf

Image

Evgsurf avatar Jun 04 '25 05:06 Evgsurf

As I can find the problem is appendArc function, which generates unexpected count of segments.

Evgsurf avatar Jun 04 '25 05:06 Evgsurf

This code generate arc. I expect to get 4 segments, but really there is 5

  const SEGMENTS =  8;


  let path = path2.create([[10,0]]);
  path = path2.appendArc({endpoint:[-10,0],radius: [10,10],segments:SEGMENTS},path);

Image

Evgsurf avatar Jun 04 '25 05:06 Evgsurf

@Evgsurf Nice find! That code has been around for a long long time, so there may be some strange logic.

We still accept fixes for V2, so if you have time... how about changing the code?

z3dev avatar Sep 15 '25 01:09 z3dev