OpenSCAD generated lens hood
OpenSCAD code to generate lens hood
//special variables control the number of facets used to generate an arc
$fa=1; // minimum angle for a fragment
$fs=0.05; //minimum size of a fragment
vbarreldim = 60; //[mm] Lens barrel size
vopticenter = 10; //[mm] how far optical lens center is from lens barrel; if in doubts add a few mm to be on safe side
vnegativex = 5*25.4; //[mm] negative/sensor size x*y
vnegativey = 4*25.4;
vfocal = 180; //[mm] focal length (at infinity)
vg = 1; //[mm] lens hood thickness
vslots = 0; //[mm] slots cut on mount end to make it more flexible
vcut = 0.8; //[mm] - one long slot cut to make hood more flexible
vsafety = 1.50; //1+ safety factor to make hood a little bit wider
//3d print tolerances
vintadd = 0.3; //tolerance to add on internal holes when no slots are used
// vnegativex*vsafety
difference() {
difference() {
cylinder(r=(vbarreldim/2)+vg, h=(vfocal-vopticenter));
if ( (vslots>0) || (vcut>0) ) cylinder(r=(vbarreldim/2), h=(vfocal-vopticenter)+2);
if ( (vslots==0) && (vcut==0) ) cylinder(r=(vbarreldim/2)+vintadd, h=(vfocal-vopticenter)+2);
}
/**/
translate([0,0,vfocal-vopticenter]) rotate([180,0,0])
#polyhedron(
points=[ [(vnegativex*vsafety)/2,(vnegativey*vsafety)/2,0],[(vnegativex*vsafety)/2,-((vnegativey*vsafety)/2),0],[-((vnegativex*vsafety)/2),-((vnegativey*vsafety)/2),0],[-((vnegativex*vsafety)/2),(vnegativey*vsafety)/2,0], // the four points at base
[0,0,vfocal] ], // the apex point
faces=[ [0,1,4],[1,2,4],[2,3,4],[3,0,4], // each triangle side
[1,0,3],[2,1,3] ] // two triangles for square base
);
if ( (vslots>0) && (vcut==0) ) #for (i=[0:10:350]) rotate(a=i, v=[0,0,1]) cube([1,vbarreldim+vg+10,vslots*2], center=true);
if ( (vcut>0) ) #cube([vcut,vbarreldim+vg+10,vfocal], center=false);
}
//special variables control the number of facets used to generate an arc
$fa=1; // minimum angle for a fragment
$fs=0.05; //minimum size of a fragment
vbarreldim = 60; //[mm] Lens barrel size
vopticenter = 10; //[mm] how far optical lens center is from lens barrel; if in doubts add a few mm to be on safe side
vnegativex = 5*25.4; //[mm] negative/sensor size x*y
vnegativey = 4*25.4;
vfocal = 180; //[mm] focal length (at infinity)
vg = 1; //[mm] lens hood thickness
vslots = 0; //[mm] slots cut on mount end to make it more flexible
vcut = 0.8; //[mm] - one long slot cut to make hood more flexible
vsafety = 1.50; //1+ safety factor to make hood a little bit wider
//3d print tolerances
vintadd = 0.3; //tolerance to add on internal holes when no slots are used
// vnegativex*vsafety
difference() {
difference() {
cylinder(r=(vbarreldim/2)+vg, h=(vfocal-vopticenter));
if ( (vslots>0) || (vcut>0) ) cylinder(r=(vbarreldim/2), h=(vfocal-vopticenter)+2);
if ( (vslots==0) && (vcut==0) ) cylinder(r=(vbarreldim/2)+vintadd, h=(vfocal-vopticenter)+2);
}
/**/
translate([0,0,vfocal-vopticenter]) rotate([180,0,0])
#polyhedron(
points=[ [(vnegativex*vsafety)/2,(vnegativey*vsafety)/2,0],[(vnegativex*vsafety)/2,-((vnegativey*vsafety)/2),0],[-((vnegativex*vsafety)/2),-((vnegativey*vsafety)/2),0],[-((vnegativex*vsafety)/2),(vnegativey*vsafety)/2,0], // the four points at base
[0,0,vfocal] ], // the apex point
faces=[ [0,1,4],[1,2,4],[2,3,4],[3,0,4], // each triangle side
[1,0,3],[2,1,3] ] // two triangles for square base
);
if ( (vslots>0) && (vcut==0) ) #for (i=[0:10:350]) rotate(a=i, v=[0,0,1]) cube([1,vbarreldim+vg+10,vslots*2], center=true);
if ( (vcut>0) ) #cube([vcut,vbarreldim+vg+10,vfocal], center=false);
}
Comments
Post a Comment