Clean up naming, add coord

This commit is contained in:
Ian Gulliver
2016-12-25 12:26:34 -08:00
parent b2c7a0508a
commit f667b1385d
8 changed files with 54 additions and 19 deletions

35
fcad/coord.scad Normal file
View 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)
);

View File

@@ -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])

View File

@@ -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>;

View File

@@ -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)
);

View File

@@ -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) = (

View File

@@ -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) = (

View File

@@ -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)

View File

@@ -2,4 +2,4 @@ use <fcad/fcad.scad>;
fDrawX(fCylinder(10, r1=5, r2=2))
fDrawX(fSphere(10))
fDrawX(fCube(10));
fDrawX(fCube(10));