discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

F5 works, but not F6

NH
nop head
Sun, Jun 14, 2015 3:34 PM

Actually the rotation is only needed when $fn is a multiple of 4. It lines
up without when $fn is a multiple of 2 and not at all if it is odd.

On 14 June 2015 at 15:41, nop head nop.head@gmail.com wrote:

Actually it was caused by the winding order of one of the end caps being
wrong. This fixes it: -

function cap(facets, segment = 0, i = 0) = i < facets ? concat(segment ?
facets * segment + i : facets - 1 - i, cap(facets, segment, i + 1)) : [];

Also the sphere facets can be aligned with the tube by adding a rotation:

 translate(path_points[0])
     rotate([0, 180 / $fn, 0]) sphere(ballDiam / 2);

On 14 June 2015 at 15:17, nop head nop.head@gmail.com wrote:

PolySet has nonplanar faces. Attempting alternate construction

ERROR: Alternate construction failed. CGAL error in
CGAL_Nef_polyhedron3(): CGAL ERROR: assertion violation! Expr:
e->incident_sface() != SFace_const_handle() File:
/data/OpenSCAD/libraries-mingw32-master/mxe/usr/i686-w64-mingw32.static/include/CGAL/Nef_S2/SM_const_decorator.h
Line: 326

On 14 June 2015 at 15:07, nop head nop.head@gmail.com wrote:

Unfortunately F6 fails on my system but it works in 2 minutes if I
remove the spheres at the end points.

Looks like a bug in OpenScad triggered by unioning nearly coincident
faces.

On 14 June 2015 at 14:54, jon jon@jonbondy.com wrote:

Thank you very much.  You are very generous with your time.

Jon

On 6/14/2015 8:31 AM, nop head wrote:

rch = 0.1;
ballDiam = 25.4 * 1/4 + rch;
myScale = 1/40;
hubR = 5;

function f(a,b,t) =  // spiral
[ (a + t * b) * cos(t),
(a + t * b) * sin(t),
0
];

$fn = 50;

function m_translate(v) = [ [1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0],
[v.x, v.y, v.z, 1  ] ];

function m_rotate(v) =  [ [1,  0,        0,        0],
[0,  cos(v.x),  sin(v.x), 0],
[0, -sin(v.x),  cos(v.x), 0],
[0,  0,        0,        1] ]
* [ [ cos(v.y), 0,  -sin(v.y), 0],
[0,        1,  0,        0],
[ sin(v.y), 0,  cos(v.y), 0],
[0,        0,  0,        1] ]
* [ [ cos(v.z),  sin(v.z), 0, 0],
[-sin(v.z),  cos(v.z), 0, 0],
[ 0,        0,        1, 0],
[ 0,        0,        0, 1] ];

function vec3(v) = [v.x, v.y, v.z];
function transform(v, m)  = vec3([v.x, v.y, v.z, 1] * m);

function orientate(position, normal) = m_rotate([0,
atan2(sqrt(pow(normal[0], 2) + pow(normal[1], 2)), normal[2]), 0])
* m_rotate([0, 0, atan2(normal[1], normal[0])])
* m_translate(position);

function circle_points(r = 1, a = 0) = a < 360 ? concat([[r * sin(a), r

  • cos(a), 0]], circle_points(r, a + 360 / $fn)) : [] ;

function path_points(a, b, step, t = 0) = t <= 720 ? concat([f(a,b,t)],
path_points(a, b, step, t + step)) : [] ;

function transform_points(list, matrix, i = 0) = i < len(list) ?
concat([ transform(list[i], matrix) ], transform_points(list, matrix, i +
1)) : [];

function tube_points(profile, path, i = 0) = i < len(path) - 1
? concat(transform_points(profile,
orientate(path[i], (path[i + 1] - path[i])/ 2)), tube_points(profile, path,
i + 1))
: transform_points(profile,
orientate(path[i], (path[i] - path[i - 1])/ 2)) ;

function tube_faces(segs, facets, s, i = 0) = i < facets ? concat([[s *
facets + i,
s *
facets + (i + 1) % facets,
((s

    1. % segs) * facets + (i + 1) % facets,
      ((s
    1. % segs) * facets + i]],

tube_faces(segs, facets, s, i + 1)) : [];

function path_faces(segs, facets, i = 0) = i < segs - 1 ?
concat(tube_faces(segs, facets, i), path_faces(segs, facets, i + 1)) : [];

function cap(facets, segment = 0, i = 0) = i < facets ? concat(i +
facets * segment, cap(facets, segment, i + 1)) : [];

circle_points = circle_points(ballDiam / 2);
facets = len(circle_points);

path_points = path_points(hubR, myScale, 1);
segments = len(path_points);

tube_points = tube_points(circle_points, path_points);
path_faces = path_faces(segments, facets);

union() {
translate(path_points[0])
sphere(ballDiam / 2);

 polyhedron(points = tube_points, faces = concat([cap(facets)],

path_faces, [cap(facets, segments - 1)]));

 translate(path_points[segments - 1])
     sphere(ballDiam / 2);

}

On 14 June 2015 at 12:41, jon jon@jonbondy.com wrote:

I found and modified kit wallace's knot code (which is based on some
of your code).  Once I understood that the function at the top controlled
the entire object, it was indeed simple.  That is, the two of you made it
simple for me!  Not sure how to eliminate the requirement that the tube be
closed, though.

On 6/13/2015 8:55 PM, nop head wrote:

$fn = 50;
for (d = [0:1:720]) hull()

I think it will just take a very long time or consume all of the
memory because CGAL hates the massive implicit union of objects with lots
of vertices. It simply doesn't scale to high detail models. If you can
construct it with functions that generate lists to feed into polyhedron it
will be much faster.

See the work kitwallace did with knots. A spiral is not too different.

On 14 June 2015 at 01:35, jon jon@jonbondy.com wrote:

I can get this to work with F5, but not with F6: it just hangs for
hours, running full CPU.  Any thoughts?

rch = 0.1;
ballDiam = 25.4 * 1/4 + rch;
$fn = 50;

module spiral() {
myScale = 1/40;
hubR = 5;
for (d = [0:1:720]) {
hull(){
rotate([0, 0, d])
translate([hubR + d * myScale, 0, 0])
sphere(d = ballDiam);
rotate([0, 0, d])
translate([hubR + (d+1) * myScale, 0, 0])
sphere(d = ballDiam);

         }
     }

 };

difference() {
translate([0, 0, -ballDiam * 0.7])
cylinder(h=ballDiam, r=28);
spiral();
}


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


OpenSCAD mailing listDiscuss@lists.openscad.orghttp://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

No virus found in this message.
Checked by AVG - www.avg.com
Version: 2015.0.6030 / Virus Database: 4360/10009 - Release Date:
06/13/15


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


OpenSCAD mailing listDiscuss@lists.openscad.orghttp://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

No virus found in this message.
Checked by AVG - www.avg.com
Version: 2015.0.6030 / Virus Database: 4360/10012 - Release Date:
06/14/15


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

Actually the rotation is only needed when $fn is a multiple of 4. It lines up without when $fn is a multiple of 2 and not at all if it is odd. On 14 June 2015 at 15:41, nop head <nop.head@gmail.com> wrote: > Actually it was caused by the winding order of one of the end caps being > wrong. This fixes it: - > > function cap(facets, segment = 0, i = 0) = i < facets ? concat(segment ? > facets * segment + i : facets - 1 - i, cap(facets, segment, i + 1)) : []; > > Also the sphere facets can be aligned with the tube by adding a rotation: > > translate(path_points[0]) > rotate([0, 180 / $fn, 0]) sphere(ballDiam / 2); > > > > > On 14 June 2015 at 15:17, nop head <nop.head@gmail.com> wrote: > >> PolySet has nonplanar faces. Attempting alternate construction >> >> ERROR: Alternate construction failed. CGAL error in >> CGAL_Nef_polyhedron3(): CGAL ERROR: assertion violation! Expr: >> e->incident_sface() != SFace_const_handle() File: >> /data/OpenSCAD/libraries-mingw32-master/mxe/usr/i686-w64-mingw32.static/include/CGAL/Nef_S2/SM_const_decorator.h >> Line: 326 >> >> >> >> On 14 June 2015 at 15:07, nop head <nop.head@gmail.com> wrote: >> >>> Unfortunately F6 fails on my system but it works in 2 minutes if I >>> remove the spheres at the end points. >>> >>> Looks like a bug in OpenScad triggered by unioning nearly coincident >>> faces. >>> >>> On 14 June 2015 at 14:54, jon <jon@jonbondy.com> wrote: >>> >>>> Thank you very much. You are very generous with your time. >>>> >>>> Jon >>>> >>>> >>>> On 6/14/2015 8:31 AM, nop head wrote: >>>> >>>> rch = 0.1; >>>> ballDiam = 25.4 * 1/4 + rch; >>>> myScale = 1/40; >>>> hubR = 5; >>>> >>>> function f(a,b,t) = // spiral >>>> [ (a + t * b) * cos(t), >>>> (a + t * b) * sin(t), >>>> 0 >>>> ]; >>>> >>>> $fn = 50; >>>> >>>> function m_translate(v) = [ [1, 0, 0, 0], >>>> [0, 1, 0, 0], >>>> [0, 0, 1, 0], >>>> [v.x, v.y, v.z, 1 ] ]; >>>> >>>> function m_rotate(v) = [ [1, 0, 0, 0], >>>> [0, cos(v.x), sin(v.x), 0], >>>> [0, -sin(v.x), cos(v.x), 0], >>>> [0, 0, 0, 1] ] >>>> * [ [ cos(v.y), 0, -sin(v.y), 0], >>>> [0, 1, 0, 0], >>>> [ sin(v.y), 0, cos(v.y), 0], >>>> [0, 0, 0, 1] ] >>>> * [ [ cos(v.z), sin(v.z), 0, 0], >>>> [-sin(v.z), cos(v.z), 0, 0], >>>> [ 0, 0, 1, 0], >>>> [ 0, 0, 0, 1] ]; >>>> >>>> function vec3(v) = [v.x, v.y, v.z]; >>>> function transform(v, m) = vec3([v.x, v.y, v.z, 1] * m); >>>> >>>> function orientate(position, normal) = m_rotate([0, >>>> atan2(sqrt(pow(normal[0], 2) + pow(normal[1], 2)), normal[2]), 0]) >>>> * m_rotate([0, 0, atan2(normal[1], normal[0])]) >>>> * m_translate(position); >>>> >>>> function circle_points(r = 1, a = 0) = a < 360 ? concat([[r * sin(a), r >>>> * cos(a), 0]], circle_points(r, a + 360 / $fn)) : [] ; >>>> >>>> function path_points(a, b, step, t = 0) = t <= 720 ? concat([f(a,b,t)], >>>> path_points(a, b, step, t + step)) : [] ; >>>> >>>> function transform_points(list, matrix, i = 0) = i < len(list) ? >>>> concat([ transform(list[i], matrix) ], transform_points(list, matrix, i + >>>> 1)) : []; >>>> >>>> function tube_points(profile, path, i = 0) = i < len(path) - 1 >>>> ? concat(transform_points(profile, >>>> orientate(path[i], (path[i + 1] - path[i])/ 2)), tube_points(profile, path, >>>> i + 1)) >>>> : transform_points(profile, >>>> orientate(path[i], (path[i] - path[i - 1])/ 2)) ; >>>> >>>> function tube_faces(segs, facets, s, i = 0) = i < facets ? concat([[s * >>>> facets + i, >>>> s * >>>> facets + (i + 1) % facets, >>>> ((s >>>> + 1) % segs) * facets + (i + 1) % facets, >>>> ((s >>>> + 1) % segs) * facets + i]], >>>> >>>> tube_faces(segs, facets, s, i + 1)) : []; >>>> >>>> function path_faces(segs, facets, i = 0) = i < segs - 1 ? >>>> concat(tube_faces(segs, facets, i), path_faces(segs, facets, i + 1)) : []; >>>> >>>> function cap(facets, segment = 0, i = 0) = i < facets ? concat(i + >>>> facets * segment, cap(facets, segment, i + 1)) : []; >>>> >>>> circle_points = circle_points(ballDiam / 2); >>>> facets = len(circle_points); >>>> >>>> path_points = path_points(hubR, myScale, 1); >>>> segments = len(path_points); >>>> >>>> tube_points = tube_points(circle_points, path_points); >>>> path_faces = path_faces(segments, facets); >>>> >>>> union() { >>>> translate(path_points[0]) >>>> sphere(ballDiam / 2); >>>> >>>> polyhedron(points = tube_points, faces = concat([cap(facets)], >>>> path_faces, [cap(facets, segments - 1)])); >>>> >>>> translate(path_points[segments - 1]) >>>> sphere(ballDiam / 2); >>>> } >>>> >>>> >>>> On 14 June 2015 at 12:41, jon <jon@jonbondy.com> wrote: >>>> >>>>> I found and modified kit wallace's knot code (which is based on some >>>>> of your code). Once I understood that the function at the top controlled >>>>> the entire object, it was indeed simple. That is, the two of you made it >>>>> simple for me! Not sure how to eliminate the requirement that the tube be >>>>> closed, though. >>>>> >>>>> On 6/13/2015 8:55 PM, nop head wrote: >>>>> >>>>> $fn = 50; >>>>> for (d = [0:1:720]) hull() >>>>> >>>>> I think it will just take a very long time or consume all of the >>>>> memory because CGAL hates the massive implicit union of objects with lots >>>>> of vertices. It simply doesn't scale to high detail models. If you can >>>>> construct it with functions that generate lists to feed into polyhedron it >>>>> will be much faster. >>>>> >>>>> See the work kitwallace did with knots. A spiral is not too different. >>>>> >>>>> On 14 June 2015 at 01:35, jon <jon@jonbondy.com> wrote: >>>>> >>>>>> I can get this to work with F5, but not with F6: it just hangs for >>>>>> hours, running full CPU. Any thoughts? >>>>>> >>>>>> >>>>>> rch = 0.1; >>>>>> ballDiam = 25.4 * 1/4 + rch; >>>>>> $fn = 50; >>>>>> >>>>>> module spiral() { >>>>>> myScale = 1/40; >>>>>> hubR = 5; >>>>>> for (d = [0:1:720]) { >>>>>> hull(){ >>>>>> rotate([0, 0, d]) >>>>>> translate([hubR + d * myScale, 0, 0]) >>>>>> sphere(d = ballDiam); >>>>>> rotate([0, 0, d]) >>>>>> translate([hubR + (d+1) * myScale, 0, 0]) >>>>>> sphere(d = ballDiam); >>>>>> >>>>>> } >>>>>> } >>>>>> >>>>>> }; >>>>>> >>>>>> difference() { >>>>>> translate([0, 0, -ballDiam * 0.7]) >>>>>> cylinder(h=ballDiam, r=28); >>>>>> spiral(); >>>>>> } >>>>>> >>>>>> _______________________________________________ >>>>>> OpenSCAD mailing list >>>>>> Discuss@lists.openscad.org >>>>>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >>>>>> >>>>> >>>>> >>>>> >>>>> _______________________________________________ >>>>> OpenSCAD mailing listDiscuss@lists.openscad.orghttp://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >>>>> >>>>> >>>>> >>>>> No virus found in this message. >>>>> Checked by AVG - www.avg.com >>>>> Version: 2015.0.6030 / Virus Database: 4360/10009 - Release Date: >>>>> 06/13/15 >>>>> >>>>> >>>>> >>>>> _______________________________________________ >>>>> OpenSCAD mailing list >>>>> Discuss@lists.openscad.org >>>>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >>>>> >>>>> >>>> >>>> >>>> _______________________________________________ >>>> OpenSCAD mailing listDiscuss@lists.openscad.orghttp://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >>>> >>>> >>>> >>>> No virus found in this message. >>>> Checked by AVG - www.avg.com >>>> Version: 2015.0.6030 / Virus Database: 4360/10012 - Release Date: >>>> 06/14/15 >>>> >>>> >>>> >>>> _______________________________________________ >>>> OpenSCAD mailing list >>>> Discuss@lists.openscad.org >>>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >>>> >>>> >>> >> >
B
bdl
Sun, Feb 19, 2017 3:03 AM

I'm hitting this as well.  I wrote a module to do "shift_extrude" and it
works nicely with F5 preview.  For F6 rendering, if I only have one shifted
extrusion, it's fine, but if I add a second, I get:

ERROR: CGAL error in CGAL_Nef_polyhedron3(): CGAL ERROR: assertion
violation! Expr: e->incident_sface() != SFace_const_handle() File:
/opt/mxe/usr/x86_64-w64-mingw32.static/include/CGAL/Nef_S2/SM_const_decorator.h
Line: 326

I extracted the minimum code to reproduce the error:
bug_report.scad http://forum.openscad.org/file/n20483/bug_report.scad

Oddly enough, it doesn't seem to be a matter of the number of slices.  I
tried changing the number of slices to 10 to reduce the number of vertices
and it still fails.  Even with the separation between the two objects.

--
View this message in context: http://forum.openscad.org/F5-works-but-not-F6-tp12875p20483.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

I'm hitting this as well. I wrote a module to do "shift_extrude" and it works nicely with F5 preview. For F6 rendering, if I only have one shifted extrusion, it's fine, but if I add a second, I get: ERROR: CGAL error in CGAL_Nef_polyhedron3(): CGAL ERROR: assertion violation! Expr: e->incident_sface() != SFace_const_handle() File: /opt/mxe/usr/x86_64-w64-mingw32.static/include/CGAL/Nef_S2/SM_const_decorator.h Line: 326 I extracted the minimum code to reproduce the error: bug_report.scad <http://forum.openscad.org/file/n20483/bug_report.scad> Oddly enough, it doesn't seem to be a matter of the number of slices. I tried changing the number of slices to 10 to reduce the number of vertices and it still fails. Even with the separation between the two objects. -- View this message in context: http://forum.openscad.org/F5-works-but-not-F6-tp12875p20483.html Sent from the OpenSCAD mailing list archive at Nabble.com.
TP
Torsten Paul
Sun, Feb 19, 2017 3:18 AM

On 02/19/2017 04:03 AM, bdl wrote:

I extracted the minimum code to reproduce the error:
bug_report.scad http://forum.openscad.org/file/n20483/bug_report.scad

On 02/19/2017 04:03 AM, bdl wrote: > I extracted the minimum code to reproduce the error: > bug_report.scad <http://forum.openscad.org/file/n20483/bug_report.scad> > The winding order of some faces is wrong. See https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/FAQ#Why_is_my_model_showing_up_with_F5_but_not_F6.3F ciao, Torsten.
B
bdl
Sun, Feb 19, 2017 3:35 AM

Yeah, I just figured that out while playing around.

My regular_polygon winds counterclockwise in the plane, to the top and
bottom faces are wrong if height > 0 and all the other faces are wrong if
height < 0.  I fixed it and now things seem to be working.

What's odd is I've had errors in face winding before and never gotten that
error... usually things just look funny... but maybe I was only using F5 in
those cases and just didn't notice the problem here.

--
View this message in context: http://forum.openscad.org/F5-works-but-not-F6-tp12875p20485.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Yeah, I just figured that out while playing around. My regular_polygon winds counterclockwise in the plane, to the top and bottom faces are wrong if height > 0 and all the other faces are wrong if height < 0. I fixed it and now things seem to be working. What's odd is I've had errors in face winding before and never gotten that error... usually things just look funny... but maybe I was only using F5 in those cases and just didn't notice the problem here. -- View this message in context: http://forum.openscad.org/F5-works-but-not-F6-tp12875p20485.html Sent from the OpenSCAD mailing list archive at Nabble.com.
P
Parkinbot
Sun, Feb 19, 2017 6:53 PM

well done nophead. This is a version using my sweep():

use
<Naca_sweep.scad>
$fn=50;
spiral(a1 = 120, a2 = 960, r=22, rc=10);

module spiral(a1=180, a2=720, r=25, rc=10)
{
sweep(gendat(a1, a2, r, rc));
translate(spiral_(a1, r)) sphere(rc);
translate(spiral_(a2, r)) sphere(rc);
}

function gendat(a1=180, a2=720, r=25, rc=10) = let(N=$fn?$fn:360/$fa,
M=ceil((a2-a1)/360N), st = (a2-a1)/M)
[for(i=[0:M]) let(a=i
st+a1) traject(circle_(rc), direction_(a),
spiral_(a, r))]; // compose all trajectory data

function circle_(r=10, n=undef) = let(N=n?n:$fn?$fn:360/$fa, st = 360/N)
[for(i=[0:N-1]) [rcos(ist), 0, rsin(ist)]]; // 2D shape

function spiral_(a, r) = ra/360[sin(a), cos(a)]; // archimedes spiral

function direction_(a, r=10) = let(p1 = spiral_(a-.5, r), p2 =
spiral_(a+.5, r)) (p2-p1)/norm(p2-p1); // direction vector needed for
rotation

function traject(L, v, t) = let(rot = [[v[1], -v[0], 0],[-v[0], v[1], 0],
[0, 0, 1]])
[for(i=L) rot*i+[t[0], t[1], 0]]; // rotate + translate to place circle
into trajectory

--
View this message in context: http://forum.openscad.org/F5-works-but-not-F6-tp12875p20493.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

well done nophead. This is a version using my sweep(): > use > <Naca_sweep.scad> > $fn=50; > spiral(a1 = 120, a2 = 960, r=22, rc=10); > > module spiral(a1=180, a2=720, r=25, rc=10) > { > sweep(gendat(a1, a2, r, rc)); > translate(spiral_(a1, r)) sphere(rc); > translate(spiral_(a2, r)) sphere(rc); > } > > function gendat(a1=180, a2=720, r=25, rc=10) = let(N=$fn?$fn:360/$fa, > M=ceil((a2-a1)/360*N), st = (a2-a1)/M) > [for(i=[0:M]) let(a=i*st+a1) traject(circle_(rc), direction_(a), > spiral_(a, r))]; // compose all trajectory data > > function circle_(r=10, n=undef) = let(N=n?n:$fn?$fn:360/$fa, st = 360/N) > [for(i=[0:N-1]) [r*cos(i*st), 0, r*sin(i*st)]]; // 2D shape > > function spiral_(a, r) = r*a/360*[sin(a), cos(a)]; // archimedes spiral > > function direction_(a, r=10) = let(p1 = spiral_(a-.5, r), p2 = > spiral_(a+.5, r)) (p2-p1)/norm(p2-p1); // direction vector needed for > rotation > > function traject(L, v, t) = let(rot = [[v[1], -v[0], 0],[-v[0], v[1], 0], > [0, 0, 1]]) > [for(i=L) rot*i+[t[0], t[1], 0]]; // rotate + translate to place circle > into trajectory -- View this message in context: http://forum.openscad.org/F5-works-but-not-F6-tp12875p20493.html Sent from the OpenSCAD mailing list archive at Nabble.com.
NH
nop head
Mon, Feb 20, 2017 5:27 PM

Nice. A bit simpler than mine!

On 19 February 2017 at 18:53, Parkinbot rudolf@parkinbot.com wrote:

well done nophead. This is a version using my sweep():

use
<Naca_sweep.scad>
$fn=50;
spiral(a1 = 120, a2 = 960, r=22, rc=10);

module spiral(a1=180, a2=720, r=25, rc=10)
{
sweep(gendat(a1, a2, r, rc));
translate(spiral_(a1, r)) sphere(rc);
translate(spiral_(a2, r)) sphere(rc);
}

function gendat(a1=180, a2=720, r=25, rc=10) = let(N=$fn?$fn:360/$fa,
M=ceil((a2-a1)/360N), st = (a2-a1)/M)
[for(i=[0:M]) let(a=i
st+a1) traject(circle_(rc), direction_(a),
spiral_(a, r))]; // compose all trajectory data

function circle_(r=10, n=undef) = let(N=n?n:$fn?$fn:360/$fa, st = 360/N)
[for(i=[0:N-1]) [rcos(ist), 0, rsin(ist)]]; // 2D shape

function spiral_(a, r) = ra/360[sin(a), cos(a)]; // archimedes spiral

function direction_(a, r=10) = let(p1 = spiral_(a-.5, r), p2 =
spiral_(a+.5, r)) (p2-p1)/norm(p2-p1); // direction vector needed for
rotation

function traject(L, v, t) = let(rot = [[v[1], -v[0], 0],[-v[0], v[1], 0],
[0, 0, 1]])
[for(i=L) rot*i+[t[0], t[1], 0]]; // rotate + translate to place circle
into trajectory

--
View this message in context: http://forum.openscad.org/F5-
works-but-not-F6-tp12875p20493.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

Nice. A bit simpler than mine! On 19 February 2017 at 18:53, Parkinbot <rudolf@parkinbot.com> wrote: > well done nophead. This is a version using my sweep(): > > > > use > > <Naca_sweep.scad> > > $fn=50; > > spiral(a1 = 120, a2 = 960, r=22, rc=10); > > > > module spiral(a1=180, a2=720, r=25, rc=10) > > { > > sweep(gendat(a1, a2, r, rc)); > > translate(spiral_(a1, r)) sphere(rc); > > translate(spiral_(a2, r)) sphere(rc); > > } > > > > function gendat(a1=180, a2=720, r=25, rc=10) = let(N=$fn?$fn:360/$fa, > > M=ceil((a2-a1)/360*N), st = (a2-a1)/M) > > [for(i=[0:M]) let(a=i*st+a1) traject(circle_(rc), direction_(a), > > spiral_(a, r))]; // compose all trajectory data > > > > function circle_(r=10, n=undef) = let(N=n?n:$fn?$fn:360/$fa, st = 360/N) > > [for(i=[0:N-1]) [r*cos(i*st), 0, r*sin(i*st)]]; // 2D shape > > > > function spiral_(a, r) = r*a/360*[sin(a), cos(a)]; // archimedes spiral > > > > function direction_(a, r=10) = let(p1 = spiral_(a-.5, r), p2 = > > spiral_(a+.5, r)) (p2-p1)/norm(p2-p1); // direction vector needed for > > rotation > > > > function traject(L, v, t) = let(rot = [[v[1], -v[0], 0],[-v[0], v[1], 0], > > [0, 0, 1]]) > > [for(i=L) rot*i+[t[0], t[1], 0]]; // rotate + translate to place circle > > into trajectory > > > > > > -- > View this message in context: http://forum.openscad.org/F5- > works-but-not-F6-tp12875p20493.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 >
R
Ronaldo
Tue, Feb 21, 2017 3:59 PM

With a bit more code, the spherical caps may be include in the polyhedron
definition. The following code is a self contained specialized sweep for
circular sections with spherical caps. The path can be easily changed from
the spiral to something else. F6 takes virtually nothing and don't crash
when boolean operated if the polyhedron has no self-intersections.

<code> R_ini = 20; R_end = 100; ang_ini = 0; ang_end = 800; long_n = 200; sect_n = 32; diam = 20;

spiral_path = spiral(R_ini, R_end, ang_ini, ang_end, long_n);
spiral_tube = tube(spiral_path, diam/2, sect_n);

difference(){
mesh2poly(spiral_tube);
// uncomment to check F6
//    translate([(R_ini+R_end)/5, (R_ini+R_end)/5, 0]) cube(3*diam);
}

// build a mesh for the whole tube with spherical caps
function tube(path, r, n) =
let( m= len(path),
tube_ = [for(i=[0:m-1] ) // the tube itself
let( pt  = path[i],
// tangent at path[i]
tg  = unit(path[min(i+1,m-1)]-path[max(i-1,0)]),
c  =  tg.y,
s  = -tg.x,
cir = circle_(r, n)[[c,s,0],[-s,c,0],[0,0,1]])
[for(p=cir) p+pt]
],
tgi  = path[0]-path[1],
tgf  = path[m-1]-path[m-2],
capi = spherical_cap(tube_[0],  r
unit(tgi), path[0],  true,
floor(n/4)),
capf = spherical_cap(tube_[m-1], r*unit(tgf), path[m-1], false,
floor(n/4)) )
concat( capi, tube_ , capf );

// a half sphere to close the tube
function spherical_cap(cir, tg, ct, start, n) =
let( m = len(cir),
cir0 = [for(p=cir) p-ct ],
rang = start? [n:-1:0] : [0:n] )
[for(i=rang) let(c=cos(90i/n)cir0, s=sin(90i/n))
[for(p=c) p+s
tg+ct ] ];

// a spiraled path
function spiral(r1, r2, a1, a2, m) =
let( da = (a2-a1)/m )
[for(i=[0:m], ai = a1 + ida, ri = r1 + (r2-r1)i/m )
ri
[cos(ai), sin(ai),0
cos(ai/3)] ];

function circle_(r,n) =
[for(i=[0:n]) r*[cos(360i/n),0,sin(360i/n)]  ] ;

// draw a mesh (matrix of points) as a polyhedron
module mesh2poly(rmesh) {
n = len(rmesh) ;
m = len(rmesh[0]) ;
vertices = [ for(i=[n-1: -1: 0]) for(pt=rmesh[i]) pt ];
tris = concat(  [ for(i=[0:n-2],j=[0:m-2])
[ i*m+j, (i+1)*m+j, (i+1)m+j+1 ] ] ,
[ for(i=[0:n-2],j=[0:m-2])
[ i
m+j, (i+1)m+j+1, im+j+1 ] ] );
polyhedron(vertices, tris);
}

function unit(v) = v/norm(v);
</code>

--
View this message in context: http://forum.openscad.org/F5-works-but-not-F6-tp12875p20523.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

With a bit more code, the spherical caps may be include in the polyhedron definition. The following code is a self contained specialized sweep for circular sections with spherical caps. The path can be easily changed from the spiral to something else. F6 takes virtually nothing and don't crash when boolean operated if the polyhedron has no self-intersections. <code> R_ini = 20; R_end = 100; ang_ini = 0; ang_end = 800; long_n = 200; sect_n = 32; diam = 20; spiral_path = spiral(R_ini, R_end, ang_ini, ang_end, long_n); spiral_tube = tube(spiral_path, diam/2, sect_n); difference(){ mesh2poly(spiral_tube); // uncomment to check F6 // translate([(R_ini+R_end)/5, (R_ini+R_end)/5, 0]) cube(3*diam); } // build a mesh for the whole tube with spherical caps function tube(path, r, n) = let( m= len(path), tube_ = [for(i=[0:m-1] ) // the tube itself let( pt = path[i], // tangent at path[i] tg = unit(path[min(i+1,m-1)]-path[max(i-1,0)]), c = tg.y, s = -tg.x, cir = circle_(r, n)*[[c,s,0],[-s,c,0],[0,0,1]]) [for(p=cir) p+pt] ], tgi = path[0]-path[1], tgf = path[m-1]-path[m-2], capi = spherical_cap(tube_[0], r*unit(tgi), path[0], true, floor(n/4)), capf = spherical_cap(tube_[m-1], r*unit(tgf), path[m-1], false, floor(n/4)) ) concat( capi, tube_ , capf ); // a half sphere to close the tube function spherical_cap(cir, tg, ct, start, n) = let( m = len(cir), cir0 = [for(p=cir) p-ct ], rang = start? [n:-1:0] : [0:n] ) [for(i=rang) let(c=cos(90*i/n)*cir0, s=sin(90*i/n)) [for(p=c) p+s*tg+ct ] ]; // a spiraled path function spiral(r1, r2, a1, a2, m) = let( da = (a2-a1)/m ) [for(i=[0:m], ai = a1 + i*da, ri = r1 + (r2-r1)*i/m ) ri*[cos(ai), sin(ai),0*cos(ai/3)] ]; function circle_(r,n) = [for(i=[0:n]) r*[cos(360*i/n),0,sin(360*i/n)] ] ; // draw a mesh (matrix of points) as a polyhedron module mesh2poly(rmesh) { n = len(rmesh) ; m = len(rmesh[0]) ; vertices = [ for(i=[n-1: -1: 0]) for(pt=rmesh[i]) pt ]; tris = concat( [ for(i=[0:n-2],j=[0:m-2]) [ i*m+j, (i+1)*m+j, (i+1)*m+j+1 ] ] , [ for(i=[0:n-2],j=[0:m-2]) [ i*m+j, (i+1)*m+j+1, i*m+j+1 ] ] ); polyhedron(vertices, tris); } function unit(v) = v/norm(v); </code> -- View this message in context: http://forum.openscad.org/F5-works-but-not-F6-tp12875p20523.html Sent from the OpenSCAD mailing list archive at Nabble.com.