[OpenSCAD] extending MCAD with an example for rotation

mitch mtchkll at gmail.com
Wed Apr 8 22:10:02 EDT 2015


I made a variant of your code to create coordinate systems relative to one
another, drawing axes at each origin. Check it out below, maybe you will
find it useful, or be able to point to similar work.

Thanks,
Mitch

<http://forum.openscad.org/file/n12335/DemoLeg.demoleg> 
<http://forum.openscad.org/file/n12335/BranchingDemo.branchingdemo> 


//ex_leg();
ex_branching();

//example: multiple "branches"
module ex_branching(){
    v0=[0,0,0,0,0,0];
    v1=[10,-15,5,0,30,0];
    v2=[0,-40,15,0,160,0];
    v3=[30,30,30,0,0,45];
    
    axes(v1) {cube(4);
        axes(v1){
        axes(v3){
            translate([4,4,4]) sphere(4,center=true);
        }
            axes(v2){
                axes(v2);
                axes(v1){
                    difference(){
                        cube(10);
                        cube(10,center=true);
                    }
                }
            }
        };
    }
}


//example: leg
module ex_leg(){
    v0=[0,0,0,0,0,0];
    foot_width=6;foot_length=20;foot_height=4;
    joint_radius=3;
    leg_width=4;leg_length=60;
    a_ankle_x=10;
    a_ankle_y=0;
    a_ankle_z=0;
    a_knee_x=-15;
    a_knee_y=0;
    a_knee_z=0;
    thigh_length=40;
    thigh_width=6;
    
    
   
v_foot_leg=[foot_width/2,foot_length+joint_radius,foot_height/2,a_ankle_x,a_ankle_y,a_ankle_z];
    v_leg_thigh=[0,0,leg_length+2*joint_radius,a_knee_x,a_knee_y,a_knee_z];
    
    axes(v0){
        %cube([foot_width,foot_length,foot_height]);
        axes(v_foot_leg){
            sphere(joint_radius,center=true);
            translate([0,0,leg_length/2+joint_radius])
            %cube([leg_width,leg_width,leg_length],center=true);
            axes(v_leg_thigh){
                sphere(joint_radius,center=true);
                translate([0,0,thigh_length/2+joint_radius]) 
                %cube([thigh_width,thigh_width,thigh_length],center=true);
            
            }
        }
    }
}
    

//axes reference geometry
module axes(coords){
    
    //represent axes in a particular position and orientation.
    x=coords[0];
    y=coords[1];
    z=coords[2];
    rx=coords[3];
    ry=coords[4];
    rz=coords[5];
    h=10;
    w=1;
    length=sqrt(pow(x,2)+pow(y,2)+pow(z,2));
    echo(length);
    b=sqrt(pow(x,2)+pow(y,2));
 
    color([0,0,0,1]) rotate(atan2(y,x)) rotate([0,-atan2(z,norm([x,y])),0])
translate([length/2,0,0]) cube([length,.2,.2],center=true);
    translate([x,y,z]) rotate([rx,ry,rz]) {
        color([1,0,0,1]) translate([h/2,0,0]) cube([h,w,w],center=true);
        color([0,1,0,1]) translate([0,h/2,0]) cube([w,h,w],center=true);
        color([0,0,1,1]) translate([0,0,h/2]) cube([w,w,h],center=true);
        color([0,0,0,1]) cube(2*w,center=true);
    children();
    }
    
}






--
View this message in context: http://forum.openscad.org/extending-MCAD-with-an-example-for-rotation-tp12290p12335.html
Sent from the OpenSCAD mailing list archive at Nabble.com.




More information about the Discuss mailing list