256 lines
8.3 KiB
OpenSCAD
256 lines
8.3 KiB
OpenSCAD
include <globals.scad>;
|
|
include <primitives.scad>;
|
|
|
|
use <headband.scad>;
|
|
use <chamfer.scad>;
|
|
|
|
EAR_VERSION = 3;
|
|
EAR_SKEW = 0.6;
|
|
EAR_SCALE = 1.4;
|
|
EAR_BEND_FACTOR = 0.04;
|
|
EAR_STRETCH_FACTOR = 1.2;
|
|
EAR_ANGLE = 42;
|
|
WITH_RAKE = true;
|
|
DETAILS = true;
|
|
|
|
catear_v3_control_points = function (S, sf, bf, mn, a) let (s=S/2, R=rotation_matrix(a)) [
|
|
[ s , 0, 0],
|
|
[ S*bf, S*sf*mn, 0] * R,
|
|
[-S*bf, S*sf*mn, 0] * R,
|
|
[-s , 0, 0],
|
|
];
|
|
|
|
/**
|
|
* unsupported parameters: chamfer, chamfer_shape, details, end_caps
|
|
*/
|
|
module catear_v3(height, thickness, fractal=0, side_len=30, bend_factor=0.15, stretch_factor=1.2, debug=false, chamfer=CHAMFER, chamfer_shape=CHAMFER_SHAPE, details=true, end_caps=true, skew=2.0, $fn=$fn) {
|
|
control_points = catear_v3_control_points(
|
|
S=side_len,
|
|
sf=stretch_factor,
|
|
bf=bend_factor,
|
|
mn=1.16,
|
|
a=skew*10
|
|
);
|
|
curve_vertices = bezier_curve_vertices(control_points, $fn);
|
|
if (debug) {
|
|
translate([0, 0, 2*height]) rotate(90) bezier_curve_debug(control_points);
|
|
echo("curve_vertices: ", curve_vertices);
|
|
}
|
|
rotate(90) render_curve(
|
|
curve_vertices,
|
|
width=thickness,
|
|
height=height,
|
|
chamfer=chamfer,
|
|
debug=debug
|
|
);
|
|
}
|
|
|
|
/**
|
|
* unsupported parameters: debug, chamfer, chamfer_shape, details, end_caps
|
|
*/
|
|
module catear_v2(height, thickness, fractal=0, side_len=30, bend_factor=0.15, stretch_factor=1.2, debug=false, chamfer=CHAMFER, chamfer_shape=CHAMFER_SHAPE, details=true, end_caps=true, skew=2.0) {
|
|
r=side_len/2;
|
|
T=side_len+thickness;
|
|
S=side_len-thickness;
|
|
x_stretch = function (x) pow(x, abs(skew));
|
|
y_stretch = function (y) pow(y, 2.0);
|
|
E=1.6*stretch_factor;
|
|
a=y_stretch(r)+thickness/2;
|
|
b=y_stretch(r)-thickness/2;
|
|
e=(E*a-thickness)/b;
|
|
echo("E",E,"e",e, "a", a, "b", b, "c", thickness);
|
|
outer_remap = function (p) [scalc(x_stretch, p.x, T/2, -T/2)*sign(skew), scalc(y_stretch, p.y, 0, T/2)*E, p.z];
|
|
inner_remap = function (p) [scalc(x_stretch, p.x, S/2, -S/2)*sign(skew), scalc(y_stretch, p.y, 0, T/2)*e, p.z];
|
|
or = function (p) [p.x, 2*p.y, p.z];
|
|
|
|
arc(0.5, r, thickness, height, outer_remap=outer_remap, inner_remap=inner_remap);
|
|
}
|
|
|
|
/**
|
|
* unsupported parameters: skew
|
|
*/
|
|
module catear_v1(height, thickness, fractal=0, side_len=30, bend_factor=0.15, stretch_factor=1.2, debug=false, chamfer=CHAMFER, chamfer_shape=CHAMFER_SHAPE, details=true, end_caps=true, skew=2.0) {
|
|
$A=[0, side_len/2];
|
|
$B=[0,-side_len/2];
|
|
$C=[-(side_len/2/sin(120))*1.5*stretch_factor, 0];
|
|
$c=sqrt(pow($A.x-$B.x, 2)+pow($A.y-$B.y, 2));
|
|
$b=sqrt(pow($A.x-$C.x, 2)+pow($A.y-$C.y, 2));
|
|
$a=sqrt(pow($C.x-$B.x, 2)+pow($C.y-$B.y, 2));
|
|
$hc=-$C.x;
|
|
$alpha=asin($hc/$b);
|
|
$beta=$alpha;
|
|
$gamma=180-$alpha-$beta;
|
|
$delta=180*bend_factor;
|
|
$bend_radius=$a/(2*cos(90-$delta/2));
|
|
$bend_offset=$bend_radius*sin(90-$delta/2);
|
|
|
|
translate([0, -$c/2, 0])
|
|
rotate($beta, [0, 0, 1])
|
|
translate([0, $a/2, 0])
|
|
translate([$bend_offset, 0, 0])
|
|
color("#00ffff")
|
|
chamfer(size=(details)?chamfer:0, child_h=height, child_bot=-height/2, shape=chamfer_shape)
|
|
partial_ring(
|
|
part=$delta/360,
|
|
radius=$bend_radius,
|
|
thickness=thickness,
|
|
height=height
|
|
);
|
|
translate([0, $c/2, 0])
|
|
rotate(-$alpha, [0, 0, 1])
|
|
translate([0, -$b/2, 0])
|
|
translate([$bend_offset, 0, 0])
|
|
color("#ff00ff")
|
|
chamfer(size=(details)?chamfer:0, child_h=height, child_bot=-height/2, shape=chamfer_shape)
|
|
partial_ring(
|
|
part=$delta/360,
|
|
radius=$bend_radius,
|
|
thickness=thickness,
|
|
height=height
|
|
);
|
|
if (end_caps) {
|
|
translate($A) color("#aaaaaa")
|
|
chamfer(size=chamfer, child_h=height, child_bot=-height/2, shape=chamfer_shape)
|
|
cylinder(h=height, d=thickness, center=true);
|
|
translate($B) color("#bbbbbb")
|
|
chamfer(size=chamfer, child_h=height, child_bot=-height/2, shape=chamfer_shape)
|
|
cylinder(h=height, d=thickness, center=true);
|
|
translate($C) color("#cccccc")
|
|
chamfer(size=chamfer, child_h=height, child_bot=-height/2, shape=chamfer_shape)
|
|
cylinder(h=height, d=thickness, center=true);
|
|
}
|
|
|
|
if (debug) {
|
|
echo("A", $A, "a", $a, "alpha", $alpha);
|
|
echo("B", $B, "b", $b, "beta ", $beta);
|
|
echo("C", $C, "c", $c, "gamma", $gamma);
|
|
echo("bend_factor", bend_factor);
|
|
echo("delta:", $delta);
|
|
echo("bend_radius", $bend_radius);
|
|
echo("bend_offset", $bend_offset);
|
|
color("#000000") cylinder(h=4, d=4);
|
|
translate($C/2) color("red") cube([$hc, thickness, height*1.1], center=true);
|
|
color("red") cube([thickness, $c, height*1.1], center=true);
|
|
color("red") translate([0, $c/2, 0])
|
|
rotate(-$alpha, [0, 0, 1])
|
|
translate([0, -$b/2, 0])
|
|
cube([thickness,$b, height*1.1], center=true);
|
|
color("red") translate([0, -$c/2, 0])
|
|
rotate($beta, [0, 0, 1])
|
|
translate([0, $a/2, 0])
|
|
cube([thickness, $a, height*1.1], center=true);
|
|
}
|
|
}
|
|
|
|
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=EAR_SCALE, ear_bend_factor=EAR_BEND_FACTOR, ear_stretch_factor=EAR_STRETCH_FACTOR, ear_angle=EAR_ANGLE, chamfer=CHAMFER, chamfer_shape=CHAMFER_SHAPE, with_rake=WITH_RAKE, details=DETAILS, ear_skew=EAR_SKEW, ear_version=EAR_VERSION) {
|
|
|
|
$a=size/2*ear_scale;
|
|
$delta=2*(acos($a/(size*2))-90);
|
|
ear_offset=size*sin(90-$delta/2);
|
|
|
|
union() {
|
|
if (ear_version == 3 ) {
|
|
rotate( ear_angle, [0, 0, 1]) {
|
|
translate([-ear_offset, 0, 0]) catear_v3(
|
|
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, 0]) catear_v3(
|
|
debug=false,
|
|
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
|
|
);
|
|
}
|
|
}
|
|
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]) {
|
|
translate([-ear_offset, 0, 0]) catear_v2(
|
|
debug=false,
|
|
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
|
|
);
|
|
}
|
|
}
|
|
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]) {
|
|
translate([-ear_offset, 0, 0]) catear_v1(
|
|
debug=false,
|
|
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
|
|
);
|
|
}
|
|
}
|
|
headband(
|
|
size=size,
|
|
height=height,
|
|
thickness=thickness,
|
|
part=part,
|
|
stretch_len=stretch_len,
|
|
tip_len=tip_len,
|
|
tip_bend=tip_bend,
|
|
with_rake=with_rake,
|
|
details=details
|
|
);
|
|
};
|
|
}
|
|
|
|
rotate(-90) catear_headband();
|