I want to do a cylinder, which has holes on it(like in the inserted photo). I managed to do the holes, but I don't have any idea how to make them rotated, to look like on the photo.
Can you please help me? I ran out of ideas.
My code:
h=150;
r_cylinder=62.5;
r_hole1=2;
r_hole2=3;
r_hole3=4;
r_bighole=15;
distance=30;
n=24;
$fn=120;
difference()
{
cylinder(h, r_cylinder,r_cylinder,center=true);
cylinder(h+1,r_bighole,r_bighole,center=true);
for(i=[1:n])
{
translate([distance*cos(i*(360/n)),distance*sin(i*(360/n)),0])
circle(r_hole1);
translate([(distance+10)*cos(i*(360/(n))),(distance+10)*sin(i*(360/(n))),0]) cylinder(h+1,r_hole2,r_hole2,center=true);
translate([(distance+20)*cos(i*(360/(n))),(distance+20)*sin(i*(360/(n))),0]) cylinder(h+1,r_hole3,r_hole3,center=true);
}
}
Screenshot:

I am trying to get the holes like on the photo.
Well, using your logic and code (Once corrected: I've change the 1st series of holes from
circletocylindersince it was obviously your goal to have 3 ranks of holes), the only thing you have to do is to shift the angles.Since you have one hole every 360/24=15 degrees, just add 5 degrees to the angle of second holes, and 10 to the angle of 3rd.
Or, to avoid hard coding, and keep it as a formula of n, use
i*(360/n)as you did for angle of first rank holes,(i+1/3)*(360/n)for second, and(1+2/3)*(360/n)for third.That being said, rather than doing trigonometry yourself, and, avoid some code duplication, I would rather rely on
rotateto do that. Understand that rotates rotates around an axes that passes through the origin. So, it depends whether you rotate first and translate after, or translate first and translate after.For example
cube([1,1,1], center=true)is a cube at the originrotate([0,0,45]) cube([1,1,1])is, at the origin, a cube rotated around the origin (a losange from the top)So
translate([2,0,0]) rotate([0,0,45]) cube([1,1,1], center=True)is the same thing shiftedIf I do it the other way: `translate([2,0,0]) cube([1,1,1], center=true) is a cube away from the origin
So rotate([0,0,45]) is that last figure, rotated around the origin
So, that is the last construct I would rather use. Instead of digging a hole at position
[D*cos(α), D*sin(α), 0], I would dig it at position[D,0,0]and then rotate that shifted hole with angle α.Like this
is replaced by
Not only it is a bit shorter (especially when, like in your case, D and alpha are longer expressions, since the 1st version write them twice, while the second just once), but also it relies more on openscad for geometry, since, after all, it's its jobs. Plus, I think it makes it easier to think in terms of angles.
So
Or using double
forloopOr, last suggestion, you could create a
repeatInCirclemodifier. And also, use different distances for the 3 ranks (for now, the same distance separate holes of rank 1 and rank 2, than what separates rank 2 from rank 3. 10 each time. But since the diameter of the holes are bigger and bigger, it is probably better if distance is smaller at first and bigger then. As it is so in your example image. Like this