Reworked orientation to use vectors. Added spin.

This commit is contained in:
Revar Desmera
2019-05-25 23:31:05 -07:00
parent d236fbf640
commit 16919f39c3
25 changed files with 978 additions and 768 deletions

View File

@@ -7,10 +7,8 @@ cuboid([60,40,40], rounding=5, edges=edges("Z"), anchor=BOTTOM) {
attach(TOP) cylinder(d=20, h=30) {
attach(TOP) cylinder(d1=50, d2=30, h=12);
}
for (a = [FRONT, BACK, LEFT, RIGHT]) {
attach(a) cylinder(d1=14, d2=5, h=20) {
attach(TOP, LEFT, overlap=5) prismoid([30,20], [20,20], h=10, shift=[-7,0]);
}
attach([FRONT, BACK, LEFT, RIGHT]) cylinder(d1=14, d2=5, h=20) {
attach(TOP, LEFT, overlap=5) prismoid([30,20], [20,20], h=10, shift=[-7,0]);
}
}
}

View File

@@ -2,10 +2,11 @@ include <BOSL2/std.scad>
include <BOSL2/paths.scad>
include <BOSL2/beziers.scad>
rounding_factor = 0.667;
function CR_corner(size, orient=[0,0,0], trans=[0,0,0]) =
function CR_corner(size, spin=0, orient=UP, trans=[0,0,0]) =
let (
r = 0.4,
r = rounding_factor,
k = r/2,
// I know this patch is not yet correct for continuous
// rounding, but it's a first approximation proof of concept.
@@ -19,16 +20,16 @@ function CR_corner(size, orient=[0,0,0], trans=[0,0,0]) =
]
) [for (row=patch)
translate_points(v=trans,
rotate_points3d(v=orient,
rotate_points3d(a=spin, from=UP, to=orient,
scale_points(v=size, row)
)
)
];
function CR_edge(size, orient=[0,0,0], trans=[0,0,0]) =
function CR_edge(size, spin=0, orient=UP, trans=[0,0,0]) =
let (
r = 0.4,
r = rounding_factor,
a = -1/2,
b = -1/4,
c = 1/4,
@@ -45,7 +46,7 @@ function CR_edge(size, orient=[0,0,0], trans=[0,0,0]) =
]
) [for (row=patch)
translate_points(v=trans,
rotate_points3d(v=orient,
rotate_points3d(a=spin, from=UP, to=orient,
scale_points(v=size, row)
)
)
@@ -57,43 +58,43 @@ module CR_cube(size=[100,100,100], r=10, splinesteps=8, cheat=false)
s = size-2*[r,r,r];
h = size/2;
corners = [
CR_corner([r,r,r], orient=ORIENT_Z, trans=[-size.x/2, -size.y/2, -size.z/2]),
CR_corner([r,r,r], orient=ORIENT_Z_90, trans=[ size.x/2, -size.y/2, -size.z/2]),
CR_corner([r,r,r], orient=ORIENT_Z_180, trans=[ size.x/2, size.y/2, -size.z/2]),
CR_corner([r,r,r], orient=ORIENT_Z_270, trans=[-size.x/2, size.y/2, -size.z/2]),
CR_corner([r,r,r], spin=0, orient=UP, trans=[-size.x/2, -size.y/2, -size.z/2]),
CR_corner([r,r,r], spin=90, orient=UP, trans=[ size.x/2, -size.y/2, -size.z/2]),
CR_corner([r,r,r], spin=180, orient=UP, trans=[ size.x/2, size.y/2, -size.z/2]),
CR_corner([r,r,r], spin=270, orient=UP, trans=[-size.x/2, size.y/2, -size.z/2]),
CR_corner([r,r,r], orient=ORIENT_ZNEG, trans=[ size.x/2, -size.y/2, size.z/2]),
CR_corner([r,r,r], orient=ORIENT_ZNEG_90, trans=[-size.x/2, -size.y/2, size.z/2]),
CR_corner([r,r,r], orient=ORIENT_ZNEG_180, trans=[-size.x/2, size.y/2, size.z/2]),
CR_corner([r,r,r], orient=ORIENT_ZNEG_270, trans=[ size.x/2, size.y/2, size.z/2])
CR_corner([r,r,r], spin=0, orient=DOWN, trans=[ size.x/2, -size.y/2, size.z/2]),
CR_corner([r,r,r], spin=90, orient=DOWN, trans=[-size.x/2, -size.y/2, size.z/2]),
CR_corner([r,r,r], spin=180, orient=DOWN, trans=[-size.x/2, size.y/2, size.z/2]),
CR_corner([r,r,r], spin=270, orient=DOWN, trans=[ size.x/2, size.y/2, size.z/2])
];
edges = [
CR_edge([r, r, s.x], orient=ORIENT_X, trans=[ 0, -h.y, -h.z]),
CR_edge([r, r, s.x], orient=ORIENT_X_90, trans=[ 0, h.y, -h.z]),
CR_edge([r, r, s.x], orient=ORIENT_X_180, trans=[ 0, h.y, h.z]),
CR_edge([r, r, s.x], orient=ORIENT_X_270, trans=[ 0, -h.y, h.z]),
CR_edge([r, r, s.x], spin=0, orient=RIGHT, trans=[ 0, -h.y, h.z]),
CR_edge([r, r, s.x], spin=90, orient=RIGHT, trans=[ 0, -h.y, -h.z]),
CR_edge([r, r, s.x], spin=180, orient=RIGHT, trans=[ 0, h.y, -h.z]),
CR_edge([r, r, s.x], spin=270, orient=RIGHT, trans=[ 0, h.y, h.z]),
CR_edge([r, r, s.y], orient=ORIENT_Y, trans=[ h.x, 0, -h.z]),
CR_edge([r, r, s.y], orient=ORIENT_Y_90, trans=[-h.x, 0, -h.z]),
CR_edge([r, r, s.y], orient=ORIENT_Y_180, trans=[-h.x, 0, h.z]),
CR_edge([r, r, s.y], orient=ORIENT_Y_270, trans=[ h.x, 0, h.z]),
CR_edge([r, r, s.y], spin=0, orient=BACK, trans=[-h.x, 0, h.z]),
CR_edge([r, r, s.y], spin=90, orient=BACK, trans=[ h.x, 0, h.z]),
CR_edge([r, r, s.y], spin=180, orient=BACK, trans=[ h.x, 0, -h.z]),
CR_edge([r, r, s.y], spin=270, orient=BACK, trans=[-h.x, 0, -h.z]),
CR_edge([r, r, s.z], orient=ORIENT_Z, trans=[-h.x, -h.y, 0]),
CR_edge([r, r, s.z], orient=ORIENT_Z_90, trans=[ h.x, -h.y, 0]),
CR_edge([r, r, s.z], orient=ORIENT_Z_180, trans=[ h.x, h.y, 0]),
CR_edge([r, r, s.z], orient=ORIENT_Z_270, trans=[-h.x, h.y, 0])
CR_edge([r, r, s.z], spin=0, orient=UP, trans=[-h.x, -h.y, 0]),
CR_edge([r, r, s.z], spin=90, orient=UP, trans=[ h.x, -h.y, 0]),
CR_edge([r, r, s.z], spin=180, orient=UP, trans=[ h.x, h.y, 0]),
CR_edge([r, r, s.z], spin=270, orient=UP, trans=[-h.x, h.y, 0])
];
faces = [
// Yes, these are degree 1 bezier patches. That means just the four corner points.
// Since these are flat, it doesn't matter what degree they are, and this will reduce calculation overhead.
bezier_patch_flat([s.y, s.z], N=1, orient=ORIENT_X, trans=[ h.x, 0, 0]),
bezier_patch_flat([s.y, s.z], N=1, orient=ORIENT_XNEG, trans=[-h.x, 0, 0]),
bezier_patch_flat([s.y, s.z], N=1, orient=RIGHT, trans=[ h.x, 0, 0]),
bezier_patch_flat([s.y, s.z], N=1, orient=LEFT, trans=[-h.x, 0, 0]),
bezier_patch_flat([s.x, s.z], N=1, orient=ORIENT_Y, trans=[ 0, h.y, 0]),
bezier_patch_flat([s.x, s.z], N=1, orient=ORIENT_YNEG, trans=[ 0, -h.y, 0]),
bezier_patch_flat([s.x, s.z], N=1, orient=BACK, trans=[ 0, h.y, 0]),
bezier_patch_flat([s.x, s.z], N=1, orient=FRONT, trans=[ 0, -h.y, 0]),
bezier_patch_flat([s.x, s.y], N=1, orient=ORIENT_Z, trans=[ 0, 0, h.z]),
bezier_patch_flat([s.x, s.y], N=1, orient=ORIENT_ZNEG, trans=[ 0, 0, -h.z])
bezier_patch_flat([s.x, s.y], N=1, orient=UP, trans=[ 0, 0, h.z]),
bezier_patch_flat([s.x, s.y], N=1, orient=DOWN, trans=[ 0, 0, -h.z])
];
// Generating all the patches above took about 0.05 secs.
@@ -107,7 +108,7 @@ module CR_cube(size=[100,100,100], r=10, splinesteps=8, cheat=false)
}
CR_cube(size=[100,100,100], r=20, splinesteps=9, cheat=false);
CR_cube(size=[100,100,100], r=20, splinesteps=15, cheat=false);
cube(1);

View File

@@ -3,46 +3,60 @@ include <BOSL2/std.scad>
// Shows all the orientations on cubes in their correct rotations.
orientations = [
ORIENT_X, ORIENT_Y, ORIENT_Z,
ORIENT_XNEG, ORIENT_YNEG, ORIENT_ZNEG,
ORIENT_X_90, ORIENT_Y_90, ORIENT_Z_90,
ORIENT_XNEG_90, ORIENT_YNEG_90, ORIENT_ZNEG_90,
ORIENT_X_180, ORIENT_Y_180, ORIENT_Z_180,
ORIENT_XNEG_180, ORIENT_YNEG_180, ORIENT_ZNEG_180,
ORIENT_X_270, ORIENT_Y_270, ORIENT_Z_270,
ORIENT_XNEG_270, ORIENT_YNEG_270, ORIENT_ZNEG_270
RIGHT, BACK, UP,
LEFT, FWD, DOWN,
];
axiscolors = ["red", "forestgreen", "dodgerblue"];
axisdiam = 0.5;
axislen = 12;
axislbllen = 15;
axiscolors = ["red", "forestgreen", "dodgerblue"];
module orient_cube(ang) {
color("lightgray") cube(20, center=true);
color(axiscolors.x) up ((20-1)/2+0.01) back ((20-1)/2+0.01) cube([18,1,1], center=true);
color(axiscolors.y) up ((20-1)/2+0.01) right((20-1)/2+0.01) cube([1,18,1], center=true);
color(axiscolors.z) back((20-1)/2+0.01) right((20-1)/2+0.01) cube([1,1,18], center=true);
for (axis=[0:2], neg=[0:1]) {
idx = axis + 3*neg;
labels = [
"RIGHT", "BACK", "UP",
"LEFT", "FWD", "DOWN"
];
rot(ang, from=UP, to=orientations[idx]) {
up(10) {
back(4) color("black") text3d(text=str("spin=",ang), size=2.5);
fwd(2) color(axiscolors[axis]) text3d(text="orient=", size=2.5);
fwd(6) color(axiscolors[axis]) text3d(text=labels[idx], size=2.5);
}
}
}
}
module text3d(text, h=0.01, size=3) {
linear_extrude(height=h, convexity=10) {
text(text=text, size=size, valign="center", halign="center");
}
linear_extrude(height=h, convexity=10) {
text(text=text, size=size, valign="center", halign="center");
}
}
module dottedline(l, d) for(y = [0:d*3:l]) up(y) sphere(d=d);
module orient_cubes() {
// X axis
color(axiscolors[0]) {
yrot( 90) cylinder(h=axislen, d=axisdiam, center=false);
right(axislbllen) rot([90,0,0]) text3d(text="X+");
yrot(-90) dottedline(l=axislen, d=axisdiam);
left(axislbllen) rot([90,0,180]) text3d(text="X-");
}
// Y axis
color(axiscolors[1]) {
xrot(-90) cylinder(h=axislen, d=axisdiam, center=false);
back(axislbllen) rot([90,0,90]) text3d(text="Y+");
xrot( 90) dottedline(l=axislen, d=axisdiam);
fwd(axislbllen) rot([90,0,-90]) text3d(text="Y-");
}
// Z axis
color(axiscolors[2]) {
cylinder(h=axislen, d=axisdiam, center=false);
up(axislbllen) rot([0,-90,90+$vpr[2]]) text3d(text="Z+");
@@ -50,30 +64,15 @@ module orient_cubes() {
down(axislbllen) rot([0,90,-90+$vpr[2]]) text3d(text="Z-");
}
for (ang = [0:90:270]) {
translate(cylindrical_to_xyz(40, ang+90, 0)) {
color("lightgray") cube(20, center=true);
}
}
for (axis=[0:2], neg=[0:1], ang = [0:90:270]) {
idx = axis + 3*neg + 6*ang/90;
translate(cylindrical_to_xyz(40, ang+90, 0)) {
rotate(orientations[idx]) {
up(10) {
ydistribute(8) {
color("black") text3d(text=str(ang, "º"), size=5);
color(axiscolors[axis]) text3d(text=str(["X","Y","Z"][axis], ["+","-"][neg]), size=5);
}
}
}
off = rotate_points3d([40*BACK],ang)[0];
translate(off) {
orient_cube(ang);
}
}
}
//rotate(a=180, v=[1,1,0])
orient_cubes();