Remove start/end angle, do substantial cleanup
This commit is contained in:
110
fcad.scad
110
fcad.scad
@@ -1,8 +1,8 @@
|
|||||||
fDraw(fSphere(5));
|
fDraw(fSphere(10));
|
||||||
|
|
||||||
///// Drawing modules
|
///// Drawing modules
|
||||||
module fDraw(model) {
|
module fDraw(model) {
|
||||||
polyhedron(points=fPoints(model), faces=fFaces(model));
|
polyhedron(points=fPoints(model), faces=fFaces(model));
|
||||||
}
|
}
|
||||||
|
|
||||||
module fDrawN(model, scales) {
|
module fDrawN(model, scales) {
|
||||||
@@ -11,8 +11,8 @@ module fDrawN(model, scales) {
|
|||||||
model_max = fMaxPoint(model);
|
model_max = fMaxPoint(model);
|
||||||
translation =
|
translation =
|
||||||
[for (axis = [0 : 2])
|
[for (axis = [0 : 2])
|
||||||
scales[axis] * model_max[axis]];
|
scales[axis] * model_max[axis]];
|
||||||
translate(translation) children();
|
translate(translation) children();
|
||||||
}
|
}
|
||||||
|
|
||||||
module fDrawX(model) {
|
module fDrawX(model) {
|
||||||
@@ -45,64 +45,45 @@ function fCube(dims) = (
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
function fCylinder(r, h, start_angle=0, end_angle=360, sides=36) = (
|
function fCylinder(h, r, sides=36) = (
|
||||||
let(degrees_per_face = (end_angle - start_angle) / sides,
|
let(degrees_per_side = 360 / sides,
|
||||||
face_range = [0 : sides - 1],
|
side_range = [0 : sides - 1])
|
||||||
vertical_range = [0 : sides],
|
|
||||||
complete = (start_angle == 0 && end_angle == 360),
|
|
||||||
bottom_index = (sides + 1) * 2)
|
|
||||||
[
|
[
|
||||||
[fKeyPoints, concat(
|
[fKeyPoints,
|
||||||
fCartesianProduct([
|
fCartesianProduct([
|
||||||
[for (i = vertical_range)
|
[for (side = side_range)
|
||||||
let (angle = start_angle + (i * degrees_per_face))
|
let (angle = side * degrees_per_side)
|
||||||
[r * sin(angle), r * cos(angle)]],
|
[r * sin(angle), r * cos(angle)]],
|
||||||
[0, h],
|
[0, h],
|
||||||
]),
|
]),
|
||||||
complete ? [] : [
|
],
|
||||||
[0, 0, 0], // bottom center
|
|
||||||
[0, 0, h], // top center
|
|
||||||
]
|
|
||||||
)],
|
|
||||||
[fKeyFaces, concat(
|
[fKeyFaces, concat(
|
||||||
// bottom
|
// bottom
|
||||||
[concat(
|
[[for (side = [sides : -1 : 0]) side * 2]],
|
||||||
[for (i = [sides : -1 : 0]) i * 2],
|
|
||||||
complete ? [] : [bottom_index]
|
|
||||||
)],
|
|
||||||
// top
|
// top
|
||||||
[concat(
|
[[for (side = [0 : sides]) side * 2 + 1]],
|
||||||
[for (i = [0 : sides]) i * 2 + 1],
|
|
||||||
complete ? [] : [bottom_index + 1]
|
|
||||||
)],
|
|
||||||
// sides
|
// sides
|
||||||
[for (i = face_range)
|
[for (side = side_range)
|
||||||
[for (j = [2, 3, 1, 0]) i * 2 + j]],
|
[for (vertex = [2, 3, 1, 0]) (side * 2 + vertex) % (sides * 2)]]
|
||||||
// cut ins
|
|
||||||
complete ? [] : [
|
|
||||||
[0, 1, bottom_index + 1, bottom_index],
|
|
||||||
[bottom_index - 1, bottom_index - 2, bottom_index, bottom_index + 1],
|
|
||||||
]
|
|
||||||
)],
|
)],
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
function fSphere(r, sides=36, stripes=18) = (
|
function fSphere(r, sides=36, stripes=18) = (
|
||||||
let(stripe_slice = 180 / stripes,
|
let(degrees_per_slice = 180 / stripes,
|
||||||
side_slice = 360 / sides,
|
degrees_per_side = 360 / sides,
|
||||||
top_index = (stripes - 1) * sides,
|
top_index = (stripes - 1) * sides)
|
||||||
bottom_index = top_index + 1)
|
|
||||||
[
|
[
|
||||||
[fKeyPoints, concat(
|
[fKeyPoints, concat(
|
||||||
[for (stripe_index = [1 : stripes - 1])
|
[for (stripe_index = [1 : stripes - 1])
|
||||||
for (side_index = [0 : sides - 1])
|
for (side_index = [0 : sides - 1])
|
||||||
let (stripe_angle = stripe_index * stripe_slice,
|
let (stripe_angle = stripe_index * degrees_per_slice,
|
||||||
side_angle = side_index * side_slice,
|
side_angle = side_index * degrees_per_side,
|
||||||
stripe_radius = r * sin(stripe_angle),
|
stripe_radius = r * sin(stripe_angle),
|
||||||
stripe_z = r * cos(stripe_angle),
|
stripe_z = r * cos(stripe_angle),
|
||||||
side_x = stripe_radius * sin(side_angle),
|
side_x = stripe_radius * sin(side_angle),
|
||||||
side_y = stripe_radius * cos(side_angle))
|
side_y = stripe_radius * cos(side_angle))
|
||||||
[side_x, side_y, stripe_z]
|
[side_x, side_y, stripe_z]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[0, 0, r], // top
|
[0, 0, r], // top
|
||||||
@@ -110,28 +91,39 @@ function fSphere(r, sides=36, stripes=18) = (
|
|||||||
]
|
]
|
||||||
)],
|
)],
|
||||||
[fKeyFaces, concat(
|
[fKeyFaces, concat(
|
||||||
|
// side squares
|
||||||
[for (stripe_index = [2 : stripes - 1])
|
[for (stripe_index = [2 : stripes - 1])
|
||||||
for (side_index = [0 : sides - 1])
|
for (side_index = [0 : sides - 1])
|
||||||
let (prev_side_base = (stripe_index - 2) * sides,
|
let (prev_side_base = (stripe_index - 2) * sides,
|
||||||
side_base = (stripe_index - 1) * sides)
|
side_base = (stripe_index - 1) * sides)
|
||||||
[prev_side_base + (side_index + 1) % sides,
|
[
|
||||||
prev_side_base + side_index,
|
prev_side_base + (side_index + 1) % sides,
|
||||||
side_base + side_index,
|
prev_side_base + side_index,
|
||||||
side_base + (side_index + 1) % sides]
|
side_base + side_index,
|
||||||
|
side_base + (side_index + 1) % sides,
|
||||||
|
]
|
||||||
],
|
],
|
||||||
|
// top triangles
|
||||||
[for (side_index = [0 : sides - 1])
|
[for (side_index = [0 : sides - 1])
|
||||||
[top_index, side_index, (side_index + 1) % sides]
|
[
|
||||||
|
top_index,
|
||||||
|
side_index,
|
||||||
|
(side_index + 1) % sides,
|
||||||
|
]
|
||||||
],
|
],
|
||||||
|
// bottom triangles
|
||||||
[for (side_index = [0 : sides - 1])
|
[for (side_index = [0 : sides - 1])
|
||||||
let (side_base = (stripes - 2) * sides)
|
let (side_base = (stripes - 2) * sides)
|
||||||
[bottom_index,
|
[
|
||||||
side_base + (side_index + 1) % sides,
|
top_index + 1,
|
||||||
side_base + side_index]
|
side_base + (side_index + 1) % sides,
|
||||||
|
side_base + side_index,
|
||||||
|
]
|
||||||
]
|
]
|
||||||
)],
|
)],
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
///// 3D object information functions
|
///// 3D object information functions
|
||||||
function fMinPoint(model) = (
|
function fMinPoint(model) = (
|
||||||
[for (axis = [0 : 2])
|
[for (axis = [0 : 2])
|
||||||
@@ -141,7 +133,7 @@ function fMinPoint(model) = (
|
|||||||
function fMaxPoint(model) = (
|
function fMaxPoint(model) = (
|
||||||
[for (axis = [0 : 2])
|
[for (axis = [0 : 2])
|
||||||
max([for (point = fPoints(model)) point[axis]])]
|
max([for (point = fPoints(model)) point[axis]])]
|
||||||
);
|
);
|
||||||
|
|
||||||
function fCenterPoint(model) = (
|
function fCenterPoint(model) = (
|
||||||
let(model_min = fMinPoint(model),
|
let(model_min = fMinPoint(model),
|
||||||
@@ -152,7 +144,7 @@ function fCenterPoint(model) = (
|
|||||||
[for (axis = [0 : 2])
|
[for (axis = [0 : 2])
|
||||||
model_min[axis] + (model_size[axis] / 2)]
|
model_min[axis] + (model_size[axis] / 2)]
|
||||||
);
|
);
|
||||||
|
|
||||||
///// 3D object translation functions
|
///// 3D object translation functions
|
||||||
function fTranslate(model, translation) = (
|
function fTranslate(model, translation) = (
|
||||||
[
|
[
|
||||||
@@ -173,15 +165,15 @@ function fZeroN(model, scales) = (
|
|||||||
scales[axis] * model_min[axis]])
|
scales[axis] * model_min[axis]])
|
||||||
fTranslate(model, translation)
|
fTranslate(model, translation)
|
||||||
);
|
);
|
||||||
|
|
||||||
function fZeroX(model) = (
|
function fZeroX(model) = (
|
||||||
fZeroN(model, [-1, 0, 0])
|
fZeroN(model, [-1, 0, 0])
|
||||||
);
|
);
|
||||||
|
|
||||||
function fZeroY(model) = (
|
function fZeroY(model) = (
|
||||||
fZeroN(model, [0, -1, 0])
|
fZeroN(model, [0, -1, 0])
|
||||||
);
|
);
|
||||||
|
|
||||||
function fZeroZ(model) = (
|
function fZeroZ(model) = (
|
||||||
fZeroN(model, [0, 0, -1])
|
fZeroN(model, [0, 0, -1])
|
||||||
);
|
);
|
||||||
@@ -193,7 +185,7 @@ function fCenterN(model, scales) = (
|
|||||||
scales[axis] * model_center[axis]])
|
scales[axis] * model_center[axis]])
|
||||||
fTranslate(model, translation)
|
fTranslate(model, translation)
|
||||||
);
|
);
|
||||||
|
|
||||||
function fCenterX(model) = (
|
function fCenterX(model) = (
|
||||||
fCenterN(model, [-1, 0, 0])
|
fCenterN(model, [-1, 0, 0])
|
||||||
);
|
);
|
||||||
@@ -201,7 +193,7 @@ function fCenterX(model) = (
|
|||||||
function fCenterY(model) = (
|
function fCenterY(model) = (
|
||||||
fCenterN(model, [0, -1, 0])
|
fCenterN(model, [0, -1, 0])
|
||||||
);
|
);
|
||||||
|
|
||||||
function fCenterZ(model) = (
|
function fCenterZ(model) = (
|
||||||
fCenterN(model, [0, 0, -1])
|
fCenterN(model, [0, 0, -1])
|
||||||
);
|
);
|
||||||
@@ -222,7 +214,7 @@ fTypeUnknown = "unknown";
|
|||||||
function fType(x) = (
|
function fType(x) = (
|
||||||
x == undef ? fTypeUndef
|
x == undef ? fTypeUndef
|
||||||
: floor(x) == x ? fTypeInt
|
: floor(x) == x ? fTypeInt
|
||||||
: abs(x) + 1 > abs(x) ? fTypeFloat
|
: abs(x) + 1 > abs(x) ? fTypeFloat
|
||||||
: str(x) == x ? fTypeString
|
: str(x) == x ? fTypeString
|
||||||
: str(x) == "false" || str(x) == "true" ? fTypeBoolean
|
: str(x) == "false" || str(x) == "true" ? fTypeBoolean
|
||||||
: (x[0] == x[0]) && len(x) != undef ? fTypeVector
|
: (x[0] == x[0]) && len(x) != undef ? fTypeVector
|
||||||
@@ -269,7 +261,7 @@ function fVectorSlice(vec, start=0, step=undef, end=undef) = (
|
|||||||
[for (i = [start : real_step : real_end])
|
[for (i = [start : real_step : real_end])
|
||||||
vec[i]]
|
vec[i]]
|
||||||
);
|
);
|
||||||
|
|
||||||
function fCartesianProduct(vecs) = (
|
function fCartesianProduct(vecs) = (
|
||||||
len(vecs) == 1 ?
|
len(vecs) == 1 ?
|
||||||
vecs[0]
|
vecs[0]
|
||||||
@@ -282,7 +274,7 @@ function fCartesianProduct(vecs) = (
|
|||||||
function fPoints(model) = (
|
function fPoints(model) = (
|
||||||
fMapLookup(fKeyPoints, model)
|
fMapLookup(fKeyPoints, model)
|
||||||
);
|
);
|
||||||
|
|
||||||
function fFaces(model) = (
|
function fFaces(model) = (
|
||||||
fMapLookup(fKeyFaces, model)
|
fMapLookup(fKeyFaces, model)
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user