discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

need some help with polyhedron()

M
Mekko
Thu, Dec 17, 2015 3:08 PM

I've been trying to learn polyhedron() by making a cylinder the hard way and
I used Trygon's code for the spring washer to get me started (thanks
Trygon!)

The object renders fine in OpenSCAD but it looks very messed up in MeshLab.
Here are some pictures:
http://imgur.com/a/SCj2R

Is the order of points in a face important? Is the order of faces important?
I'm kind of floundering.

Here's the code:

cyl_rad=30; // outside radius
core_rad=10; // hole radius
height=80; // tube height
layers=20; // layers
segments=20;

function cyl(h) = let(
outer_points=[for(l=[0:layers-1]) for(i=[0:segments-1])
let(a=i360/segments) [cyl_radcos(a), cyl_radsin(a), l(h/layers)]],
inner_points=[for(l=[0:layers-1]) for(i=[0:segments-1])
let(a=i360/segments) [core_radcos(a), core_radsin(a), l(h/layers)]])

[concat(outer_points, inner_points)];

function tops_and_bottoms() = let(
bottoms1=[for(i=[0:segments-1]) let (j=(i+1)%segments) [i, j,
j+layerssegments]],
bottoms2=[for(i=[0:segments-1]) let (j=(i+1)%segments) [i,
i+layers
segments, j+layers*segments]],
tops1=[for(i=[0:segments-1]) let (j=(i+1)%segments)
[i+(layers-1)*segments, j+(layers-1)segments,
j+layers
segments+(layers-1)*segments]],
tops2=[for(i=[0:segments-1]) let (j=(i+1)%segments)
[i+(layers-1)segments, i+layerssegments+(layers-1)segments,
j+layers
segments+(layers-1)*segments]])

[concat(bottoms1, bottoms2, tops1, tops2)]; 

function sides() = [for(l=[0:layers-2]) [for(i=[0:segments-1])
let(j=(i+1)%segments) [
[i+lsegments, j+lsegments, j+(l+1)segments], [i+lsegments,
i+(l+1)*segments, j+(l+1)*segments],
[i+(l+layers)*segments, j+(l+layers)*segments,
j+(l+1+layers)*segments], [i+(l+layers)*segments, i+(l+1+layers)*segments,
j+(l+1+layers)*segments]]]];

function Unpack(p) = [for(i=p) for(j=i) j];

cyl_points=Unpack(cyl(height));

allfaces=concat(Unpack(tops_and_bottoms()), Unpack(Unpack(sides())));

polyhedron(cyl_points, allfaces);

--
View this message in context: http://forum.openscad.org/need-some-help-with-polyhedron-tp15196.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

I've been trying to learn polyhedron() by making a cylinder the hard way and I used Trygon's code for the spring washer to get me started (thanks Trygon!) The object renders fine in OpenSCAD but it looks very messed up in MeshLab. Here are some pictures: http://imgur.com/a/SCj2R Is the order of points in a face important? Is the order of faces important? I'm kind of floundering. Here's the code: cyl_rad=30; // outside radius core_rad=10; // hole radius height=80; // tube height layers=20; // layers segments=20; function cyl(h) = let( outer_points=[for(l=[0:layers-1]) for(i=[0:segments-1]) let(a=i*360/segments) [cyl_rad*cos(a), cyl_rad*sin(a), l*(h/layers)]], inner_points=[for(l=[0:layers-1]) for(i=[0:segments-1]) let(a=i*360/segments) [core_rad*cos(a), core_rad*sin(a), l*(h/layers)]]) [concat(outer_points, inner_points)]; function tops_and_bottoms() = let( bottoms1=[for(i=[0:segments-1]) let (j=(i+1)%segments) [i, j, j+layers*segments]], bottoms2=[for(i=[0:segments-1]) let (j=(i+1)%segments) [i, i+layers*segments, j+layers*segments]], tops1=[for(i=[0:segments-1]) let (j=(i+1)%segments) [i+(layers-1)*segments, j+(layers-1)*segments, j+layers*segments+(layers-1)*segments]], tops2=[for(i=[0:segments-1]) let (j=(i+1)%segments) [i+(layers-1)*segments, i+layers*segments+(layers-1)*segments, j+layers*segments+(layers-1)*segments]]) [concat(bottoms1, bottoms2, tops1, tops2)]; function sides() = [for(l=[0:layers-2]) [for(i=[0:segments-1]) let(j=(i+1)%segments) [ [i+l*segments, j+l*segments, j+(l+1)*segments], [i+l*segments, i+(l+1)*segments, j+(l+1)*segments], [i+(l+layers)*segments, j+(l+layers)*segments, j+(l+1+layers)*segments], [i+(l+layers)*segments, i+(l+1+layers)*segments, j+(l+1+layers)*segments]]]]; function Unpack(p) = [for(i=p) for(j=i) j]; cyl_points=Unpack(cyl(height)); allfaces=concat(Unpack(tops_and_bottoms()), Unpack(Unpack(sides()))); polyhedron(cyl_points, allfaces); -- View this message in context: http://forum.openscad.org/need-some-help-with-polyhedron-tp15196.html Sent from the OpenSCAD mailing list archive at Nabble.com.
NH
nop head
Thu, Dec 17, 2015 3:15 PM

From the manual: "Point ordering for faces When looking at the face from

the outside inwards, the points must be clockwise."

The order of the faces does not matter.

On 17 December 2015 at 15:08, Mekko serve@perdix.org wrote:

I've been trying to learn polyhedron() by making a cylinder the hard way
and
I used Trygon's code for the spring washer to get me started (thanks
Trygon!)

The object renders fine in OpenSCAD but it looks very messed up in MeshLab.
Here are some pictures:
http://imgur.com/a/SCj2R

Is the order of points in a face important? Is the order of faces
important?
I'm kind of floundering.

Here's the code:

cyl_rad=30; // outside radius
core_rad=10; // hole radius
height=80; // tube height
layers=20; // layers
segments=20;

function cyl(h) = let(
outer_points=[for(l=[0:layers-1]) for(i=[0:segments-1])
let(a=i360/segments) [cyl_radcos(a), cyl_radsin(a), l(h/layers)]],
inner_points=[for(l=[0:layers-1]) for(i=[0:segments-1])
let(a=i360/segments) [core_radcos(a), core_radsin(a), l(h/layers)]])

 [concat(outer_points, inner_points)];

function tops_and_bottoms() = let(
bottoms1=[for(i=[0:segments-1]) let (j=(i+1)%segments) [i, j,
j+layerssegments]],
bottoms2=[for(i=[0:segments-1]) let (j=(i+1)%segments) [i,
i+layers
segments, j+layers*segments]],
tops1=[for(i=[0:segments-1]) let (j=(i+1)%segments)
[i+(layers-1)*segments, j+(layers-1)segments,
j+layers
segments+(layers-1)*segments]],
tops2=[for(i=[0:segments-1]) let (j=(i+1)%segments)
[i+(layers-1)segments, i+layerssegments+(layers-1)segments,
j+layers
segments+(layers-1)*segments]])

 [concat(bottoms1, bottoms2, tops1, tops2)];

function sides() = [for(l=[0:layers-2]) [for(i=[0:segments-1])
let(j=(i+1)%segments) [
[i+lsegments, j+lsegments, j+(l+1)segments], [i+lsegments,
i+(l+1)*segments, j+(l+1)*segments],
[i+(l+layers)*segments, j+(l+layers)*segments,
j+(l+1+layers)*segments], [i+(l+layers)*segments, i+(l+1+layers)*segments,
j+(l+1+layers)*segments]]]];

function Unpack(p) = [for(i=p) for(j=i) j];

cyl_points=Unpack(cyl(height));

allfaces=concat(Unpack(tops_and_bottoms()), Unpack(Unpack(sides())));

polyhedron(cyl_points, allfaces);

--
View this message in context:
http://forum.openscad.org/need-some-help-with-polyhedron-tp15196.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

>From the manual: "*Point ordering for faces* When looking at the face from the outside inwards, the points must be clockwise." The order of the faces does not matter. On 17 December 2015 at 15:08, Mekko <serve@perdix.org> wrote: > I've been trying to learn polyhedron() by making a cylinder the hard way > and > I used Trygon's code for the spring washer to get me started (thanks > Trygon!) > > The object renders fine in OpenSCAD but it looks very messed up in MeshLab. > Here are some pictures: > http://imgur.com/a/SCj2R > > Is the order of points in a face important? Is the order of faces > important? > I'm kind of floundering. > > Here's the code: > > cyl_rad=30; // outside radius > core_rad=10; // hole radius > height=80; // tube height > layers=20; // layers > segments=20; > > > function cyl(h) = let( > outer_points=[for(l=[0:layers-1]) for(i=[0:segments-1]) > let(a=i*360/segments) [cyl_rad*cos(a), cyl_rad*sin(a), l*(h/layers)]], > inner_points=[for(l=[0:layers-1]) for(i=[0:segments-1]) > let(a=i*360/segments) [core_rad*cos(a), core_rad*sin(a), l*(h/layers)]]) > > [concat(outer_points, inner_points)]; > > > function tops_and_bottoms() = let( > bottoms1=[for(i=[0:segments-1]) let (j=(i+1)%segments) [i, j, > j+layers*segments]], > bottoms2=[for(i=[0:segments-1]) let (j=(i+1)%segments) [i, > i+layers*segments, j+layers*segments]], > tops1=[for(i=[0:segments-1]) let (j=(i+1)%segments) > [i+(layers-1)*segments, j+(layers-1)*segments, > j+layers*segments+(layers-1)*segments]], > tops2=[for(i=[0:segments-1]) let (j=(i+1)%segments) > [i+(layers-1)*segments, i+layers*segments+(layers-1)*segments, > j+layers*segments+(layers-1)*segments]]) > > [concat(bottoms1, bottoms2, tops1, tops2)]; > > function sides() = [for(l=[0:layers-2]) [for(i=[0:segments-1]) > let(j=(i+1)%segments) [ > [i+l*segments, j+l*segments, j+(l+1)*segments], [i+l*segments, > i+(l+1)*segments, j+(l+1)*segments], > [i+(l+layers)*segments, j+(l+layers)*segments, > j+(l+1+layers)*segments], [i+(l+layers)*segments, i+(l+1+layers)*segments, > j+(l+1+layers)*segments]]]]; > > > function Unpack(p) = [for(i=p) for(j=i) j]; > > cyl_points=Unpack(cyl(height)); > > allfaces=concat(Unpack(tops_and_bottoms()), Unpack(Unpack(sides()))); > > polyhedron(cyl_points, allfaces); > > > > -- > View this message in context: > http://forum.openscad.org/need-some-help-with-polyhedron-tp15196.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 >
M
Mekko
Thu, Dec 17, 2015 5:45 PM

Aargh! Thanks for your patience, nophead - that's the politest RTFM I think
I've ever read.

Sorry to waste everyone's time!

I should have read the manual more carefully and I would have if OpenSCAD
had flagged that something was wrong. Or if it had rendered all messed up
like MeshLab.

--
View this message in context: http://forum.openscad.org/need-some-help-with-polyhedron-tp15196p15198.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Aargh! Thanks for your patience, nophead - that's the politest RTFM I think I've ever read. Sorry to waste everyone's time! I should have read the manual more carefully and I would have if OpenSCAD had flagged that something was wrong. Or if it had rendered all messed up like MeshLab. -- View this message in context: http://forum.openscad.org/need-some-help-with-polyhedron-tp15196p15198.html Sent from the OpenSCAD mailing list archive at Nabble.com.
NH
nop head
Thu, Dec 17, 2015 5:51 PM

If you press F12 it will show the reversed faces in purple in the "Thrown
together view". Not sure why it doesn't always do that, presumably it's a
performance issue.

On 17 December 2015 at 17:45, Mekko serve@perdix.org wrote:

Aargh! Thanks for your patience, nophead - that's the politest RTFM I think
I've ever read.

Sorry to waste everyone's time!

I should have read the manual more carefully and I would have if OpenSCAD
had flagged that something was wrong. Or if it had rendered all messed up
like MeshLab.

--
View this message in context:
http://forum.openscad.org/need-some-help-with-polyhedron-tp15196p15198.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

If you press F12 it will show the reversed faces in purple in the "Thrown together view". Not sure why it doesn't always do that, presumably it's a performance issue. On 17 December 2015 at 17:45, Mekko <serve@perdix.org> wrote: > Aargh! Thanks for your patience, nophead - that's the politest RTFM I think > I've ever read. > > Sorry to waste everyone's time! > > I should have read the manual more carefully and I would have if OpenSCAD > had flagged that something was wrong. Or if it had rendered all messed up > like MeshLab. > > > > -- > View this message in context: > http://forum.openscad.org/need-some-help-with-polyhedron-tp15196p15198.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 >