jscad / csg.js

DEPRECATED: CSG Library for JSCAD (See the link below)
https://github.com/jscad/OpenJSCAD.org/tree/master/packages/modeling
MIT License
218 stars 56 forks source link

2d translate doesn't operate in Z plane #192

Closed thesjg closed 4 years ago

thesjg commented 4 years ago

let circleA = circle({r: 5}); let circleB = circleA.translate([0,0,100]) return circleB;

Does not move the circle in the desired direction. Performing a translate in either other axis has the expected result.

z3dev commented 4 years ago

@thesjg thanks for the post

The operations on 2D geometry always assume Z=0, which is expected. You can convert to 3D geometry by extruding.

Will that work for your design?

thesjg commented 4 years ago

@z3dev I was hoping to build 3d geometry by hull()'ing or chain_hull()'ing 2d geometry together that had been translate()'d in Z. 2d geometry also doesn't appear to be able to be rotated off of Z=0. This seems to severely limit the functionality of hull, without an available 3d hull, unless I'm missing something basic?

Thanks

thesjg commented 4 years ago

@z3dev I solved this for my application using a rotational extrude -- just attacked it from a different direction. In keeping with the assumed Z=0 for 2D geometry, it would be nice to see the concept of "planes" or similar... and following that it would be logical to be able to project 2d geometry between planes. I think that's how the common CAD packages deal with this.

Thanks!

    let barrel = rotate_extrude({fn: 72, startAngle: 0, angle: 360},
        polygon({ points: [
            [0, 0],
            [inch_to_mm(myBarrelData['muzzle_diameter'] / 2), 0],
            [inch_to_mm(myBarrelData['neck_diameter'] / 2), inch_to_mm(myBarrelData['finish_length'] - myBarrelData['neck_length'])],
            [inch_to_mm(myBarrelData['cylinder_diameter'] / 2), inch_to_mm(myBarrelData['finish_length'] - myBarrelData['cylinder_length'])],
            [inch_to_mm(myBarrelData['cylinder_diameter'] / 2), inch_to_mm(myBarrelData['finish_length'])],
            [0, inch_to_mm(myBarrelData['finish_length'])],
            [0, 0]
        ] })
    );
z3dev commented 4 years ago

Super. FYI, there’s a pull request to add 3D hull to V1 of CSG #134 You might be interested in this if you get stuck in your designs.

z3dev commented 4 years ago

@thesjg V2 now has 3D hull, and 3D hullChain functionality. Would you like to try it out?

z3dev commented 4 years ago

@thesjg there’s a few changes in the ‘extrude’ space in JSCAD V2. All extrusions use the same underlying function called extrudeFromSlices(). This has been improved allowing convex as well as complex ‘slices’ to be extruded along steps. For a good example, see the code for extrudeRotate().

The key data structure is the ‘slice’ which is a planar 3D polygon. This can be transformed just like any 3D shape, and should allow further extensions to extrusions.

thesjg commented 4 years ago

Cool! Thanks for the updates, I will try these out!

z3dev commented 4 years ago

Cool. Here’s where to start.

https://openjscad.org/dokuwiki/doku.php?id=early_v2

z3dev commented 4 years ago

@thesjg I hope that you have a solution, or even many by now.

Please close this issue.

thesjg commented 4 years ago

Have not yet had a chance to try, but closing this issue to clear the clutter.

z3dev commented 4 years ago

Also, there are now some examples of extruding in 3D space. These might be a good starting place for you designs.

https://github.com/jscad/OpenJSCAD.org/tree/V2/packages/examples/core/curves/bezier