Welcome! Log In Create A New Profile

Advanced

[solved] thumbs up Wrong math?

Posted by o_lampe 
[solved] thumbs up Wrong math?
May 30, 2015 11:38AM
Hi guys,
I tried to rotate a cube 45° and translate it to the right position, but the result leaves a small gap I cannot explain.
See the #highlighted code at the end and the screenshot.

What´s wrong with my math?
-Olaf


union(){
    translate ([40,0,10])mirror([1,0,1]){ 
    translate ([0,0,10])difference(){
        cube([10,10,20]);
        translate([5,5,-0.001]) cylinder(h=20.002,r=3);
    }
    }
    translate ([0,40,10])mirror([0,1,1]){ 
    translate ([0,0,10])difference(){
        cube([10,10,20]);
        translate([5,5,-0.001]) cylinder(h=20.002,r=3);
    }
    }
    translate ([0,0,10])difference(){
        cube([10,10,20]);
        translate([5,5,-0.001]) cylinder(h=20.002,r=3);
    }
    
    //45° struts
    #translate([10*sin(45),0,10+5*sin(45)])rotate([0,45,0]) difference(){
            cube([10,10,20]);
            translate([5,5,-0.001]) cylinder(h=20.002,r=3);
        } 
    #translate([0,10*sin(45),10+5*sin(45)]) rotate([-45,0,0])difference(){
        cube([10,10,20]);
        translate([5,5,-0.001]) cylinder(h=20.002,r=3);
    } 
  cube(10);
}

Edited 1 time(s). Last edit at 06/01/2015 05:34AM by o_lampe.
Attachments:
open | download - 45-struts.JPG (43.8 KB)
Re: Wrong math?
May 30, 2015 07:49PM
Quote
o_lampe
Hi guys,
I tried to rotate a cube 45° and translate it to the right position, but the result leaves a small gap I cannot explain.
See the #highlighted code at the end and the screenshot.

What´s wrong with my math?
-Olaf


union(){
    translate ([40,0,10])mirror([1,0,1]){ 
    translate ([0,0,10])difference(){
        cube([10,10,20]);
        translate([5,5,-0.001]) cylinder(h=20.002,r=3);
    }
    }
    translate ([0,40,10])mirror([0,1,1]){ 
    translate ([0,0,10])difference(){
        cube([10,10,20]);
        translate([5,5,-0.001]) cylinder(h=20.002,r=3);
    }
    }
    translate ([0,0,10])difference(){
        cube([10,10,20]);
        translate([5,5,-0.001]) cylinder(h=20.002,r=3);
    }
    
    //45° struts
    #translate([10*sin(45),0,10+5*sin(45)])rotate([0,45,0]) difference(){
            cube([10,10,20]);
            translate([5,5,-0.001]) cylinder(h=20.002,r=3);
        } 
    #translate([0,10*sin(45),10+5*sin(45)]) rotate([-45,0,0])difference(){
        cube([10,10,20]);
        translate([5,5,-0.001]) cylinder(h=20.002,r=3);
    } 
  cube(10);
}  

for situations like that it's usually easier to position the cube from the centre and bottom of the cube like this:

cubeheight=20;
translate([0,0,cubeheight/2])cube([10,10,cubeheight]);


union(){
    translate ([40,0,10])mirror([1,0,1]){ 
    translate ([0,0,10])difference(){
        cube([10,10,20]);
        translate([5,5,-0.001]) cylinder(h=20.002,r=3);
    }
    }
    translate ([0,40,10])mirror([0,1,1]){ 
    translate ([0,0,10])difference(){
        cube([10,10,20]);
        translate([5,5,-0.001]) cylinder(h=20.002,r=3);
    }
    }
    translate ([0,0,10])difference(){
        cube([10,10,20]);
        translate([5,5,-0.001]) cylinder(h=20.002,r=3);
    }
    
    //45° struts
    difference(){
   translate([10,5,10])rotate([0,45,0])translate([0,0,10])cube([10,10,20],center = true);
   translate([10,5,10])rotate([0,45,0])cylinder(h=20.002,r=3);
    }
    
   difference(){
   #translate([5,10,10])rotate([0,45,90])translate([0,0,10])cube([10,10,20],center = true);
   translate([5,10,10])rotate([0,45,90])cylinder(h=20.002,r=3);
    }   
        
 
  cube(10);
}

hope you don't mind i modified the posted code to position the cubes and cylinder from the bottom centre of them , the above should do what you want it to




-=( blog )=- -=( thingiverse )=- -=( 3Dindustries )=- -=( Aluhotend - mostly metal hotend)=--=( Facebook )=-



Re: Wrong math?
May 30, 2015 07:54PM
is the depth of each hole important? looking inside the holes the bottoms won't be flat and the lower ones have the corners of the cubes sticking into them,




-=( blog )=- -=( thingiverse )=- -=( 3Dindustries )=- -=( Aluhotend - mostly metal hotend)=--=( Facebook )=-



Re: Wrong math?
May 31, 2015 03:01AM
To come back to your original question:

Quote
o_lampe
What´s wrong with my math?

Instead of 10*sin(45) it should be 10-5*cos(45).

Edited 1 time(s). Last edit at 06/01/2015 12:47AM by enif.
Re: Wrong math?
June 01, 2015 05:33AM
Thanks to all for the replies!

I tried the cos(45) variant and it totally makes sense. thumbs up

I will work through jolly´s version too, to understand the difference.

These corner parts were meant as a quick and dirty enclosure for my printer, but it took 4 hours to write these few lines...
I could have made them from marble in less time winking smiley
I´ll try to make that parametric , so the angles of the diagonal struts refer to the x/y/z lenght ratios.
-Olaf
Re: [solved] thumbs up Wrong math?
June 01, 2015 07:57AM
As "thejollygrimreaper" says, it is usually far easier to construct the part that you are going to rotate so that its origin is at the point of rotation, rotate and then translate to the place it will mate. It avoids having to figure out the trig equation to use. Making each part as a module also helps.

Dave
Re: [solved] thumbs up Wrong math?
June 01, 2015 03:44PM
I got it thumbs up

But what still puzzles me is the "rotation centerpoint" function [CTRL] + 3
I would expect it to go through [0,0,0], but it is "somewhere, out there"
And it is not related to the real rotation.

Is it only for the "camera"?
-Olaf
Re: [solved] thumbs up Wrong math?
June 01, 2015 06:17PM
Quote
o_lampe
I got it thumbs up

But what still puzzles me is the "rotation centerpoint" function [CTRL] + 3
I would expect it to go through [0,0,0], but it is "somewhere, out there"
And it is not related to the real rotation.

Is it only for the "camera"?
-Olaf

it's only for the camera , what it allows you to do is rotate the part around a different selectable point, to use it move the object with the right mouse button and line up your desire point witht he red lines then simple rotate the part with the left mouse button




-=( blog )=- -=( thingiverse )=- -=( 3Dindustries )=- -=( Aluhotend - mostly metal hotend)=--=( Facebook )=-



Sorry, only registered users may post in this forum.

Click here to login