From 9f68fb41dc5456eb849718339e02afcc2f60f868 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Sun, 25 Dec 2016 12:57:32 -0800 Subject: [PATCH] Initial coords for Cube --- fcad/coord.scad | 4 +++- fcad/cube.scad | 4 ++++ fcad/model.scad | 28 +++++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/fcad/coord.scad b/fcad/coord.scad index 86287bf..08ab285 100644 --- a/fcad/coord.scad +++ b/fcad/coord.scad @@ -1,7 +1,9 @@ // Short for "coordinate system", including translation, rotation, and scale // coord: // fKeyType "type" fType(): fTypeCoord "coord" -// fKeyTranslation "translation" fCoordTranslation(): +// fKeyTranslation "translation" fCoordTranslation(): [ x, y, z ] +// fKeyRotation "rotation" fCoordRotation(): [ x, y, z ] +// fKeyScale "scale" fCoordScale(): [ x, y, z ] fTypeCoord = "coord"; diff --git a/fcad/cube.scad b/fcad/cube.scad index ce843bd..0297ccf 100644 --- a/fcad/cube.scad +++ b/fcad/cube.scad @@ -11,6 +11,10 @@ function fCube(dims) = ( [4, 5, 7, 6], // +x [2, 6, 7, 3], // +y [1, 3, 7, 5], // +z + ], + coords=[ + [ "/x+,/y+,-z+", fCoord(translation=[x / 2, y / 2, 0]) ], + [ "/x+,/y+,+z+", fCoord(translation=[x / 2, y / 2, z]) ], ] ) ); diff --git a/fcad/model.scad b/fcad/model.scad index 38ee1ae..c03a527 100644 --- a/fcad/model.scad +++ b/fcad/model.scad @@ -2,6 +2,14 @@ /// fKeyType "type" fType(): fTypeModel "model" /// fKeyPoints "points" fModelPoints(): [ [x, y, z], ... ] /// fKeyFaces "faces" fModelFaces(): [ [ pointIdx, ... ], ... ] +/// fKeyCoords "coords" fModelCoords(): [ [ name, coord ], ... ] + +/// Standard model coords names: +/// +/// [-/+] edge ("/" is midpoint) +/// [xyz] axis +/// [-+] direction +/// [-/+]x[-+],[-/+]y[-+],[-/+]z[-+] fTypeModel = "model"; @@ -11,12 +19,14 @@ function fIsModel(x) = ( fKeyPoints = "points"; fKeyFaces = "faces"; +fKeyCoords = "coords"; -function fModel(points, faces) = ( +function fModel(points, faces, coords=[]) = ( [ [fKeyType, fTypeModel], [fKeyPoints, points], [fKeyFaces, faces], + [fKeyCoords, coords], ] ); @@ -27,3 +37,19 @@ function fModelPoints(model) = ( function fModelFaces(model) = ( fMapLookup(fKeyFaces, model) ); + +fCoordAliases = [ + [ "bottom", "/x+,/y+,-z+" ], + [ "top", "/x+,/y+,+z+" ], + [ "center", "/x+,/y+,/z+" ], +]; + +function fModelCoords(model) = ( + fMapLookup(fKeyCoords, model) +); + +function fModelCoord(model, name) = ( + let(alias = fMapLookup(name, fCoordAliases), + realName = alias ? alias : name) + fMapLookup(realName, fModelCoords(model)) +);