Removing all surfaces in the X-Y Plane

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

Removing all surfaces in the X-Y Plane

hsafti
Dear all,

I am an inexperienced OpenSCAD user. I would like to prepare an STL file for a 2D simulation in OpenFOAM using cfMesh's cartesian2DMesh generator (if you can suggest a workflow I would appreciate it). Whats is needed is a ribbon surface that represents the out-of-plane extrude. This means that if my 2D simulation has the Z-axis as the out-of-plane axis, then I need to have the X-axis direction on all surfaces. My geometry is simple I create a union of a couple of cubes. How can I then remove the X-Y plane surfaces of the union. I would like to avoid inputting the points with their coordinates directly to reduce overhead calculations and maintain things parametric. So if you know the magic trick, I would really appreciate it!

Best regards,
Hisham 

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

Re: Removing all surfaces in the X-Y Plane

leebc
I'm not entirely clear on what you're asking.

Does
        projection()
        https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/3D_to_2D_Projection
Do what you're looking for?
With "projection(cut=true)" you can slice a model into layers.


Or, if you want the entire model, maybe
        resize()
        https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Transformations#resize
with one dimension set to "0.0001"?  But I think that gives you the same
thing as "projection(cut=false)"...


Thus Hisham Elsafti hast written on Wed, Jan 08, 2020 at 11:42:43AM +0100, and, according to prophecy, it shall come to pass that:

> Dear all,
>
> I am an inexperienced OpenSCAD user. I would like to prepare an STL file
> for a 2D simulation in OpenFOAM using cfMesh's cartesian2DMesh generator
> (if you can suggest a workflow I would appreciate it). Whats is needed is a
> ribbon surface that represents the out-of-plane extrude. This means that if
> my 2D simulation has the Z-axis as the out-of-plane axis, then I need to
> have the X-axis direction on all surfaces. My geometry is simple I create a
> union of a couple of cubes. How can I then remove the X-Y plane surfaces of
> the union. I would like to avoid inputting the points with their
> coordinates directly to reduce overhead calculations and maintain things
> parametric. So if you know the magic trick, I would really appreciate it!
>
> Best regards,
> Hisham

> _______________________________________________
> 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: Removing all surfaces in the X-Y Plane

alexgibson
Hi Hisham

As Bryan mentioned, projection() has several modes, one of which might do
the job for you, but I'm also struggling to understand exactly what you need
to achieve here.

Without worrying too much about the purpose, can you describe what is the
output that you are looking to get from OpenSCAD, and what is the source
material?  

Pictures/screenshots welcome!

Cheers,

Alex Gibson

admg consulting

edumaker limited

. Project management
. Operations & Process improvement
. 3D Printing


-----Original Message-----
From: Discuss [mailto:[hidden email]] On Behalf Of Bryan
Lee
Sent: 08 January 2020 10:55
To: OpenSCAD general discussion
Subject: Re: [OpenSCAD] Removing all surfaces in the X-Y Plane

I'm not entirely clear on what you're asking.

Does
        projection()
       
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/3D_to_2D_Projection
Do what you're looking for?
With "projection(cut=true)" you can slice a model into layers.


Or, if you want the entire model, maybe
        resize()
       
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Transformations#resize
with one dimension set to "0.0001"?  But I think that gives you the same
thing as "projection(cut=false)"...


Thus Hisham Elsafti hast written on Wed, Jan 08, 2020 at 11:42:43AM +0100,
and, according to prophecy, it shall come to pass that:
> Dear all,
>
> I am an inexperienced OpenSCAD user. I would like to prepare an STL file
> for a 2D simulation in OpenFOAM using cfMesh's cartesian2DMesh generator
> (if you can suggest a workflow I would appreciate it). Whats is needed is
a
> ribbon surface that represents the out-of-plane extrude. This means that
if
> my 2D simulation has the Z-axis as the out-of-plane axis, then I need to
> have the X-axis direction on all surfaces. My geometry is simple I create
a
> union of a couple of cubes. How can I then remove the X-Y plane surfaces
of
> the union. I would like to avoid inputting the points with their
> coordinates directly to reduce overhead calculations and maintain things
> parametric. So if you know the magic trick, I would really appreciate it!
>
> Best regards,
> Hisham

> _______________________________________________
> 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


--
This email has been checked for viruses by AVG.
https://www.avg.com


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

Re: Removing all surfaces in the X-Y Plane

hsafti
Hi guys,

Thanks a lot for your quick response. I am sorry for struggling to explain
myself. If you consider page 4 of this document
http://cfmesh.com/wp-content/uploads/2015/09/User_Guide-cfMesh_v1.1.pdf I
would like to turn a volume enclosed shape like Fig. 5 into a hollow shape
like Fig.4. Because all side surfaces are X-Y plane surfaces, I thought it
might be a useful condition.

I think projection may not be the optimum solution but it is nice to know
this capability.

I produce a union of several cubes:

<code>
union(){
    translate(v=[-6, -0.1, -0.005]){
        cube(size=[21, 0.2, 1.01]);
    };
    translate(v=[0, 0.1, -0.005]){
        cube(size=[0.2, 3.0, 1.01]);
    };
    translate(v=[-5.0, 3.1, -0.005]){
        cube(size=[10, 10, 1.01]);
    };
};
</code>

And would like to export only the outer surface and delete the front and
back surfaces!

Best regards,
Hisham



--
Sent from: http://forum.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: Removing all surfaces in the X-Y Plane

alexgibson
Hi Hisham, that makes sense.

So you're trying to remove the top and bottom face of an STL, leaving the
sides intact, deliberately producing a non-manifold object.

If you're trying to do this as a one-off, the quickest way is to download
'meshmixer', open the exported STL file from OpenSCAD, select the triangles
on the surfaces you don't want and hit delete.

If you need to do this for a batch of files and make a workflow, you could
use this:  https://www.thingiverse.com/thing:62666

It's an STL file to OpenSCAD converter - takes an STL mesh and turns it into
an OpenSCAD code polygon.  You could then edit that polygon to remove all
the faces where all points are on the same Z height (IE they are flat on the
XY plane).  Not sure if it will produce an error if you try to render the
STL as it will certainly be non-manifold, but if it works it's highly
reproducible...

Cheers,

Alex Gibson

admg consulting

edumaker limited

. Project management
. Operations & Process improvement
. 3D Printing


-----Original Message-----
From: Discuss [mailto:[hidden email]] On Behalf Of
hsafti
Sent: 08 January 2020 12:06
To: [hidden email]
Subject: Re: [OpenSCAD] Removing all surfaces in the X-Y Plane

Hi guys,

Thanks a lot for your quick response. I am sorry for struggling to explain
myself. If you consider page 4 of this document
http://cfmesh.com/wp-content/uploads/2015/09/User_Guide-cfMesh_v1.1.pdf I
would like to turn a volume enclosed shape like Fig. 5 into a hollow shape
like Fig.4. Because all side surfaces are X-Y plane surfaces, I thought it
might be a useful condition.

I think projection may not be the optimum solution but it is nice to know
this capability.

I produce a union of several cubes:

<code>
union(){
    translate(v=[-6, -0.1, -0.005]){
        cube(size=[21, 0.2, 1.01]);
    };
    translate(v=[0, 0.1, -0.005]){
        cube(size=[0.2, 3.0, 1.01]);
    };
    translate(v=[-5.0, 3.1, -0.005]){
        cube(size=[10, 10, 1.01]);
    };
};
</code>

And would like to export only the outer surface and delete the front and
back surfaces!

Best regards,
Hisham



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


--
This email has been checked for viruses by AVG.
https://www.avg.com


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

Re: Removing all surfaces in the X-Y Plane

OpenSCAD mailing list-2
Another option that might be even easier is to use the Inkscape (free, multi-platform) svg editor with the Path to OpenSCAD extension installed.


It has a somewhat documented feature in that an open path generates a user-specified wall thickness line rather than an enclosed polygon/path. This means that if you create a path such as in figure 4 but don't close the end, merely overlap the lines, then use the extension to create an OpenSCAD output, it will be identical to figure 4. Because of the user-specified wall thickness, it's still a 3-dimensional object.

The creator of the extension states that he will not be supporting/developing the extension, as it is native in the newest version of Inkscape. This would require the process to be changed within Inkscape to offset the original drawing to create the "thin-wall" extrusion.

Of course if a thin wall is unacceptable, the real answer remains Meshmixer.

Another work flow option in Meshmixer is to use the Edit/Plane Cut feature and select No Fill, then slice away the top and bottom of the envelope. It's a good bit faster for those shapes which permit entire planes to be vaporized.




The suggestion for Meshmixer was one that popped into my alleged mind too, as the methodology described is spot on.

On Wednesday, January 8, 2020, 7:27:50 AM EST, Alex Gibson <[hidden email]> wrote:


Hi Hisham, that makes sense.

So you're trying to remove the top and bottom face of an STL, leaving the
sides intact, deliberately producing a non-manifold object.

If you're trying to do this as a one-off, the quickest way is to download
'meshmixer', open the exported STL file from OpenSCAD, select the triangles
on the surfaces you don't want and hit delete.

If you need to do this for a batch of files and make a workflow, you could
use this:  https://www.thingiverse.com/thing:62666

It's an STL file to OpenSCAD converter - takes an STL mesh and turns it into
an OpenSCAD code polygon.  You could then edit that polygon to remove all
the faces where all points are on the same Z height (IE they are flat on the
XY plane).  Not sure if it will produce an error if you try to render the
STL as it will certainly be non-manifold, but if it works it's highly
reproducible...

Cheers,

Alex Gibson



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

Re: Removing all surfaces in the X-Y Plane

cbernhardt
In reply to this post by hsafti
I wrote a program to read and write STL files that works inside AutoCAD.  The
program colors the triangles based on the Z value of the normal vector of
each triangle.  For your purpose (I think) that you want to eliminate all
triangles that have non zero Z values for the normal vector.  Doing so will
produce a model that looks like the attached picture.   If you are somewhat
experienced in programming you could write a program that reads the STL file
and eliminates the triangles that have non zero Z values in their normal
vectors.
If you are not into programming you can open the STL file ( as long as it is
an ASCII file) in a text editor and erase all the triangles that do not have
“0” (zero) as the last number in the line that begins with “facet normal”
For example, here are several lines from the STL file produced by your
OpenSCAD code:
  facet normal -1 -0 0
    outer loop
      vertex -6 0.0999994 1.005
      vertex -6 -0.0999994 -0.00499916
      vertex -6 -0.0999994 1.005
    endloop
  endfacet
  facet normal 0 0 1
    outer loop
      vertex 5 13.1 1.005
      vertex 0.2 3.1 1.005
      vertex 5 3.1 1.005
    endloop
  endfacet

For your purpose erase the line that reads “facet normal 0 0 1” and the
following 6 lines.  This will erase a single triangle.  Continue editing the
entire file and erase all triangles that do not have a “0” as the last digit
in the facet normal line.
I cannot seem to get the Insert Image function to work, so here is a link to
the modified STL file and image.
http://www.carols62.com/test3.stl
http://www.carols62.com/test3.jpg




--
Sent from: http://forum.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: Removing all surfaces in the X-Y Plane

hsafti
Dear all,

Thanks a lot for all your help and support and congratulations on this
really active community spirit. It is in fact the motivation behind using
OpenSCAD to use it inside Python scripts to automate preprocessing. I even
use openpyscad which to my experience does not support the projection method
(not bad, I can still make and call an openScad script if needed). Using an
external tool manually will kill the purpose of the whole thing. I am
currently considering planning to use Python's meshio library to
conviniently read the stl file, filter points with z>0 and consider only
surfaces with verticies only from the remaining points, rewrite as stl or
some other format. Theoretically this should work but you all know how these
things go south in reality :D

So thanks again to all!

Best regards,
Hisham  



--
Sent from: http://forum.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: Removing all surfaces in the X-Y Plane

hsafti
Sorry .. Just came tired from work! Of course I will remove surfaces based on
surface normal or use a utility from cfMesh that produces the surface I need
from an X-Y planar sketch ... This is maybe why both ideas got mixed in my
head!



--
Sent from: http://forum.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: Removing all surfaces in the X-Y Plane

alexgibson
In reply to this post by hsafti
So a manual edit in Meshmixer would be out of the picture.

You are already aware of automating OpenSCAD - do you use the command line
instance of OpenSCAD?

So this can get you a folder-full of STL files.

'All' you need to do is in Python or something else (I have used GREP or
even MS Excel before, have very patchy programming skills!) parse the STL
files in an automation script.
You would only need to identify and delete each triangle where ALL 3 points
have the same Z value.

Good luck!

Alex Gibson

admg consulting

edumaker limited

. Project management
. Operations & Process improvement
. 3D Printing


-----Original Message-----
From: Discuss [mailto:[hidden email]] On Behalf Of
hsafti
Sent: 09 January 2020 18:21
To: [hidden email]
Subject: Re: [OpenSCAD] Removing all surfaces in the X-Y Plane

Dear all,

Thanks a lot for all your help and support and congratulations on this
really active community spirit. It is in fact the motivation behind using
OpenSCAD to use it inside Python scripts to automate preprocessing. I even
use openpyscad which to my experience does not support the projection method
(not bad, I can still make and call an openScad script if needed). Using an
external tool manually will kill the purpose of the whole thing. I am
currently considering planning to use Python's meshio library to
conviniently read the stl file, filter points with z>0 and consider only
surfaces with verticies only from the remaining points, rewrite as stl or
some other format. Theoretically this should work but you all know how these
things go south in reality :D

So thanks again to all!

Best regards,
Hisham  



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


--
This email has been checked for viruses by AVG.
https://www.avg.com


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

Re: Removing all surfaces in the X-Y Plane

hsafti
Hi Alex and all,

Thanks again for your helpful tips. Python saves the day once more. Using
the numpy-stl library, one can do this short code:


import numpy
from stl import mesh

mesh3D = mesh.Mesh.from_file('mesh3D.stl')

indecies=[]
for i in range(len(mesh3D.normals)):
    if mesh3D.normals[i][2] ==0:
        indecies.append(i)

verticeCount = len(indecies)
data = numpy.zeros(verticeCount, dtype=mesh.Mesh.dtype)

mesh2D = mesh.Mesh(data, remove_empty_areas=False)

for k in range(verticeCount):
    mesh2D.v0[k] = mesh3D.v0[indecies[k]]
    mesh2D.v1[k] = mesh3D.v1[indecies[k]]
    mesh2D.v2[k] = mesh3D.v2[indecies[k]]

mesh2D.save('mesh2D.stl')


Thanks again and until next time ;-)

<http://forum.openscad.org/file/t2716/result.png>



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org