[WIP] add polyhedron-based catears
This commit is contained in:
parent
519a41c7a4
commit
58fe834489
3 changed files with 187 additions and 96 deletions
|
@ -25,7 +25,12 @@ module catear_v3(height, thickness, fractal=0, side_len=30, bend_factor=0.15, st
|
||||||
C = [-S*bf, S*sf*mn, 0] * R;
|
C = [-S*bf, S*sf*mn, 0] * R;
|
||||||
D = [-s , 0, 0];
|
D = [-s , 0, 0];
|
||||||
|
|
||||||
if (debug) translate([0, 0, height]) rotate(90) bezier_curve_debug([A, B, C, D]);
|
curve_vertices = bezier_curve_vertices([A, B, C, D], $fn);
|
||||||
|
if (debug) {
|
||||||
|
translate([0, 0, height]) rotate(90) bezier_curve_debug([A, B, C, D]);
|
||||||
|
echo("curve_vertices: ", curve_vertices);
|
||||||
|
}
|
||||||
|
rotate(90) render_curve(curve_vertices, width=thickness, height=height, chamfer=chamfer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -125,13 +130,14 @@ module catear_v1(height, thickness, fractal=0, side_len=30, bend_factor=0.15, st
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module catear_headband(debug=DEBUG, size=SIZE, height=HEIGHT, thickness=THICKNESS, part=PART, stretch_len=STRETCH_LEN, tip_len=TIP_LEN, tip_bend=TIP_BEND, ear_scale=1.5, ear_bend_factor=0.15, ear_stretch_factor=1.2, ear_angle=42, chamfer=CHAMFER, chamfer_shape=CHAMFER_SHAPE, with_rake=true, details=true, ear_skew=2.0) {
|
module catear_headband(debug=DEBUG, size=SIZE, height=HEIGHT, thickness=THICKNESS, part=PART, stretch_len=STRETCH_LEN, tip_len=TIP_LEN, tip_bend=TIP_BEND, ear_scale=1.5, ear_bend_factor=0.15, ear_stretch_factor=1.2, ear_angle=42, chamfer=CHAMFER, chamfer_shape=CHAMFER_SHAPE, with_rake=true, details=true, ear_skew=2.0, ear_version=3) {
|
||||||
|
|
||||||
$a=size/2*ear_scale;
|
$a=size/2*ear_scale;
|
||||||
$delta=2*(acos($a/(size*2))-90);
|
$delta=2*(acos($a/(size*2))-90);
|
||||||
ear_offset=size*sin(90-$delta/2);
|
ear_offset=size*sin(90-$delta/2);
|
||||||
|
|
||||||
union() {
|
union() {
|
||||||
|
if (ear_version == 3 ) {
|
||||||
rotate( ear_angle, [0, 0, 1]) {
|
rotate( ear_angle, [0, 0, 1]) {
|
||||||
translate([-ear_offset, 0, 0]) catear_v3(
|
translate([-ear_offset, 0, 0]) catear_v3(
|
||||||
debug=debug,
|
debug=debug,
|
||||||
|
@ -146,34 +152,6 @@ module catear_headband(debug=DEBUG, size=SIZE, height=HEIGHT, thickness=THICKNES
|
||||||
skew=ear_skew
|
skew=ear_skew
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
rotate( ear_angle, [0, 0, 1]) {
|
|
||||||
translate([-ear_offset, 0, -2*height]) catear_v2(
|
|
||||||
debug=debug,
|
|
||||||
height=height,
|
|
||||||
thickness=thickness,
|
|
||||||
side_len=size/2*ear_scale,
|
|
||||||
bend_factor=ear_bend_factor,
|
|
||||||
stretch_factor=ear_stretch_factor,
|
|
||||||
chamfer=chamfer,
|
|
||||||
chamfer_shape=chamfer_shape,
|
|
||||||
details=details,
|
|
||||||
skew=ear_skew
|
|
||||||
);
|
|
||||||
}
|
|
||||||
rotate( ear_angle, [0, 0, 1]) {
|
|
||||||
translate([-ear_offset, 0, -height]) catear_v1(
|
|
||||||
debug=debug,
|
|
||||||
height=height,
|
|
||||||
thickness=thickness,
|
|
||||||
side_len=size/2*ear_scale,
|
|
||||||
bend_factor=ear_bend_factor,
|
|
||||||
stretch_factor=ear_stretch_factor,
|
|
||||||
chamfer=chamfer,
|
|
||||||
chamfer_shape=chamfer_shape,
|
|
||||||
details=details,
|
|
||||||
skew=ear_skew
|
|
||||||
);
|
|
||||||
}
|
|
||||||
rotate(-ear_angle, [0, 0, 1]) {
|
rotate(-ear_angle, [0, 0, 1]) {
|
||||||
translate([-ear_offset, 0, 0]) catear_v3(
|
translate([-ear_offset, 0, 0]) catear_v3(
|
||||||
debug=false,
|
debug=false,
|
||||||
|
@ -188,8 +166,24 @@ module catear_headband(debug=DEBUG, size=SIZE, height=HEIGHT, thickness=THICKNES
|
||||||
skew=-ear_skew
|
skew=-ear_skew
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (ear_version == 2 ) {
|
||||||
|
rotate( ear_angle, [0, 0, 1]) {
|
||||||
|
translate([-ear_offset, 0, 0]) catear_v2(
|
||||||
|
debug=debug,
|
||||||
|
height=height,
|
||||||
|
thickness=thickness,
|
||||||
|
side_len=size/2*ear_scale,
|
||||||
|
bend_factor=ear_bend_factor,
|
||||||
|
stretch_factor=ear_stretch_factor,
|
||||||
|
chamfer=chamfer,
|
||||||
|
chamfer_shape=chamfer_shape,
|
||||||
|
details=details,
|
||||||
|
skew=ear_skew
|
||||||
|
);
|
||||||
|
}
|
||||||
rotate(-ear_angle, [0, 0, 1]) {
|
rotate(-ear_angle, [0, 0, 1]) {
|
||||||
translate([-ear_offset, 0, -2*height]) catear_v2(
|
translate([-ear_offset, 0, 0]) catear_v2(
|
||||||
debug=false,
|
debug=false,
|
||||||
height=height,
|
height=height,
|
||||||
thickness=thickness,
|
thickness=thickness,
|
||||||
|
@ -202,8 +196,24 @@ module catear_headband(debug=DEBUG, size=SIZE, height=HEIGHT, thickness=THICKNES
|
||||||
skew=-ear_skew
|
skew=-ear_skew
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (ear_version == 1 ) {
|
||||||
|
rotate( ear_angle, [0, 0, 1]) {
|
||||||
|
translate([-ear_offset, 0, 0]) catear_v1(
|
||||||
|
debug=debug,
|
||||||
|
height=height,
|
||||||
|
thickness=thickness,
|
||||||
|
side_len=size/2*ear_scale,
|
||||||
|
bend_factor=ear_bend_factor,
|
||||||
|
stretch_factor=ear_stretch_factor,
|
||||||
|
chamfer=chamfer,
|
||||||
|
chamfer_shape=chamfer_shape,
|
||||||
|
details=details,
|
||||||
|
skew=ear_skew
|
||||||
|
);
|
||||||
|
}
|
||||||
rotate(-ear_angle, [0, 0, 1]) {
|
rotate(-ear_angle, [0, 0, 1]) {
|
||||||
translate([-ear_offset, 0, -height]) catear_v1(
|
translate([-ear_offset, 0, 0]) catear_v1(
|
||||||
debug=false,
|
debug=false,
|
||||||
height=height,
|
height=height,
|
||||||
thickness=thickness,
|
thickness=thickness,
|
||||||
|
@ -216,6 +226,7 @@ module catear_headband(debug=DEBUG, size=SIZE, height=HEIGHT, thickness=THICKNES
|
||||||
skew=-ear_skew
|
skew=-ear_skew
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
headband(
|
headband(
|
||||||
size=size,
|
size=size,
|
||||||
height=height,
|
height=height,
|
||||||
|
@ -230,4 +241,4 @@ module catear_headband(debug=DEBUG, size=SIZE, height=HEIGHT, thickness=THICKNES
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
rotate(-90) catear_headband(ear_bend_factor=0.15, ear_skew=2, debug=true);
|
rotate(-90) catear_headband(ear_bend_factor=0.15, ear_skew=2, ear_version=3);
|
||||||
|
|
|
@ -50,9 +50,21 @@ g = function (p) [scalc(xremap, p.x, -S/2, S/2), scalc(yremap, p.y, 0, S/2)*e, p
|
||||||
|
|
||||||
rotate([0, 90, 0]) color("yellow") arc(0.5, r, THICKNESS, HEIGHT, outer_remap=f, inner_remap=g);
|
rotate([0, 90, 0]) color("yellow") arc(0.5, r, THICKNESS, HEIGHT, outer_remap=f, inner_remap=g);
|
||||||
|
|
||||||
color("red") catear_v2(HEIGHT, THICKNESS, side_len=SIZE/2*EAR_SCALE, stretch_factor=EAR_STRETCH_FACTOR);
|
color("red") catear_v2(
|
||||||
|
height=HEIGHT,
|
||||||
|
thickness=THICKNESS,
|
||||||
|
side_len=SIZE/2*EAR_SCALE,
|
||||||
|
stretch_factor=EAR_STRETCH_FACTOR
|
||||||
|
);
|
||||||
|
|
||||||
// a = b + c
|
// a = b + c
|
||||||
// x * a = y * b + c
|
// x * a = y * b + c
|
||||||
// y / x = a /(b + c)
|
// y * b = x * a - c
|
||||||
// y = x * a /(b + c)
|
// y =(x * a - c)/ b
|
||||||
|
|
||||||
|
// 100 = 95 + 5
|
||||||
|
// x * 100 = y * 95 + 5
|
||||||
|
// 5 * 100 = y * 95 + 5
|
||||||
|
// 500 = y * 95 + 5
|
||||||
|
// 495 = y * 95
|
||||||
|
// y = 495 / 95
|
||||||
|
|
|
@ -33,23 +33,91 @@ module bezier_curve_debug(control_points, $fn=$fn) {
|
||||||
color("green") translate(bezier_spline(control_points, 0.5)) sphere(d=1, $fn=24);
|
color("green") translate(bezier_spline(control_points, 0.5)) sphere(d=1, $fn=24);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// c^2=a^2+b^2 // a == b
|
||||||
|
// c^2=2a^2 // /2
|
||||||
|
// c^2/2=a^2 // sqrt
|
||||||
|
// sqrt(c^2/2)=a
|
||||||
|
chamfer_offset = function (c) sqrt((c*c)/2);
|
||||||
|
|
||||||
|
rendered_curve_segment_vertices = function (p, v, n, width, height, chamfer)
|
||||||
|
let (d=normalize(n-p)) let (up=[0, 0, 1]) let (right=normalize(cross(d, up))) [
|
||||||
|
//p, v, n, width, height, chamfer_offset(chamfer), d, up, right,
|
||||||
|
v+up*(height/2)+right*(-width/2+chamfer_offset(chamfer)),
|
||||||
|
v+up*(height/2)+right*(width/2-chamfer_offset(chamfer)),
|
||||||
|
v+up*(height/2-chamfer_offset(chamfer))+right*(width/2),
|
||||||
|
v+up*(-height/2+chamfer_offset(chamfer))+right*(width/2),
|
||||||
|
v+up*(-height/2)+right*(width/2-chamfer_offset(chamfer)),
|
||||||
|
v+up*(-height/2)+right*(-width/2+chamfer_offset(chamfer)),
|
||||||
|
v+up*(-height/2+chamfer_offset(chamfer))+right*(-width/2),
|
||||||
|
v+up*(height/2-chamfer_offset(chamfer))+right*(-width/2)
|
||||||
|
];
|
||||||
|
|
||||||
rendered_curve_segment_vertices = function (p, v, n, width, height, chamfer) [];
|
module render_curve(curve_vertices, width, height, chamfer, debug=false) {
|
||||||
|
/*
|
||||||
|
* vertex generation order:
|
||||||
|
* - we generate vertices segment by segment
|
||||||
|
* - one segement for every curve vertex provided
|
||||||
|
* - each segment has eight vertices that form the outer ring
|
||||||
|
* - the corners are chamfered so the vertices are pairs at the corners
|
||||||
|
* - we start with the top segment and move clockwise
|
||||||
|
* - top-down axis is determined globally by z-axis unless direction at start vertex is z
|
||||||
|
* - if direction at start vertes is z, top-down is y-adis instead
|
||||||
|
* - the left vertex of the top edge is 0, the other is 1
|
||||||
|
* - left-right axis is determined by normal between travel direction and up-down axis
|
||||||
|
* - the last vertex is part of the same corner as 0 but part of the left edge
|
||||||
|
* - segment edge n has vertices `n` and `(n+1)%8`
|
||||||
|
* - segment joining edge n has vertices local index `n` of both segments
|
||||||
|
* - global `i` index of local index `n` for segment `m` is `i=8*m+n`
|
||||||
|
* - so we have `count=length(curve_vertices)` segments and `count*8` vertices
|
||||||
|
* - we are not generating a thorus so the faces for our polyhedron are:
|
||||||
|
* - two eight sided end cap faces
|
||||||
|
* - `(count-1)*8` four sided mantle faces
|
||||||
|
* - direction at vertex is the vector from the previonus to the next vertex
|
||||||
|
* - for the first an last vertex the only neighbor is mirrored around the vertex
|
||||||
|
* - the start end cap is face `0`
|
||||||
|
* - the face mantle face n has vertices `[n, +(n+1)%8, n+8, n+8+(n+1)%8]`
|
||||||
|
* - the stop end cap is face `count*8`
|
||||||
|
*/
|
||||||
|
|
||||||
module render_curve(curve_vertices, width, height, chamfer) {
|
start = let(v=curve_vertices[0], n=curve_vertices[1]) let(p=v+(v-n))
|
||||||
start = let(v=curve_vertices[0], n=curve_vertices[1]) let(p=v-n)
|
|
||||||
rendered_curve_segment_vertices(p, v, n, width, height, chamfer);
|
rendered_curve_segment_vertices(p, v, n, width, height, chamfer);
|
||||||
|
echo("len(curve_vertices): ", len(curve_vertices));
|
||||||
middle = [ for (i=[1:len(curve_vertices)-2]) let(
|
middle = [ for (i=[1:len(curve_vertices)-2]) let(
|
||||||
p = curve_vertives[i-1],
|
p = curve_vertices[i-1],
|
||||||
v = curve_vertices[i],
|
v = curve_vertices[i],
|
||||||
n = curve_vertives[i+1]
|
n = curve_vertices[i+1]
|
||||||
) rendered_curve_segment_vertices(p, v, n, width, height, chamfer)
|
) each rendered_curve_segment_vertices(p, v, n, width, height, chamfer)
|
||||||
];
|
];
|
||||||
end = let(i=len(curve_vertices)) let(v=curve_vertices[i], p=curve_vertices[i-1]) let(n=v-p)
|
echo("len(middle): ", len(middle));
|
||||||
|
stop = let(i=len(curve_vertices))
|
||||||
|
let(v=curve_vertices[i-1], p=curve_vertices[i-2]) let(n=v+(v-p))
|
||||||
rendered_curve_segment_vertices(p, v, n, width, height, chamfer);
|
rendered_curve_segment_vertices(p, v, n, width, height, chamfer);
|
||||||
|
|
||||||
// TODO
|
if (debug) {
|
||||||
|
echo(start);
|
||||||
|
color("#ff00ff") for (v = start) translate(v+[0, 0, height]) sphere(d=.25, $fn=16);
|
||||||
|
echo(middle);
|
||||||
|
color("white") for (v = middle) translate(v+[0, 0, height]) sphere(d=.25, $fn=16);
|
||||||
|
echo(stop);
|
||||||
|
color("cyan") for (v = stop) translate(v+[0, 0, height]) sphere(d=.25, $fn=16);
|
||||||
|
}
|
||||||
|
|
||||||
|
render_vertices = concat(start, middle, stop);
|
||||||
|
echo("len(render_vertices)", len(render_vertices));
|
||||||
|
echo(render_vertices);
|
||||||
|
|
||||||
|
start_cap = [ for (i=[0:1:7]) i];
|
||||||
|
echo(start_cap);
|
||||||
|
mantle = let (M=len(curve_vertices)-1) [ for (m=[0:M-1],n=[0:7]) let (i=m*8+n)
|
||||||
|
[i, i+8, n==7 ? i+1 : i+8+1, n==7 ? i-7 : i+1]
|
||||||
|
];
|
||||||
|
echo(mantle);
|
||||||
|
end_cap = let (m=len(curve_vertices)-1) [ for (i=[m*8+7:-1:m*8]) i ];
|
||||||
|
echo(end_cap);
|
||||||
|
|
||||||
|
faces = concat([start_cap], mantle, [end_cap]);
|
||||||
|
|
||||||
|
translate([0, 0, debug ? height : 0]) polyhedron(points=render_vertices, faces=faces);
|
||||||
}
|
}
|
||||||
|
|
||||||
arc_vertex = function (a, r, t, translate=[0,0,0], remap=id) remap([
|
arc_vertex = function (a, r, t, translate=[0,0,0], remap=id) remap([
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue