# [solved] Wrong math?

Posted by o_lampe
 [solved] Wrong math? May 30, 2015 11:38AM Registered: 7 years ago Posts: 5,232
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.
 Re: Wrong math? May 30, 2015 07:49PM Admin Registered: 10 years ago Posts: 1,063
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 Admin Registered: 10 years ago Posts: 1,063
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 Registered: 8 years ago Posts: 590
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 Registered: 7 years ago Posts: 5,232
Thanks to all for the replies!

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

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
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] Wrong math? June 01, 2015 07:57AM Registered: 8 years ago Posts: 2,472
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] Wrong math? June 01, 2015 03:44PM Registered: 7 years ago Posts: 5,232
I got it

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] Wrong math? June 01, 2015 06:17PM Admin Registered: 10 years ago Posts: 1,063
Quote
o_lampe
I got it

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.