A faces( ) function for simple polyhedra

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

A faces( ) function for simple polyhedra

runsun
This post was updated on .
Just released a faces.scad that can generate faces for simple polyhedra:
https://github.com/runsun/faces.scad

This is part of a lib that I am working on. During my course of learning polyhedron, the faces is the most frustrating obstacle. So I think that I'd make my face() a stand-alone lib so this might help people like me.

This lib currently only supports 5 very basic polyhedra. And it use 4-point faces. I do hope that, in the future, openscad will consider having a better faces() as the builtin.

The function api:
faces( shape  // cubesides|rod|chain|ring|tube
     , nside  // # of sides
     , nseg   // # of segments for chain
     )
Its currently-supported 5 shapes are demonstrated below. The points, pts are given in the example files in the release. The construction of those pts is beyond the scope of this work.

cubesides

  cubesides

  Needed for building other shape faces.
f=faces( "cubesides", nside=4 );
polyhedron( points=pts, faces=f );
rod

  rod

  Same as a cylinder
polyhedron( points=pts, faces=faces( "rod", nside=4 ));
polyhedron( points=pts , faces=faces( "rod", nside=6 ));
tube

  tube

f=faces( "tube", nside=20 );
polyhedron( points= pts , faces=f );
chain

  chain

f=faces( "chain", nside=4, nseg=5 );
polyhedron( points=pts, faces=f );
ring

  ring

  A ring is like a closed chain.
f=faces( "ring", nside=4, nseg=10 );
polyhedron( points=pts, faces= f );
$ Runsun Pan, PhD
$ libs: scadx, doctest, faces(git), offline doc(git), runscad.py(2,git), editor of choice: CudaText ( OpenSCAD lexer); $ Tips; $ Snippets
Reply | Threaded
Open this post in threaded view
|

Re: A faces( ) function for simple polyhedrons

louijp
Hi runsun,

Nice utilities.
I downloaded your file faces.scad, and tested it with the latest mac OS X version.
The preview work fine, but the rendering fails when trying to render the ring.
This happen using showall();

when loading, the console looks like below:

 Compiling design (CSG Tree generation)...
ECHO: ""
ECHO: "ring_faces ( "darkslategray" )"
ECHO: "cubesides_faces ( "olive" )"
ECHO: "rod_faces1 ( "olive" )"
ECHO: "rod_faces2 ( "red" )"
ECHO: "tube_faces ( "green" )"
ECHO: "chain_faces ( "darkcyan" )"
ECHO: ""
Compiling design (CSG Products generation)...
Geometries in cache: 6
Geometry cache size in bytes: 16752
CGAL Polyhedrons in cache: 0
CGAL cache size in bytes: 0
Compiling design (CSG Products normalization)...
Normalized CSG tree has 6 elements
Compile and preview finished.
Total rendering time: 0 hours, 0 minutes, 0 seconds


When rendering, I get:

 Compiling design (CSG Tree generation)...
ECHO: ""
ECHO: "ring_faces ( "darkslategray" )"
ECHO: "cubesides_faces ( "olive" )"
ECHO: "rod_faces1 ( "olive" )"
ECHO: "rod_faces2 ( "red" )"
ECHO: "tube_faces ( "green" )"
ECHO: "chain_faces ( "darkcyan" )"
ECHO: ""
Rendering Polygon Mesh using CGAL...
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: /Users/kintel/code/OpenSCAD/openscad/../libraries/install/include/CGAL/Nef_S2/SM_const_decorator.h Line: 326
PolySet has nonplanar faces. Attempting alternate construction
PolySet has nonplanar faces. Attempting alternate construction
PolySet has nonplanar faces. Attempting alternate construction
Geometries in cache: 20
Geometry cache size in bytes: 50256
CGAL Polyhedrons in cache: 2
CGAL cache size in bytes: 616688
Total rendering time: 0 hours, 0 minutes, 0 seconds
   Top level object is a 3D object:
   Simple:         no
   Vertices:      132
   Halfedges:     734
   Edges:         367
   Halffacets:    482
   Facets:        241
   Volumes:         5
WARNING: Object may not be a valid 2-manifold and may need repair!
Rendering finished.

All the object are rendered except the ring.


Regards,
Jean-Paul
AC9GH

> On Jun 6, 2015, at 4:31 AM, runsun <[hidden email]> wrote:
>
> Just released a faces.scad that can generate faces for simple polyhedrons:
> https://github.com/runsun/faces.scad/blob/master/faces.scad.
>
> This is part of a lib that I am working on. During my course of learning polyhedron, the faces is the most frustrating obstacle. So I think that I'd make my face() a stand-alone lib so this might help people like me.
>
> This lib currently only supports 5 very basic polyhedrons. And it use 4-point faces. I do hope that, in the future, openscad will consider having a better faces() as the builtin.
>
> The function api:
> faces( shape  // cubesides|rod|chain|ring|tube
>      , nside  // # of sides
>      , nseg   // # of segments for chain
>      )
>
> Its currently-supported 5 shapes are demonstrated below. The points, pts are given in the example files in the release. The construction of those pts is beyond the scope of this work.
>
>
>   cubesides
>
>   Needed for building other shape faces.
> f=faces( "cubesides", nside=4 );
> polyhedron( points=pts, faces=f );
>
>
>   rod
>
>   Same as a cylinder
> polyhedron( points=pts, faces=faces( "rod", nside=4 ));
> polyhedron( points=pts , faces=faces( "rod", nside=6 ));
>
>
>   tube
>
> f=faces( "tube", nside=20 );
> polyhedron( points= pts , faces=f );
>
>
>   chain
>
> f=faces( "chain", nside=4, nseg=5 );
> polyhedron( points=pts, faces=f );
>
>
>   ring
>
>   A ring is like a closed chain.
> f=faces( "ring", nside=4, nseg=10 );
> polyhedron( points=pts, faces= f );
>
> $ Runsun Pan, PhD
> $ -- OpenScad_DocTest: doc and unit test ( Github, Thingiverse )
> $ -- hash parameter model: here, here
> $ -- Linux Mint 17.1 Rebecca x64 + OpenSCAD 2015.03.15/2015.04.01.nightly
>
> View this message in context: A faces( ) function for simple polyhedrons
> Sent from the OpenSCAD mailing list archive at Nabble.com.
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: A faces( ) function for simple polyhedrons

runsun
I believe the error is trying to render two or more separate objects.

Try do this:

module showall(){
    cubesides_faces("olive");
    rod_faces1("olive");
}    

and it still gives you the same rendering error.

Render them one at a time will be ok.
$ Runsun Pan, PhD
$ libs: scadx, doctest, faces(git), offline doc(git), runscad.py(2,git), editor of choice: CudaText ( OpenSCAD lexer); $ Tips; $ Snippets
Ivo
Reply | Threaded
Open this post in threaded view
|

Re: A faces( ) function for simple polyhedrons

Ivo
In reply to this post by runsun
runsun wrote
<br/>
The function api:

<code style="font-size:13px"><pre>faces( shape  // cubesides|rod|chain|ring|tube
     , nside  // # of sides
     , nseg   // # of segments for chain
     )</pre></code>
This would be a great way discourage / deprecate the nasty $fs=6 i've seen in models where hexagons are created by degrading the quality of cylinders.

imho $fa, $fs and $fn should only be user to control the rendering resolution of quality.

Cheers, Ivo