Haskell-Things / ImplicitCAD

A math-inspired CAD program in haskell. CSG, bevels, and shells; 2D & 3D geometry; 2D gcode generation...
https://implicitcad.org/
GNU Affero General Public License v3.0
1.41k stars 142 forks source link

Add point and line segment primitives #446

Open sorki opened 1 year ago

sorki commented 1 year ago

While trying to fix some issues with degenerate objects like cube with zero size, it occurred to me that the result of these shouldn't be an emptySpace we currently have but a 2D or 1D primitive.

That would allow us to have 1D in core which some backends could render properly (i.e. SVG, PNG, GCode can represent points and line segments) while STL could just ignore these (possibly with a warning).

Some examples

Ideally things would play nicely together when going between dimensions using extrude and slice

4D (.. or ND?) subsystem also seems to make sense :upside_down_face:

sorki commented 1 year ago

https://en.wikipedia.org/wiki/Hypercube#Construction

sorki commented 1 year ago

Further remarks:

Currently, extrude is a SymbolicObj3 constructor - Extrude SymbolicObj2 ℝ which results in SymbolicObj3, respectively, slice proposed in #448 is part of SymbolicObj2 turning 3D object into 2D. This currently is the only way to "transition" between dimensions, so we cannot represent things like degenerate cube turning into square.

Studying the types, it seems like SharedObj should be our top-level object (compared to our current SymbolicObj(2|3) that can embed SharedObj) so we can for example start with a 3D object but get 2D on the output (or both). This is already a case for OpenSCAD path, that returns both 2D and 3D objects present in SCAD input file - instead of treating these separately, they would simply get contained in a single union.

Another case to consider are current output functions, which already take abstract obj as input, but doesn't allow mixing dimensions as obj is unified with DiscreteApproxable obj to either DiscreteAproxable SymbolicObj2 format or DiscreteAproxable SymbolicObj3 format. Proposed alternative, would defer the handling of objects with varying dimensions to the export function, that could decide what to do with things it cannot handle (i.e. STL would discard points, extrude 2D to 3D (or ignore 2D), ignore higher dims).

sorki commented 1 year ago

Better names for LowerDim and HigherDim seems to be SubSpace and SuperSpace. We could also consider notion of ambient space which currently seems to be fixed to 3 dimensional euclidean space.

sorki commented 1 year ago

Related https://github.com/openscad/openscad/wiki/OEP7%3A-Mixed-Dimension-Geometry-Support