Clean up naming, add coord
This commit is contained in:
35
fcad/coord.scad
Normal file
35
fcad/coord.scad
Normal file
@@ -0,0 +1,35 @@
|
||||
// Short for "coordinate system", including translation, rotation, and scale
|
||||
// coord:
|
||||
// fKeyType "type" fType(): fTypeCoord "coord"
|
||||
// fKeyTranslation "translation" fCoordTranslation():
|
||||
|
||||
fTypeCoord = "coord";
|
||||
|
||||
function fIsCoord(x) = (
|
||||
fType(x) == fTypeCoord
|
||||
);
|
||||
|
||||
fKeyTranslation = "translation";
|
||||
fKeyRotation = "rotation";
|
||||
fKeyScale = "scale";
|
||||
|
||||
function fCoord(translation=[0, 0, 0], rotation=[0, 0, 0], scale=[1, 1, 1]) = (
|
||||
[
|
||||
[fKeyType, fTypeCoord],
|
||||
[fKeyTranslation, translation],
|
||||
[fKeyRotation, rotation],
|
||||
[fKeyScale, scale],
|
||||
]
|
||||
);
|
||||
|
||||
function fCoordTranslation(coord) = (
|
||||
fMapLookup(fKeyTranslation, coord)
|
||||
);
|
||||
|
||||
function fCoordRotation(coord) = (
|
||||
fMapLookup(fKeyRotation, coord)
|
||||
);
|
||||
|
||||
function fCoordScale(coord) = (
|
||||
fMapLookup(fKeyScale, coord)
|
||||
);
|
||||
@@ -1,10 +1,10 @@
|
||||
module fDraw(model) {
|
||||
polyhedron(points=fPoints(model), faces=fFaces(model));
|
||||
polyhedron(points=fModelPoints(model), faces=fModelFaces(model));
|
||||
}
|
||||
|
||||
module fDrawN(model, scales) {
|
||||
fDraw(model);
|
||||
points = fPoints(model);
|
||||
points = fModelPoints(model);
|
||||
model_max = fMaxPoint(model);
|
||||
translation =
|
||||
[for (axis = [0 : 2])
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
include <coord.scad>;
|
||||
include <cube.scad>;
|
||||
include <cylinder.scad>;
|
||||
include <draw.scad>;
|
||||
include <math.scad>;
|
||||
include <model.scad>;
|
||||
include <obj_util.scad>;
|
||||
include <model_util.scad>;
|
||||
include <sphere.scad>;
|
||||
include <translate.scad>;
|
||||
include <types.scad>;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/// model:
|
||||
/// fKeyType "type" fType(): fTypeModel "model"
|
||||
/// fKeyPoints "points" fPoints(): [ [x, y, z], ... ]
|
||||
/// fKeyFaces "faces" fFaces(): [ [ pointIdx, ... ], ... ]
|
||||
/// fKeyPoints "points" fModelPoints(): [ [x, y, z], ... ]
|
||||
/// fKeyFaces "faces" fModelFaces(): [ [ pointIdx, ... ], ... ]
|
||||
|
||||
fTypeModel = "model";
|
||||
|
||||
@@ -20,10 +20,10 @@ function fModel(points, faces) = (
|
||||
]
|
||||
);
|
||||
|
||||
function fPoints(model) = (
|
||||
function fModelPoints(model) = (
|
||||
fMapLookup(fKeyPoints, model)
|
||||
);
|
||||
|
||||
function fFaces(model) = (
|
||||
function fModelFaces(model) = (
|
||||
fMapLookup(fKeyFaces, model)
|
||||
);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
function fMinPoint(model) = (
|
||||
[for (axis = [0 : 2])
|
||||
min([for (point = fPoints(model)) point[axis]])]
|
||||
min([for (point = fModelPoints(model)) point[axis]])]
|
||||
);
|
||||
|
||||
function fMaxPoint(model) = (
|
||||
[for (axis = [0 : 2])
|
||||
max([for (point = fPoints(model)) point[axis]])]
|
||||
max([for (point = fModelPoints(model)) point[axis]])]
|
||||
);
|
||||
|
||||
function fCenterPoint(model) = (
|
||||
@@ -1,13 +1,12 @@
|
||||
function fTranslate(model, translation) = (
|
||||
[
|
||||
[fKeyPoints,
|
||||
[for (point = fPoints(model))
|
||||
fModel(
|
||||
points=
|
||||
[for (point = fModelPoints(model))
|
||||
[for (axis = [0 : 2])
|
||||
point[axis] + translation[axis]]
|
||||
]
|
||||
],
|
||||
[fKeyFaces, fFaces(model)],
|
||||
]
|
||||
],
|
||||
faces=fModelFaces(model)
|
||||
)
|
||||
);
|
||||
|
||||
function fZeroN(model, scales) = (
|
||||
|
||||
@@ -44,8 +44,8 @@ function fIsVector(x) = (
|
||||
);
|
||||
|
||||
// Helpers
|
||||
function fMapLookup(key, model) = (
|
||||
[for (pair = model)
|
||||
function fMapLookup(key, map) = (
|
||||
[for (pair = map)
|
||||
let (iter_key = pair[0],
|
||||
iter_value = pair[1])
|
||||
if (key == iter_key)
|
||||
|
||||
Reference in New Issue
Block a user