

Me again  minor correction in the translation (note p1 from translate(vector/2 + p1) which was missing)
module cylinder_ep(p1, p2, r1, r2) {
translate(p1)sphere(r=r1,center=true);
translate(p2)sphere(r=r2,center=true);
assign(vector = [p2[0]  p1[0],p2[1]  p1[1],p2[2]  p1[2]])
assign(distance = sqrt(pow(vector[0], 2) +
pow(vector[1], 2) +
pow(vector[2], 2)))
translate(vector/2 + p1)
//rotation of XoY plane by the Z axis with the angle of the [p1 p2] line projection with the X axis on the XoY plane
rotate([0, 0, atan2(vector[1], vector[0])]) //rotation
//rotation of ZoX plane by the y axis with the angle given by the z coordinate and the sqrt(x^2 + y^2)) point in the XoY plane
rotate([0, atan2(sqrt(pow(vector[0], 2)+pow(vector[1], 2)),vector[2]), 0])
cylinder(h = distance, r1 = r1, r2 = r2,center=true);
}
cylinder_ep([0, 20, 30], [5, 10, 15], 2, 1, $fn=20);
Andrei


beautiful!
On Sat, Jan 28, 2012 at 7:51 AM, Pasca Andrei <[hidden email]> wrote:
Me again  minor correction in the translation (note p1 from translate(vector/2 + p1) which was missing)
module cylinder_ep(p1, p2, r1, r2) {
translate(p1)sphere(r=r1,center=true);
translate(p2)sphere(r=r2,center=true);
assign(vector = [p2[0]  p1[0],p2[1]  p1[1],p2[2]  p1[2]])
assign(distance = sqrt(pow(vector[0], 2) +
pow(vector[1], 2) +
pow(vector[2], 2)))
translate(vector/2 + p1)
//rotation of XoY plane by the Z axis with the angle of the [p1 p2] line projection with the X axis on the XoY plane
rotate([0, 0, atan2(vector[1], vector[0])]) //rotation
//rotation of ZoX plane by the y axis with the angle given by the z coordinate and the sqrt(x^2 + y^2)) point in the XoY plane
rotate([0, atan2(sqrt(pow(vector[0], 2)+pow(vector[1], 2)),vector[2]), 0])
cylinder(h = distance, r1 = r1, r2 = r2,center=true);
}
cylinder_ep([0, 20, 30], [5, 10, 15], 2, 1, $fn=20);
Andrei _______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad


That's great you figured out the math behind it, although with the rounded ends, a simpler solution emerges.
module cylinder_ep(p1, p2, r1, r2) {
hull() {
translate(p1)sphere(r=r1,center=true);
translate(p2)sphere(r=r2,center=true);
}
}
cylinder_ep([0, 0, 0], [6, 11, 15], 3, 1, $fn=20);
I guess the downside to this approach is that it takes a bit longer to render, but it removes the seems between the spheres and cylinders. On Fri, Jan 27, 2012 at 4:51 PM, Triffid Hunter <[hidden email]> wrote:
beautiful!
Me again  minor correction in the translation (note p1 from translate(vector/2 + p1) which was missing)
module cylinder_ep(p1, p2, r1, r2) {
translate(p1)sphere(r=r1,center=true);
translate(p2)sphere(r=r2,center=true);
assign(vector = [p2[0]  p1[0],p2[1]  p1[1],p2[2]  p1[2]])
assign(distance = sqrt(pow(vector[0], 2) +
pow(vector[1], 2) +
pow(vector[2], 2)))
translate(vector/2 + p1)
//rotation of XoY plane by the Z axis with the angle of the [p1 p2] line projection with the X axis on the XoY plane
rotate([0, 0, atan2(vector[1], vector[0])]) //rotation
//rotation of ZoX plane by the y axis with the angle given by the z coordinate and the sqrt(x^2 + y^2)) point in the XoY plane
rotate([0, atan2(sqrt(pow(vector[0], 2)+pow(vector[1], 2)),vector[2]), 0])
cylinder(h = distance, r1 = r1, r2 = r2,center=true);
}
cylinder_ep([0, 20, 30], [5, 10, 15], 2, 1, $fn=20);
Andrei _______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad


Hello
I'm quite busy with several other topics and OpenSCAD was the solution for one of the problems. I figured the solution in a break from the current topics  I need from time to time to exercise some other parts of my brain :P.
So instead of putting this on my stack and waiting about one year to push it forward... please feel free to submit it yourself. Anyway, the code was based on your sketches :P.
@Brad  the ideea was to be able to draw a cylinder between 2 arbitrary points. The spheres were there as placeholders for the ending points. But your solution gives me some ideas, as it can be used for offseting some convex polygons  maybe this could be quicker than computing the minkowski sum.
Andrei
beautiful!
please submit this to the MCAD project, http://github.com/elmom/MCAD and/or post on thingiverse
On Sat, Jan 28, 2012 at 7:51 AM, Pasca Andrei <[hidden email]> wrote:
Me again  minor correction in the translation (note p1 from translate(vector/2 + p1) which was missing)
module cylinder_ep(p1, p2, r1, r2) {
translate(p1)sphere(r=r1,center=true);
translate(p2)sphere(r=r2,center=true);
assign(vector = [p2[0]  p1[0],p2[1]  p1[1],p2[2]  p1[2]])
assign(distance = sqrt(pow(vector[0], 2) +
pow(vector[1], 2) +
pow(vector[2], 2)))
translate(vector/2 + p1)
//rotation of XoY plane by the Z axis with the angle of the [p1 p2] line projection with the X axis on the XoY plane
rotate([0, 0, atan2(vector[1], vector[0])]) //rotation
//rotation of ZoX plane by the y axis with the angle given by the z coordinate and the sqrt(x^2 + y^2)) point in the XoY plane
rotate([0, atan2(sqrt(pow(vector[0], 2)+pow(vector[1], 2)),vector[2]), 0])
cylinder(h = distance, r1 = r1, r2 = r2,center=true);
}
cylinder_ep([0, 20, 30], [5, 10, 15], 2, 1, $fn=20);
Andrei _______________________________________________ OpenSCAD mailing list [hidden email] http://rocklinux.net/mailman/listinfo/openscad


Pasca: Thank you so much! This is perfect!
My first test of it is below, and it looks great!
For the myriad of places that I need this, there are times the end spheres will
be helpful, times when they are not needed.
Brad: your hull() idea has merits as well. It will be an
interesting test to see which is computationally faster, the hull() or the
extra CSG required by the spheres.
$fn=64;
for(i=[0:5]){
color([.5,.5,.5])cylinder_ep([cos(i*6030)*10,
sin(i*6030)*10, 0], [cos(i*60+30)*10, sin(i*60+30)*10, 0], 1.5, 1.5);
color([0,0,0])translate([cos(i*6030)*10, sin(i*6030)*10,
0])sphere(r=3,center=true);
}
color([.5,.5,.5])cylinder_ep([8.66,5, 0], [8.66*2,10, 0],
1.5, 1.5);
color([0,0,0])translate([8.66*2,10,
0])sphere(r=3,center=true);
color([.5,.5,.5])cylinder_ep([8.66*2,10, 0], [8.66*3,5, 0],
1.5, 1.5);
color([0,0,0])translate([8.66*3,5, 0])sphere(r=3,center=true);
Me again
 minor correction in the translation (note p1 from translate(vector/2 + p1)
which was missing)
module
cylinder_ep(p1, p2, r1, r2) {
//translate(p1)sphere(r=r1,center=true);
//translate(p2)sphere(r=r2,center=true);
assign(vector
= [p2[0]  p1[0],p2[1]  p1[1],p2[2]  p1[2]])
assign(distance
= sqrt(pow(vector[0], 2) +
//rotation
of XoY plane by the Z axis with the angle of the [p1 p2] line projection with
the X axis on the XoY plane
rotate([0,
0, atan2(vector[1], vector[0])]) //rotation
//rotation
of ZoX plane by the y axis with the angle given by the z coordinate and the
sqrt(x^2 + y^2)) point in the XoY plane
rotate([0,
atan2(sqrt(pow(vector[0], 2)+pow(vector[1], 2)),vector[2]), 0])
cylinder(h
= distance, r1 = r1, r2 = r2,center=true);
cylinder_ep([0,
20, 30], [5, 10, 15], 2, 1, $fn=20);

