discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

3D Rotation to the point

A
anp
Tue, Feb 17, 2015 4:11 PM

// I have a massive of points, like this:
POINTS =
[[20.000000,5.000000,15.000000],[20.000000,5.000000,25.000000],[25.000000,0.000000,15.000000],[25.000000,0.000000,25.000000],[25.000000,15.000000,-15.000000],[-15.000000,15.000000,-15.000000],[25.000000,15.000000,-25.000000],[0.000000,15.000000,-25.000000],[25.000000,25.000000,25.000000]]

// And I need to create cylinders (with constant radius) between each pair
of points like POINTS[i] and POINTS[i+1]
// So I can set radius, calculate vector coordinates
[0,0,0],[x(i),y(i),z(i)] , and it's height h(i):

RADIUS = 0.5;
function x(i) = POINTS[i+1][0]-POINTS[i][0];
function y(i) = POINTS[i+1][1]-POINTS[i][1];
function z(i) = POINTS[i+1][2]-POINTS[i][2];
function h(i) = sqrt(pow(x(i),2)+pow(y(i),2)+pow(z(i),2));

// Then the question is, how do I calculate the needed rotations and
translations to make the cylinder(h(i),RADIUS) start at POINTS[i] and end at
POINTS[i+1] ?
// I found the information about rotations here:
http://stackoverflow.com/questions/1251828/calculate-rotations-to-look-at-a-3d-point
and tried to make it work in OpenSCAD but didn't succeed.
// Here's the bad code:

//function rotx(i) = atan2(z(i),y(i));
//function rotz(i) = atan2((x(i)*cos(rotx(i))), y(i) );
//function rotz2(i) = -atan2((x(i)*cos(rotx(i))), y(i) );
//function roty(i) = atan2( cos(rotx(i)), sin(rotx(i))*sin(rotz(i)))

//for( i = [0:7]) {
// if (z(i)>=0) {
//rotate([rotx(i),roty(i),rotz(i)]
//translate(POINTS[i])
//cylinder(h=h(i),r=RADIUS);
//}
//else {
//rotate([rotx(i),roty2(i),rotz(i)]
//translate(POINTS[i])
//cylinder(h=h(i),r=RADIUS);
//}
//}

// How do I make this work? Help me, please!

--
View this message in context: http://forum.openscad.org/3D-Rotation-to-the-point-tp11651.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

// I have a massive of points, like this: POINTS = [[20.000000,5.000000,15.000000],[20.000000,5.000000,25.000000],[25.000000,0.000000,15.000000],[25.000000,0.000000,25.000000],[25.000000,15.000000,-15.000000],[-15.000000,15.000000,-15.000000],[25.000000,15.000000,-25.000000],[0.000000,15.000000,-25.000000],[25.000000,25.000000,25.000000]] // And I need to create cylinders (with constant radius) between each pair of points like POINTS[i] and POINTS[i+1] // So I can set radius, calculate vector coordinates [0,0,0],[x(i),y(i),z(i)] , and it's height h(i): RADIUS = 0.5; function x(i) = POINTS[i+1][0]-POINTS[i][0]; function y(i) = POINTS[i+1][1]-POINTS[i][1]; function z(i) = POINTS[i+1][2]-POINTS[i][2]; function h(i) = sqrt(pow(x(i),2)+pow(y(i),2)+pow(z(i),2)); // Then the question is, how do I calculate the needed rotations and translations to make the cylinder(h(i),RADIUS) start at POINTS[i] and end at POINTS[i+1] ? // I found the information about rotations here: http://stackoverflow.com/questions/1251828/calculate-rotations-to-look-at-a-3d-point and tried to make it work in OpenSCAD but didn't succeed. // Here's the bad code: //function rotx(i) = atan2(z(i),y(i)); //function rotz(i) = atan2((x(i)*cos(rotx(i))), y(i) ); //function rotz2(i) = -atan2((x(i)*cos(rotx(i))), y(i) ); //function roty(i) = atan2( cos(rotx(i)), sin(rotx(i))*sin(rotz(i))) //for( i = [0:7]) { // if (z(i)>=0) { //rotate([rotx(i),roty(i),rotz(i)] //translate(POINTS[i]) //cylinder(h=h(i),r=RADIUS); //} //else { //rotate([rotx(i),roty2(i),rotz(i)] //translate(POINTS[i]) //cylinder(h=h(i),r=RADIUS); //} //} // How do I make this work? Help me, please! -- View this message in context: http://forum.openscad.org/3D-Rotation-to-the-point-tp11651.html Sent from the OpenSCAD mailing list archive at Nabble.com.
NH
nop head
Tue, Feb 17, 2015 4:31 PM

Note you only need two rotations to point a cylinder to a point. So just
rotx and rotz should do it but you need to do them in the right order.

A much simpler way is to place spheres at your two points and take the hull
to make a cylinder that joins them with nice rounded joints.

On 17 February 2015 at 16:11, anp me@anp.me wrote:

// I have a massive of points, like this:
POINTS =

[[20.000000,5.000000,15.000000],[20.000000,5.000000,25.000000],[25.000000,0.000000,15.000000],[25.000000,0.000000,25.000000],[25.000000,15.000000,-15.000000],[-15.000000,15.000000,-15.000000],[25.000000,15.000000,-25.000000],[0.000000,15.000000,-25.000000],[25.000000,25.000000,25.000000]]

// And I need to create cylinders (with constant radius) between each pair
of points like POINTS[i] and POINTS[i+1]
// So I can set radius, calculate vector coordinates
[0,0,0],[x(i),y(i),z(i)] , and it's height h(i):

RADIUS = 0.5;
function x(i) = POINTS[i+1][0]-POINTS[i][0];
function y(i) = POINTS[i+1][1]-POINTS[i][1];
function z(i) = POINTS[i+1][2]-POINTS[i][2];
function h(i) = sqrt(pow(x(i),2)+pow(y(i),2)+pow(z(i),2));

// Then the question is, how do I calculate the needed rotations and
translations to make the cylinder(h(i),RADIUS) start at POINTS[i] and end
at
POINTS[i+1] ?
// I found the information about rotations here:

http://stackoverflow.com/questions/1251828/calculate-rotations-to-look-at-a-3d-point
and tried to make it work in OpenSCAD but didn't succeed.
// Here's the bad code:

//function rotx(i) = atan2(z(i),y(i));
//function rotz(i) = atan2((x(i)*cos(rotx(i))), y(i) );
//function rotz2(i) = -atan2((x(i)*cos(rotx(i))), y(i) );
//function roty(i) = atan2( cos(rotx(i)), sin(rotx(i))*sin(rotz(i)))

//for( i = [0:7]) {
// if (z(i)>=0) {
//rotate([rotx(i),roty(i),rotz(i)]
//translate(POINTS[i])
//cylinder(h=h(i),r=RADIUS);
//}
//else {
//rotate([rotx(i),roty2(i),rotz(i)]
//translate(POINTS[i])
//cylinder(h=h(i),r=RADIUS);
//}
//}

// How do I make this work? Help me, please!

--
View this message in context:
http://forum.openscad.org/3D-Rotation-to-the-point-tp11651.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

Note you only need two rotations to point a cylinder to a point. So just rotx and rotz should do it but you need to do them in the right order. A much simpler way is to place spheres at your two points and take the hull to make a cylinder that joins them with nice rounded joints. On 17 February 2015 at 16:11, anp <me@anp.me> wrote: > // I have a massive of points, like this: > POINTS = > > [[20.000000,5.000000,15.000000],[20.000000,5.000000,25.000000],[25.000000,0.000000,15.000000],[25.000000,0.000000,25.000000],[25.000000,15.000000,-15.000000],[-15.000000,15.000000,-15.000000],[25.000000,15.000000,-25.000000],[0.000000,15.000000,-25.000000],[25.000000,25.000000,25.000000]] > > // And I need to create cylinders (with constant radius) between each pair > of points like POINTS[i] and POINTS[i+1] > // So I can set radius, calculate vector coordinates > [0,0,0],[x(i),y(i),z(i)] , and it's height h(i): > > RADIUS = 0.5; > function x(i) = POINTS[i+1][0]-POINTS[i][0]; > function y(i) = POINTS[i+1][1]-POINTS[i][1]; > function z(i) = POINTS[i+1][2]-POINTS[i][2]; > function h(i) = sqrt(pow(x(i),2)+pow(y(i),2)+pow(z(i),2)); > > // Then the question is, how do I calculate the needed rotations and > translations to make the cylinder(h(i),RADIUS) start at POINTS[i] and end > at > POINTS[i+1] ? > // I found the information about rotations here: > > http://stackoverflow.com/questions/1251828/calculate-rotations-to-look-at-a-3d-point > and tried to make it work in OpenSCAD but didn't succeed. > // Here's the bad code: > > //function rotx(i) = atan2(z(i),y(i)); > //function rotz(i) = atan2((x(i)*cos(rotx(i))), y(i) ); > //function rotz2(i) = -atan2((x(i)*cos(rotx(i))), y(i) ); > //function roty(i) = atan2( cos(rotx(i)), sin(rotx(i))*sin(rotz(i))) > > //for( i = [0:7]) { > // if (z(i)>=0) { > //rotate([rotx(i),roty(i),rotz(i)] > //translate(POINTS[i]) > //cylinder(h=h(i),r=RADIUS); > //} > //else { > //rotate([rotx(i),roty2(i),rotz(i)] > //translate(POINTS[i]) > //cylinder(h=h(i),r=RADIUS); > //} > //} > > // How do I make this work? Help me, please! > > > > -- > View this message in context: > http://forum.openscad.org/3D-Rotation-to-the-point-tp11651.html > Sent from the OpenSCAD mailing list archive at Nabble.com. > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
PF
Peter Falke
Tue, Feb 17, 2015 4:35 PM

Hi,

depending on what you want to do there is a very easy (but somewhat slow)
way to do this in OpenSCAD.
Its called chain-hull. Just dont set $fn to a very high number. This will
make nice transitions between the tubes.

r=.5;

fn_sphere=16;

// I have a massive of points, like this:

POINTS =

[[20.000000,5.000000,15.000000],[20.000000,5.000000,25.000000],[25.000000,0.000000,15.000000],[25.000000,0.000000,25.000000],[25.000000,15.000000,-15.000000],[-15.000000,15.000000,-15.000000],[25.000000,15.000000,-25.000000],[0.000000,15.000000,-25.000000],[25.000000,25.000000,25.000000]];

for(i=[0:len(POINTS)-1]){

hull(){

translate(POINTS[i])sphere(r,$fn=fn_sphere);

translate(POINTS[i+1])sphere(r,$fn=fn_sphere);

}

}

2015-02-17 17:11 GMT+01:00 anp me@anp.me:

// I have a massive of points, like this:
POINTS =

[[20.000000,5.000000,15.000000],[20.000000,5.000000,25.000000],[25.000000,0.000000,15.000000],[25.000000,0.000000,25.000000],[25.000000,15.000000,-15.000000],[-15.000000,15.000000,-15.000000],[25.000000,15.000000,-25.000000],[0.000000,15.000000,-25.000000],[25.000000,25.000000,25.000000]]

// And I need to create cylinders (with constant radius) between each pair
of points like POINTS[i] and POINTS[i+1]
// So I can set radius, calculate vector coordinates
[0,0,0],[x(i),y(i),z(i)] , and it's height h(i):

RADIUS = 0.5;
function x(i) = POINTS[i+1][0]-POINTS[i][0];
function y(i) = POINTS[i+1][1]-POINTS[i][1];
function z(i) = POINTS[i+1][2]-POINTS[i][2];
function h(i) = sqrt(pow(x(i),2)+pow(y(i),2)+pow(z(i),2));

// Then the question is, how do I calculate the needed rotations and
translations to make the cylinder(h(i),RADIUS) start at POINTS[i] and end
at
POINTS[i+1] ?
// I found the information about rotations here:

http://stackoverflow.com/questions/1251828/calculate-rotations-to-look-at-a-3d-point
and tried to make it work in OpenSCAD but didn't succeed.
// Here's the bad code:

//function rotx(i) = atan2(z(i),y(i));
//function rotz(i) = atan2((x(i)*cos(rotx(i))), y(i) );
//function rotz2(i) = -atan2((x(i)*cos(rotx(i))), y(i) );
//function roty(i) = atan2( cos(rotx(i)), sin(rotx(i))*sin(rotz(i)))

//for( i = [0:7]) {
// if (z(i)>=0) {
//rotate([rotx(i),roty(i),rotz(i)]
//translate(POINTS[i])
//cylinder(h=h(i),r=RADIUS);
//}
//else {
//rotate([rotx(i),roty2(i),rotz(i)]
//translate(POINTS[i])
//cylinder(h=h(i),r=RADIUS);
//}
//}

// How do I make this work? Help me, please!

--
View this message in context:
http://forum.openscad.org/3D-Rotation-to-the-point-tp11651.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

--
stempeldergeschichte@googlemail.com karsten@rohrbach.de

P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist:
Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu
schreiben.
Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen.

P.S. In case my e-mail is shorter than you enjoy:
I am currently trying short replies instead of no replies at all.
Please let me know, if you like to read more.

Enjoy!

Hi, depending on what you want to do there is a very easy (but somewhat slow) way to do this in OpenSCAD. Its called chain-hull. Just dont set $fn to a very high number. This will make nice transitions between the tubes. r=.5; fn_sphere=16; // I have a massive of points, like this: POINTS = [[20.000000,5.000000,15.000000],[20.000000,5.000000,25.000000],[25.000000,0.000000,15.000000],[25.000000,0.000000,25.000000],[25.000000,15.000000,-15.000000],[-15.000000,15.000000,-15.000000],[25.000000,15.000000,-25.000000],[0.000000,15.000000,-25.000000],[25.000000,25.000000,25.000000]]; for(i=[0:len(POINTS)-1]){ hull(){ translate(POINTS[i])sphere(r,$fn=fn_sphere); translate(POINTS[i+1])sphere(r,$fn=fn_sphere); } } 2015-02-17 17:11 GMT+01:00 anp <me@anp.me>: > // I have a massive of points, like this: > POINTS = > > [[20.000000,5.000000,15.000000],[20.000000,5.000000,25.000000],[25.000000,0.000000,15.000000],[25.000000,0.000000,25.000000],[25.000000,15.000000,-15.000000],[-15.000000,15.000000,-15.000000],[25.000000,15.000000,-25.000000],[0.000000,15.000000,-25.000000],[25.000000,25.000000,25.000000]] > > // And I need to create cylinders (with constant radius) between each pair > of points like POINTS[i] and POINTS[i+1] > // So I can set radius, calculate vector coordinates > [0,0,0],[x(i),y(i),z(i)] , and it's height h(i): > > RADIUS = 0.5; > function x(i) = POINTS[i+1][0]-POINTS[i][0]; > function y(i) = POINTS[i+1][1]-POINTS[i][1]; > function z(i) = POINTS[i+1][2]-POINTS[i][2]; > function h(i) = sqrt(pow(x(i),2)+pow(y(i),2)+pow(z(i),2)); > > // Then the question is, how do I calculate the needed rotations and > translations to make the cylinder(h(i),RADIUS) start at POINTS[i] and end > at > POINTS[i+1] ? > // I found the information about rotations here: > > http://stackoverflow.com/questions/1251828/calculate-rotations-to-look-at-a-3d-point > and tried to make it work in OpenSCAD but didn't succeed. > // Here's the bad code: > > //function rotx(i) = atan2(z(i),y(i)); > //function rotz(i) = atan2((x(i)*cos(rotx(i))), y(i) ); > //function rotz2(i) = -atan2((x(i)*cos(rotx(i))), y(i) ); > //function roty(i) = atan2( cos(rotx(i)), sin(rotx(i))*sin(rotz(i))) > > //for( i = [0:7]) { > // if (z(i)>=0) { > //rotate([rotx(i),roty(i),rotz(i)] > //translate(POINTS[i]) > //cylinder(h=h(i),r=RADIUS); > //} > //else { > //rotate([rotx(i),roty2(i),rotz(i)] > //translate(POINTS[i]) > //cylinder(h=h(i),r=RADIUS); > //} > //} > > // How do I make this work? Help me, please! > > > > -- > View this message in context: > http://forum.openscad.org/3D-Rotation-to-the-point-tp11651.html > Sent from the OpenSCAD mailing list archive at Nabble.com. > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > -- stempeldergeschichte@googlemail.com <karsten@rohrbach.de> P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist: Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu schreiben. Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen. P.S. In case my e-mail is shorter than you enjoy: I am currently trying short replies instead of no replies at all. Please let me know, if you like to read more. Enjoy!
PF
Peter Falke
Tue, Feb 17, 2015 4:40 PM

@nop head: smile

But your problem would be a good one for an example in MCAD.
These 3d rotations are tricky, (use of tan2)

2015-02-17 17:35 GMT+01:00 Peter Falke stempeldergeschichte@googlemail.com
:

Hi,

depending on what you want to do there is a very easy (but somewhat slow)
way to do this in OpenSCAD.
Its called chain-hull. Just dont set $fn to a very high number. This will
make nice transitions between the tubes.

r=.5;

fn_sphere=16;

// I have a massive of points, like this:

POINTS =

[[20.000000,5.000000,15.000000],[20.000000,5.000000,25.000000],[25.000000,0.000000,15.000000],[25.000000,0.000000,25.000000],[25.000000,15.000000,-15.000000],[-15.000000,15.000000,-15.000000],[25.000000,15.000000,-25.000000],[0.000000,15.000000,-25.000000],[25.000000,25.000000,25.000000]];

for(i=[0:len(POINTS)-1]){

hull(){

translate(POINTS[i])sphere(r,$fn=fn_sphere);

translate(POINTS[i+1])sphere(r,$fn=fn_sphere);

}

}

2015-02-17 17:11 GMT+01:00 anp me@anp.me:

// I have a massive of points, like this:
POINTS =

[[20.000000,5.000000,15.000000],[20.000000,5.000000,25.000000],[25.000000,0.000000,15.000000],[25.000000,0.000000,25.000000],[25.000000,15.000000,-15.000000],[-15.000000,15.000000,-15.000000],[25.000000,15.000000,-25.000000],[0.000000,15.000000,-25.000000],[25.000000,25.000000,25.000000]]

// And I need to create cylinders (with constant radius) between each pair
of points like POINTS[i] and POINTS[i+1]
// So I can set radius, calculate vector coordinates
[0,0,0],[x(i),y(i),z(i)] , and it's height h(i):

RADIUS = 0.5;
function x(i) = POINTS[i+1][0]-POINTS[i][0];
function y(i) = POINTS[i+1][1]-POINTS[i][1];
function z(i) = POINTS[i+1][2]-POINTS[i][2];
function h(i) = sqrt(pow(x(i),2)+pow(y(i),2)+pow(z(i),2));

// Then the question is, how do I calculate the needed rotations and
translations to make the cylinder(h(i),RADIUS) start at POINTS[i] and end
at
POINTS[i+1] ?
// I found the information about rotations here:

http://stackoverflow.com/questions/1251828/calculate-rotations-to-look-at-a-3d-point
and tried to make it work in OpenSCAD but didn't succeed.
// Here's the bad code:

//function rotx(i) = atan2(z(i),y(i));
//function rotz(i) = atan2((x(i)*cos(rotx(i))), y(i) );
//function rotz2(i) = -atan2((x(i)*cos(rotx(i))), y(i) );
//function roty(i) = atan2( cos(rotx(i)), sin(rotx(i))*sin(rotz(i)))

//for( i = [0:7]) {
// if (z(i)>=0) {
//rotate([rotx(i),roty(i),rotz(i)]
//translate(POINTS[i])
//cylinder(h=h(i),r=RADIUS);
//}
//else {
//rotate([rotx(i),roty2(i),rotz(i)]
//translate(POINTS[i])
//cylinder(h=h(i),r=RADIUS);
//}
//}

// How do I make this work? Help me, please!

--
View this message in context:
http://forum.openscad.org/3D-Rotation-to-the-point-tp11651.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

--
stempeldergeschichte@googlemail.com karsten@rohrbach.de

P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist:
Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu
schreiben.
Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen.

P.S. In case my e-mail is shorter than you enjoy:
I am currently trying short replies instead of no replies at all.
Please let me know, if you like to read more.

Enjoy!

--
stempeldergeschichte@googlemail.com karsten@rohrbach.de

P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist:
Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu
schreiben.
Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen.

P.S. In case my e-mail is shorter than you enjoy:
I am currently trying short replies instead of no replies at all.
Please let me know, if you like to read more.

Enjoy!

@nop head: smile But your problem would be a good one for an example in MCAD. These 3d rotations are tricky, (use of tan2) 2015-02-17 17:35 GMT+01:00 Peter Falke <stempeldergeschichte@googlemail.com> : > Hi, > > depending on what you want to do there is a very easy (but somewhat slow) > way to do this in OpenSCAD. > Its called chain-hull. Just dont set $fn to a very high number. This will > make nice transitions between the tubes. > > r=.5; > > fn_sphere=16; > > // I have a massive of points, like this: > > POINTS = > > > [[20.000000,5.000000,15.000000],[20.000000,5.000000,25.000000],[25.000000,0.000000,15.000000],[25.000000,0.000000,25.000000],[25.000000,15.000000,-15.000000],[-15.000000,15.000000,-15.000000],[25.000000,15.000000,-25.000000],[0.000000,15.000000,-25.000000],[25.000000,25.000000,25.000000]]; > > > for(i=[0:len(POINTS)-1]){ > > hull(){ > > translate(POINTS[i])sphere(r,$fn=fn_sphere); > > translate(POINTS[i+1])sphere(r,$fn=fn_sphere); > > } > > } > > > > > > > > 2015-02-17 17:11 GMT+01:00 anp <me@anp.me>: > >> // I have a massive of points, like this: >> POINTS = >> >> [[20.000000,5.000000,15.000000],[20.000000,5.000000,25.000000],[25.000000,0.000000,15.000000],[25.000000,0.000000,25.000000],[25.000000,15.000000,-15.000000],[-15.000000,15.000000,-15.000000],[25.000000,15.000000,-25.000000],[0.000000,15.000000,-25.000000],[25.000000,25.000000,25.000000]] >> >> // And I need to create cylinders (with constant radius) between each pair >> of points like POINTS[i] and POINTS[i+1] >> // So I can set radius, calculate vector coordinates >> [0,0,0],[x(i),y(i),z(i)] , and it's height h(i): >> >> RADIUS = 0.5; >> function x(i) = POINTS[i+1][0]-POINTS[i][0]; >> function y(i) = POINTS[i+1][1]-POINTS[i][1]; >> function z(i) = POINTS[i+1][2]-POINTS[i][2]; >> function h(i) = sqrt(pow(x(i),2)+pow(y(i),2)+pow(z(i),2)); >> >> // Then the question is, how do I calculate the needed rotations and >> translations to make the cylinder(h(i),RADIUS) start at POINTS[i] and end >> at >> POINTS[i+1] ? >> // I found the information about rotations here: >> >> http://stackoverflow.com/questions/1251828/calculate-rotations-to-look-at-a-3d-point >> and tried to make it work in OpenSCAD but didn't succeed. >> // Here's the bad code: >> >> //function rotx(i) = atan2(z(i),y(i)); >> //function rotz(i) = atan2((x(i)*cos(rotx(i))), y(i) ); >> //function rotz2(i) = -atan2((x(i)*cos(rotx(i))), y(i) ); >> //function roty(i) = atan2( cos(rotx(i)), sin(rotx(i))*sin(rotz(i))) >> >> //for( i = [0:7]) { >> // if (z(i)>=0) { >> //rotate([rotx(i),roty(i),rotz(i)] >> //translate(POINTS[i]) >> //cylinder(h=h(i),r=RADIUS); >> //} >> //else { >> //rotate([rotx(i),roty2(i),rotz(i)] >> //translate(POINTS[i]) >> //cylinder(h=h(i),r=RADIUS); >> //} >> //} >> >> // How do I make this work? Help me, please! >> >> >> >> -- >> View this message in context: >> http://forum.openscad.org/3D-Rotation-to-the-point-tp11651.html >> Sent from the OpenSCAD mailing list archive at Nabble.com. >> >> _______________________________________________ >> OpenSCAD mailing list >> Discuss@lists.openscad.org >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> > > > > -- > stempeldergeschichte@googlemail.com <karsten@rohrbach.de> > > P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist: > Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu > schreiben. > Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen. > > P.S. In case my e-mail is shorter than you enjoy: > I am currently trying short replies instead of no replies at all. > Please let me know, if you like to read more. > > Enjoy! > -- stempeldergeschichte@googlemail.com <karsten@rohrbach.de> P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist: Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu schreiben. Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen. P.S. In case my e-mail is shorter than you enjoy: I am currently trying short replies instead of no replies at all. Please let me know, if you like to read more. Enjoy!
A
anp
Tue, Feb 17, 2015 4:46 PM

Unfortunately, that's more of synthetic problem, which states that those
should be cylinders; I tried to replace the spheres in your example with
circles, but obviously circles are being created towards [0,0,1], which
makes hulls that aren't towards [0,0,1] not cylinders. Making hulls is very
good method, which I couldn't think of, but still requires those rotations
to be calculated properly.

--
View this message in context: http://forum.openscad.org/3D-Rotation-to-the-point-tp11651p11657.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Unfortunately, that's more of synthetic problem, which states that those should be cylinders; I tried to replace the spheres in your example with circles, but obviously circles are being created towards [0,0,1], which makes hulls that aren't towards [0,0,1] not cylinders. Making hulls is very good method, which I couldn't think of, but still requires those rotations to be calculated properly. -- View this message in context: http://forum.openscad.org/3D-Rotation-to-the-point-tp11651p11657.html Sent from the OpenSCAD mailing list archive at Nabble.com.
PF
Peter Falke
Tue, Feb 17, 2015 4:54 PM

You can use cylinders with height epsilon=.001 and hull them together.
But, yes, you need to get the rotations correct, first.

2015-02-17 17:46 GMT+01:00 anp me@anp.me:

Unfortunately, that's more of synthetic problem, which states that those
should be cylinders; I tried to replace the spheres in your example with
circles, but obviously circles are being created towards [0,0,1], which
makes hulls that aren't towards [0,0,1] not cylinders. Making hulls is very
good method, which I couldn't think of, but still requires those rotations
to be calculated properly.

--
View this message in context:
http://forum.openscad.org/3D-Rotation-to-the-point-tp11651p11657.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

--
stempeldergeschichte@googlemail.com karsten@rohrbach.de

P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist:
Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu
schreiben.
Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen.

P.S. In case my e-mail is shorter than you enjoy:
I am currently trying short replies instead of no replies at all.
Please let me know, if you like to read more.

Enjoy!

You can use cylinders with height epsilon=.001 and hull them together. But, yes, you need to get the rotations correct, first. 2015-02-17 17:46 GMT+01:00 anp <me@anp.me>: > Unfortunately, that's more of synthetic problem, which states that those > should be cylinders; I tried to replace the spheres in your example with > circles, but obviously circles are being created towards [0,0,1], which > makes hulls that aren't towards [0,0,1] not cylinders. Making hulls is very > good method, which I couldn't think of, but still requires those rotations > to be calculated properly. > > > > -- > View this message in context: > http://forum.openscad.org/3D-Rotation-to-the-point-tp11651p11657.html > Sent from the OpenSCAD mailing list archive at Nabble.com. > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > -- stempeldergeschichte@googlemail.com <karsten@rohrbach.de> P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist: Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu schreiben. Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen. P.S. In case my e-mail is shorter than you enjoy: I am currently trying short replies instead of no replies at all. Please let me know, if you like to read more. Enjoy!
A
anp
Tue, Feb 17, 2015 5:32 PM

But, yes, you need to get the rotations correct, first.

The problem is that I'm not any good at maths and tried to "calibrate" those
angles with some obvious example, like [[25,25,25],[0,0,0]], which brought
me nowhere.
So I thought that someone has the working solution for such problem.

Peter Falke wrote

But, yes, you need to get the rotations correct, first.

--
View this message in context: http://forum.openscad.org/3D-Rotation-to-the-point-tp11651p11661.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

But, yes, you need to get the rotations correct, first. The problem is that I'm not any good at maths and tried to "calibrate" those angles with some obvious example, like [[25,25,25],[0,0,0]], which brought me nowhere. So I thought that someone has the working solution for such problem. Peter Falke wrote > But, yes, you need to get the rotations correct, first. -- View this message in context: http://forum.openscad.org/3D-Rotation-to-the-point-tp11651p11661.html Sent from the OpenSCAD mailing list archive at Nabble.com.
YA
Yona Appletree
Tue, Feb 17, 2015 5:33 PM

Here's a simple module that I use in my work and an example of how to
use it to move/size the cylinders. This also should be much faster than
using hull().

You could easily modify this to make a single module that would take two
points as well...

moduleaimAt(p) {
rotate([0,0, atan2(p.y,p.x)])
rotate([0, atan2(norm([p.x,p.y]), p.z),0])
children();
}

// First Point
a=[20,5,10];

// Second Point
b=[100,10,30];

// Point Markers
translate(a) color("red")sphere(r=1);
translate(b) color("green")sphere(r=1);

// Starting at a, aim towards b. Cylinder length is the magnitude of b-a
translate(a) aimAt(b-a)cylinder(r=.5,h=norm(b-a));

The result should look like this:
https://www.dropbox.com/s/dcdijzt52hgp1wd/Screenshot%202015-02-17%2009.33.09.png?dl=0

  • Yona

Peter Falke mailto:stempeldergeschichte@googlemail.com
February 17, 2015 at 08:54
You can use cylinders with height epsilon=.001 and hull them together.
But, yes, you need to get the rotations correct, first.

--
stempeldergeschichte@googlemail.com mailto:karsten@rohrbach.de

P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist:
Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu
schreiben.
Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen.

P.S. In case my e-mail is shorter than you enjoy:
I am currently trying short replies instead of no replies at all.
Please let me know, if you like to read more.

Enjoy!


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
anp mailto:me@anp.me
February 17, 2015 at 08:46
Unfortunately, that's more of synthetic problem, which states that those
should be cylinders; I tried to replace the spheres in your example with
circles, but obviously circles are being created towards [0,0,1], which
makes hulls that aren't towards [0,0,1] not cylinders. Making hulls is
very
good method, which I couldn't think of, but still requires those rotations
to be calculated properly.

--
View this message in context:
http://forum.openscad.org/3D-Rotation-to-the-point-tp11651p11657.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

Here's a simple module that I use in my work and an example of how to use it to move/size the cylinders. This also should be much faster than using hull(). You could easily modify this to make a single module that would take two points as well... moduleaimAt(p) { rotate([0,0, atan2(p.y,p.x)]) rotate([0, atan2(norm([p.x,p.y]), p.z),0]) children(); } // First Point a=[20,5,10]; // Second Point b=[100,10,30]; // Point Markers translate(a) color("red")sphere(r=1); translate(b) color("green")sphere(r=1); // Starting at a, aim towards b. Cylinder length is the magnitude of b-a translate(a) aimAt(b-a)cylinder(r=.5,h=norm(b-a)); The result should look like this: https://www.dropbox.com/s/dcdijzt52hgp1wd/Screenshot%202015-02-17%2009.33.09.png?dl=0 - Yona > Peter Falke <mailto:stempeldergeschichte@googlemail.com> > February 17, 2015 at 08:54 > You can use cylinders with height epsilon=.001 and hull them together. > But, yes, you need to get the rotations correct, first. > > > > > -- > stempeldergeschichte@googlemail.com <mailto:karsten@rohrbach.de> > > P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist: > Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu > schreiben. > Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen. > > P.S. In case my e-mail is shorter than you enjoy: > I am currently trying short replies instead of no replies at all. > Please let me know, if you like to read more. > > Enjoy! > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > anp <mailto:me@anp.me> > February 17, 2015 at 08:46 > Unfortunately, that's more of synthetic problem, which states that those > should be cylinders; I tried to replace the spheres in your example with > circles, but obviously circles are being created towards [0,0,1], which > makes hulls that aren't towards [0,0,1] not cylinders. Making hulls is > very > good method, which I couldn't think of, but still requires those rotations > to be calculated properly. > > > > -- > View this message in context: > http://forum.openscad.org/3D-Rotation-to-the-point-tp11651p11657.html > Sent from the OpenSCAD mailing list archive at Nabble.com. > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
PF
Peter Falke
Tue, Feb 17, 2015 6:30 PM

Here is some old code of mine (from the file attached)

// place the extruded shape at the position x(t) and

// rotate it so that is normal to thepath

module place(t){

translate(x(t))

rotate([0,0,a1(t)])

rotate([0,90-a2(t),0])

rotate([0,0,twist(t)])

scale(s(t))

child();

}

// distance between points x(t) and x(t+dt) projected onto the xy-plane

function dxy(t)=sqrt(

pow(x(t+dt)[0]-x(t)[0],2)+

pow(x(t+dt)[1]-x(t)[1],2)

);

// angle between x-axis and projection of dx(t) onto the xy-plane

function a1(t)=atan2(x(t+dt)[1]-x(t)[1],x(t+dt)[0]-x(t)[0]);

// angle between xy plane and dx(t) vector

function a2(t)=atan2(x(t+dt)[2]-x(t)[2],dxy(t));

2015-02-17 18:33 GMT+01:00 Yona Appletree hypher@gmail.com:

Here's a simple module that I use in my work and an example of how to use
it to move/size the cylinders. This also should be much faster than using
hull().

You could easily modify this to make a single module that would take two
points as well...

module aimAt(p) {
rotate([0, 0, atan2(p.y,p.x)])
rotate([0, atan2(norm([p.x,p.y]), p.z), 0])
children();
}
// First Pointa=[20,5,10];
// Second Pointb=[100,10,30];
// Point Markerstranslate(a) color("red") sphere(r=1);translate(b) color("green") sphere(r=1);
// Starting at a, aim towards b. Cylinder length is the magnitude of b-atranslate(a) aimAt(b-a) cylinder(r=.5,h=norm(b-a));

The result should look like this:
https://www.dropbox.com/s/dcdijzt52hgp1wd/Screenshot%202015-02-17%2009.33.09.png?dl=0

  • Yona

    Peter Falke stempeldergeschichte@googlemail.com
    February 17, 2015 at 08:54
    You can use cylinders with height epsilon=.001 and hull them together.
    But, yes, you need to get the rotations correct, first.

--
stempeldergeschichte@googlemail.com karsten@rohrbach.de

P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist:
Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu
schreiben.
Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen.

P.S. In case my e-mail is shorter than you enjoy:
I am currently trying short replies instead of no replies at all.
Please let me know, if you like to read more.

Enjoy!


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
anp me@anp.me
February 17, 2015 at 08:46
Unfortunately, that's more of synthetic problem, which states that those
should be cylinders; I tried to replace the spheres in your example with
circles, but obviously circles are being created towards [0,0,1], which
makes hulls that aren't towards [0,0,1] not cylinders. Making hulls is very
good method, which I couldn't think of, but still requires those rotations
to be calculated properly.

--
View this message in context:
http://forum.openscad.org/3D-Rotation-to-the-point-tp11651p11657.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

--
stempeldergeschichte@googlemail.com karsten@rohrbach.de

P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist:
Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu
schreiben.
Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen.

P.S. In case my e-mail is shorter than you enjoy:
I am currently trying short replies instead of no replies at all.
Please let me know, if you like to read more.

Enjoy!

Here is some old code of mine (from the file attached) // place the extruded shape at the position x(t) and // rotate it so that is normal to thepath module place(t){ translate(x(t)) rotate([0,0,a1(t)]) rotate([0,90-a2(t),0]) rotate([0,0,twist(t)]) scale(s(t)) child(); } // distance between points x(t) and x(t+dt) projected onto the xy-plane function dxy(t)=sqrt( pow(x(t+dt)[0]-x(t)[0],2)+ pow(x(t+dt)[1]-x(t)[1],2) ); // angle between x-axis and projection of dx(t) onto the xy-plane function a1(t)=atan2(x(t+dt)[1]-x(t)[1],x(t+dt)[0]-x(t)[0]); // angle between xy plane and dx(t) vector function a2(t)=atan2(x(t+dt)[2]-x(t)[2],dxy(t)); 2015-02-17 18:33 GMT+01:00 Yona Appletree <hypher@gmail.com>: > Here's a simple module that I use in my work and an example of how to use > it to move/size the cylinders. This also should be much faster than using > hull(). > > You could easily modify this to make a single module that would take two > points as well... > > module aimAt(p) { > rotate([0, 0, atan2(p.y,p.x)]) > rotate([0, atan2(norm([p.x,p.y]), p.z), 0]) > children(); > } > // First Pointa=[20,5,10]; > // Second Pointb=[100,10,30]; > // Point Markerstranslate(a) color("red") sphere(r=1);translate(b) color("green") sphere(r=1); > // Starting at a, aim towards b. Cylinder length is the magnitude of b-atranslate(a) aimAt(b-a) cylinder(r=.5,h=norm(b-a)); > > The result should look like this: > https://www.dropbox.com/s/dcdijzt52hgp1wd/Screenshot%202015-02-17%2009.33.09.png?dl=0 > > - Yona > > Peter Falke <stempeldergeschichte@googlemail.com> > February 17, 2015 at 08:54 > You can use cylinders with height epsilon=.001 and hull them together. > But, yes, you need to get the rotations correct, first. > > > > > -- > stempeldergeschichte@googlemail.com <karsten@rohrbach.de> > > P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist: > Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu > schreiben. > Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen. > > P.S. In case my e-mail is shorter than you enjoy: > I am currently trying short replies instead of no replies at all. > Please let me know, if you like to read more. > > Enjoy! > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > anp <me@anp.me> > February 17, 2015 at 08:46 > Unfortunately, that's more of synthetic problem, which states that those > should be cylinders; I tried to replace the spheres in your example with > circles, but obviously circles are being created towards [0,0,1], which > makes hulls that aren't towards [0,0,1] not cylinders. Making hulls is very > good method, which I couldn't think of, but still requires those rotations > to be calculated properly. > > > > -- > View this message in context: > http://forum.openscad.org/3D-Rotation-to-the-point-tp11651p11657.html > Sent from the OpenSCAD mailing list archive at Nabble.com. > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > > -- stempeldergeschichte@googlemail.com <karsten@rohrbach.de> P.S. Falls meine E-Mail kürzer ausfällt als Dir angenehm ist: Ich probiere gerade aus kurze Antworten statt gar keine Antworten zu schreiben. Wenn Du gerne mehr lesen möchtest, dann lass es mich bitte wissen. P.S. In case my e-mail is shorter than you enjoy: I am currently trying short replies instead of no replies at all. Please let me know, if you like to read more. Enjoy!