I'm trying to use Bresenham's algorithm in Openscad. I've broken things down bit by bit to see where things were going wrong. Looking at the output from Openscad, I see that the cos values are not correct for the values provided. Here is a list of values and cos(value) as displayed by Openscad.
ECHO: 0.628319, 0.99994
ECHO: 1.25664, 0.999759
ECHO: 1.88496, 0.999459
ECHO: 2.51327, 0.999038
ECHO: 3.14159, 0.998497
ECHO: 3.76991, 0.997836
ECHO: 4.39823, 0.997055
ECHO: 5.02655, 0.996154
ECHO: 5.65487, 0.995133
ECHO: 6.28319, 0.993993
This is generated by the code:
spots = 10;
difference(){
cylinder(r=50, h=10, center=true);
translate ([0,0,-10])cylinder(r=5, h=20);
for ( z = [1:10]) {
assign (step = z/spots)
assign (step2 = (2 * PI * step))
echo (step2, cos(abs(step2)));
}
}
cos() in openscad needs degrees, try:
//assign (step2 = (2 * PI * step))
assign(step2 = 360*step)