3dgeometryopenscadcsg

OpenSCAD objects rotating around a circle


I have this code, which is supposed to make multiple fans which rotate around this circle, however I am unsure what went wrong. Pretty sure it's my bad math, haha.

This is what comes out of it:

1

I've tried multiple variations of this, but I still couldn't do it. Any tips or ideas? Everything is appreciated :)

module muzzle (device_color="dimgray"){

    // fan hole cylinder
    difference(){
        translate([48.15,0,1]) color(device_color) rotate([0,90,0]) cylinder(0.5,0.5,0.5, $fn=50);
        translate([47.9,0,1]) color(device_color) rotate([0,90,0]) cylinder(2,0.35,0.35, $fn=50);
    }
    for (a=[0:14]){
        y = (a<=7) ? 0.5 - a*(0.5/7) : 0.5 + (a-7)*(0.5/7);
        z = (y>=0) ? 0 - a*(0.9/7): -0.5 + (a-7)*(1.4/7);
        rot = 180 - a*(180/7);
        echo(a,y,z,rot);
        
        translate([48.15,y,z]) rotate([rot,0,0]) union(){
            translate([0, 0, 0]) color(device_color) rotate([40,0,0]) cube([0.4,0.05,1.75]);
            translate([0, -1.11, 1.35]) color(device_color) rotate([-20,0,0]) cube([0.4,0.05,0.75]);
        }
    }
        
}

Solution

  • It's hard to answer with an accurate answer, without knowing what you want to achieve exactly. But, yes, indeed, your math are wrong. Without even understanding what you are trying to do, there is no way that there is a linear relation between y and z and a, as your cryptic formulas implies (outside the threshold, which, also, are very unlikely to be what you want).

    Besides, you shouldn't have any math to do. The whole point of rotate is usually to avoid having to compute yourself those y and z from an angle

    Just draw one blade where ever you want, from axis (assuming it is then translated to wherever the center is), and then make it rotate around that axis

    Something like

    module muzzle (device_color="dimgray"){
        // fan hole cylinder
        difference(){
            translate([48.15,0,1]) color(device_color) rotate([0,90,0]) cylinder(0.5,0.5,0.5, $fn=50);
            translate([47.9,0,1]) color(device_color) rotate([0,90,0]) cylinder(2,0.35,0.35, $fn=50);
        }
        for (a=[0:14]){
            rot = 180 - a*(180/7);
            
            translate([48.15,0,1]) rotate([rot,0,0]) union(){
                translate([0, 0.5, 0]) color(device_color) rotate([40,0,0]) cube([0.4,0.05,1.75]);
                translate([0, -0.61, 1.35]) color(device_color) rotate([-20,0,0]) cube([0.4,0.05,0.75]);
            }
        }    
    }
    

    Not sure it is the result you want. It depends on where you intended the 7th blade to start from (the one with rotation 0°). But at least it gives something consistent enter image description here

    Maybe your intention was that the blades starts perpendicularly from the core cylinder.

    In which case lines

            translate([48.15,0,1]) rotate([rot,0,0]) union(){
                translate([0, 0.5, 0]) color(device_color) rotate([40,0,0]) cube([0.4,0.05,1.75]);
                translate([0, -0.61, 1.35]) color(device_color) rotate([-20,0,0]) cube([0.4,0.05,0.75]);
    

    should rather be

            translate([48.15,0,1]) rotate([rot,0,0]) translate([0,-0.3,0.3]) union(){
                translate([0, 0, 0]) color(device_color) rotate([40,0,0]) cube([0.4,0.05,1.75]);
                translate([0, -1.11, 1.35]) color(device_color) rotate([-20,0,0]) cube([0.4,0.05,0.75]);
    

    (Note that, in this last version, I used even more openscad transformation to have to do even less math: I start your blades from [0,0,0], hence the void translate([0,0,0]) that I let only for explicitation, but added a global (but before rotation — that is, after in the code, but before in order of transformation) translate([0,-0.3, 0.3]) to choose where the 7th blade starts from — and therefore where the other start from, after roation)

    So, you can play with this -0.3,0.3 to change the position of blades. With 0.5,0 you get the first image. With that -0.3,0.3 you get the next:

    enter image description here

    Bottom line is, don't try to do math to compute rotation and positions. Firstly, as you seem to admit, I you allow me to say it, you are not very good at it :D; and secondly, that is what rotate and translate are for: do the math to compute rotation and position for you.