connectors proposal - hrgdavor/OpenJSCAD.org Wiki

Original URL: https://github.com/hrgdavor/OpenJSCAD.org/wiki/connectors-proposal

What I thinkg we need

A connector generator is useful, because different geometries have different logical places where connectors could be and how to calculate their position.

After that we need a pattern to use and combine the connectors

My preferred shortcut for aligning models that I already use in jscad scripts that I will use in these examples:

Code using connectors that would be equal to creating a cuboid with size: [10,10,10]

let cube = cuboidConnector({size:[10,10,10]})
return cube;

image

Although it looks similar it gets better when you start moving things

// create cuboid, but use bottom-south-west corner  to place it at xyz origin.
// it facing down because first letter(B) is for direction, the rest are for location
let cube = cuboidConnector({size:[10,10,10]}, 'BBSW')
return cube

image

The magic happens when you add cone to the East face of the cube

// create cuboid, but use bottom-south-west corner  to place it at xyz origin
// facing down because first letter(B) is for direction, rest for location
let cube = cuboidConnector({size:[10,10,10]}, 'BBSW')
let cone    = cylinderConnector({height:10, startRadius: [5,5], endRadius:[1]})
// align cube by fixating at East side of cube, and moving bottom of the cone there
cone = align(cube, 'E',cone, 'B') // original cone is not touched, a copy is created
// align would do this by calling cube.getConnector('E') and cone.getConnector(B) and then do the move
return [cube, cone];

image

Add a sphere on top of the cone

let cube = cuboidConnector({size:[10,10,10]}, 'BBSW')
let cone    = cylinderConnector({height:10, startRadius: [5,5], endRadius:[1]})
cone = align(cube,'E', cone, 'B') // original cone is not touched, a copy is created
return [cube, cone, align(cone,'T',sphere())];

image