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) {
|
module fDraw(model) {
|
||||||
polyhedron(points=fPoints(model), faces=fFaces(model));
|
polyhedron(points=fModelPoints(model), faces=fModelFaces(model));
|
||||||
}
|
}
|
||||||
|
|
||||||
module fDrawN(model, scales) {
|
module fDrawN(model, scales) {
|
||||||
fDraw(model);
|
fDraw(model);
|
||||||
points = fPoints(model);
|
points = fModelPoints(model);
|
||||||
model_max = fMaxPoint(model);
|
model_max = fMaxPoint(model);
|
||||||
translation =
|
translation =
|
||||||
[for (axis = [0 : 2])
|
[for (axis = [0 : 2])
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
|
include <coord.scad>;
|
||||||
include <cube.scad>;
|
include <cube.scad>;
|
||||||
include <cylinder.scad>;
|
include <cylinder.scad>;
|
||||||
include <draw.scad>;
|
include <draw.scad>;
|
||||||
include <math.scad>;
|
include <math.scad>;
|
||||||
include <model.scad>;
|
include <model.scad>;
|
||||||
include <obj_util.scad>;
|
include <model_util.scad>;
|
||||||
include <sphere.scad>;
|
include <sphere.scad>;
|
||||||
include <translate.scad>;
|
include <translate.scad>;
|
||||||
include <types.scad>;
|
include <types.scad>;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/// model:
|
/// model:
|
||||||
/// fKeyType "type" fType(): fTypeModel "model"
|
/// fKeyType "type" fType(): fTypeModel "model"
|
||||||
/// fKeyPoints "points" fPoints(): [ [x, y, z], ... ]
|
/// fKeyPoints "points" fModelPoints(): [ [x, y, z], ... ]
|
||||||
/// fKeyFaces "faces" fFaces(): [ [ pointIdx, ... ], ... ]
|
/// fKeyFaces "faces" fModelFaces(): [ [ pointIdx, ... ], ... ]
|
||||||
|
|
||||||
fTypeModel = "model";
|
fTypeModel = "model";
|
||||||
|
|
||||||
@@ -20,10 +20,10 @@ function fModel(points, faces) = (
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
function fPoints(model) = (
|
function fModelPoints(model) = (
|
||||||
fMapLookup(fKeyPoints, model)
|
fMapLookup(fKeyPoints, model)
|
||||||
);
|
);
|
||||||
|
|
||||||
function fFaces(model) = (
|
function fModelFaces(model) = (
|
||||||
fMapLookup(fKeyFaces, model)
|
fMapLookup(fKeyFaces, model)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
function fMinPoint(model) = (
|
function fMinPoint(model) = (
|
||||||
[for (axis = [0 : 2])
|
[for (axis = [0 : 2])
|
||||||
min([for (point = fPoints(model)) point[axis]])]
|
min([for (point = fModelPoints(model)) point[axis]])]
|
||||||
);
|
);
|
||||||
|
|
||||||
function fMaxPoint(model) = (
|
function fMaxPoint(model) = (
|
||||||
[for (axis = [0 : 2])
|
[for (axis = [0 : 2])
|
||||||
max([for (point = fPoints(model)) point[axis]])]
|
max([for (point = fModelPoints(model)) point[axis]])]
|
||||||
);
|
);
|
||||||
|
|
||||||
function fCenterPoint(model) = (
|
function fCenterPoint(model) = (
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
function fTranslate(model, translation) = (
|
function fTranslate(model, translation) = (
|
||||||
[
|
fModel(
|
||||||
[fKeyPoints,
|
points=
|
||||||
[for (point = fPoints(model))
|
[for (point = fModelPoints(model))
|
||||||
[for (axis = [0 : 2])
|
[for (axis = [0 : 2])
|
||||||
point[axis] + translation[axis]]
|
point[axis] + translation[axis]]
|
||||||
]
|
],
|
||||||
],
|
faces=fModelFaces(model)
|
||||||
[fKeyFaces, fFaces(model)],
|
)
|
||||||
]
|
|
||||||
);
|
);
|
||||||
|
|
||||||
function fZeroN(model, scales) = (
|
function fZeroN(model, scales) = (
|
||||||
|
|||||||
@@ -44,8 +44,8 @@ function fIsVector(x) = (
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Helpers
|
// Helpers
|
||||||
function fMapLookup(key, model) = (
|
function fMapLookup(key, map) = (
|
||||||
[for (pair = model)
|
[for (pair = map)
|
||||||
let (iter_key = pair[0],
|
let (iter_key = pair[0],
|
||||||
iter_value = pair[1])
|
iter_value = pair[1])
|
||||||
if (key == iter_key)
|
if (key == iter_key)
|
||||||
|
|||||||
Reference in New Issue
Block a user