

Hello,
I'm relatively new to OpenScad and are working on my first bigger project
right now.
There the following question came up for which I tried to search for
existing discussions here, without success
Is it possible to place a polygon in 3D space and not only on the x/yplane?
I would like to have a polygon with its vertices (points) at defined
coordinates in 3D space (x,y,z) and then to linearextrude this polygon. Do I
have to use a polyhedron instead? If I got it correctly from the polyhedron
description it cannot be flat, so I have to "linearextrude" it myself by
placing all the vertices at the correct positions in 3D space and not only
my known vertices of the base face.
Any ideas?
Thanks a lot in advance,
Thomas

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


I'm far from a wizard when it comes to openSCAD, but terminology and
application is important. For the purposes of this discussion, one must
consider that a polygon is a multisided shape on a flat plane. Once created
using the polygon command, one can rotate it in 3space. If you extrude it
as part of the operation, you can rotate it as well.
Moving to another part of your question, if your objective is a solid that
is going to have specific points in space, you can pick any three to make a
plane and use those points to create polyhedra.
I'm not sure about your reference suggesting that the polyhedron description
not be flat, as the wiki specifies that "faces" must be in the same plane,
which implies that they are flat.
When you suggest to use linear_extrude, do you require/desire to have
vertical sides prior to any rotation?

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


Thomas,
You can only define polygons in 2d space, but this shouldn’t be too much of a limitation. All points in a polygon must be on the same plane, so if you defined it in 3d space, it would be easy to have an invalid polygon.
The best way to do what you want is probably:  Given your set of 3d points, compute a transform so they all lay on the plane
 Use polygon() to render that set of points
 Use linear_extrude() to create a 3d shape from those points
 Apply the inverse of the original transform to put the 3d shape into place
Hello, I'm relatively new to OpenScad and are working on my first bigger project right now. There the following question came up for which I tried to search for existing discussions here, without success Is it possible to place a polygon in 3D space and not only on the x/yplane? I would like to have a polygon with its vertices (points) at defined coordinates in 3D space (x,y,z) and then to linearextrude this polygon. Do I have to use a polyhedron instead? If I got it correctly from the polyhedron description it cannot be flat, so I have to "linearextrude" it myself by placing all the vertices at the correct positions in 3D space and not only my known vertices of the base face. Any ideas? Thanks a lot in advance, Thomas  Sent from: http://forum.openscad.org/_______________________________________________ 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


Maybe let's start my question in another way. For example, we have four
vertices [2, 2, 2], [2, 8, 8], [7, 2, 2], [7, 8, 8] and let's create a face
between them and "linearextrude" this.
It is important to have such four vertices at exact the mentioned positions.
How would you create the 3D object? Please also consider that it is not
ensured that all four vertices are placed so "friendly" as in the example,
they could also be somehow rotatet in space.
Is there a way to create the 3D object which has its four bottom vertices at
the given coordinates without a lot of calculations and
transforming/rotating a cube?
fred_dot_u wrote
> I'm not sure about your reference suggesting that the polyhedron
> description
> not be flat, as the wiki specifies that "faces" must be in the same plane,
> which implies that they are flat.
>
> When you suggest to use linear_extrude, do you require/desire to have
> vertical sides prior to any rotation?
>
>
>
> 
> Sent from: http://forum.openscad.org/>
> _______________________________________________
> OpenSCAD mailing list
> Discuss@.openscad
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Sent from: http://forum.openscad.org/_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


This sounds like an interesting solution, thanks
However, has anyone an even simpler solution?
Hypher wrote
> The best way to do what you want is probably:
> Given your set of 3d points, compute a transform so they all lay on the
> plane
> Use polygon() to render that set of points
> Use linear_extrude() to create a 3d shape from those points
> Apply the inverse of the original transform to put the 3d shape into place

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


Well, if you don't mind the extra faces, this is pretty simple:
hull() for(p=[[2,2,2], [2,8,8], [7,2,2], [7,8,8]]) translate(p) cube(0.000002, true);
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


A polygon in OpenSCAD is always a 2D shape on the XY plane. You should not apply geometric transformations on it that take it away from the XY plane or you will be in trouble. For instance:
Additionally, you are allowed to linear_extrude 2D polygons only.
Following @Appletree, you should define your polygon in the XY plane, extrude it and then move/rotate the 3D shape to the position you want it. You can't avoid geometric transformations in this case. If you find the normal vector of the plane containing the input 3D points ( a cross product) the geometric transformations will be simple to compute: p=[[2,2,2], [2,8,8], [7,8,8], [7,2,2]]; rot = frotFromTo(nrm,[0,0,1]); // compute the rotation to the XY plane pxy = [for(pi=p) rot*pi]; // rotate the points to XY plane p2d = [for(pxyi=pxy) [pxyi[0],pxyi[1]]]; // projects on 2D // normal to the triangle [ p[0], p[1], p[2] ] function normal(p) = cross(p[1]p[0], p[2]p[1]); // matrix of the transformation of mirroring along a direction norm(v)==0 ? [[1,0,0],[0,1,0],[0,0,1]] : [ [1,0,0]  2*u[0]*u, [0,1,0]  2*u[1]*u, [0,0,1]  2*u[2]*u ]; // matrix of the minimum rotation that brings the vector di to the direction do function frotFromTo(di,do) = norm(dido)==0  norm(di)==0  norm(do)==0 ? [[1,0,0],[0,1,0],[0,0,1]] : fmirror(do/norm(do)+di/norm(di)) * fmirror(di); // the minimum rotation that brings the vector di to the direction do if( norm(dido)==0  norm(di)==0  norm(do)==0 ) mirror(do/norm(do)+di/norm(di)) mirror(di) children();
This code does not check if the input points are coplanar. Anyway, it generates a valid solid provided the first three input points are not colinear.
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


On 20171011 22:39, thomashn wrote:
> Is it possible to place a polygon in 3D space and not only on the
> x/yplane?
As others have indicated, a polygon is a 2d entity that by definition in
OpenSCAD exists in the XY plane. This could be seen as a specialization
of the mathematical term "polygon".
You may perhaps want to look at OpenSCAD polyhedron instead, which uses
3d coordinates. It is supposed to have flat faces that are in fact
mathematical polygons.
Carsten Arnholm
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


My last code works because the plane through the input points contains the origin. In a general case, we need to do translations besides the rotations. Two additional code lines solves this issue.
p=[[2,2,2+10], [2,8,8+10], [7,8,8+10], [7,2,2+10]]; // changed to not be coplanar with the origin rot = frotFromTo(nrm,[0,0,1]); // compute the rotation to the XY plane pxy = [for(pi=p) rot*pi]; // rotate the points to XY plane p2d = [for(pxyi=pxy) [pxyi[0],pxyi[1]]]; // projects on 2D dis = pxy[0][2]; // compute the displacement of the projection translate([0,0,dis]) // translate it back hull() for(pi=p) translate(pi) cube(0.0001,center=true);
The red polygon is drawn here as a check reference of the input polygon.
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


Hi Thomas,
degenerate faces and degenerate polyhedra are quite useful for what you want
to do.
A flat, degenerate polyhedron can be generated from even more degenerate
triangles like this:
module polyhedrify_points(points) {
faces = [for(i=[0:len(points)1]) [i,i,i]];
hull()
polyhedron(points, faces);
}
polyhedrify_points([[2,2,2], [2,8,8], [7,2,2], [7,8,8]]);
// Or for a nondegenerate result:
//polyhedrify_points([[2,2,2], [2,8,8], [7,2,2], [7,8,8], [0,0,10]]);
From the above it is trivial to linear extrude by some vector v.
One way for this is to hull with the translated result:
hull()
for(i=[0,1])
translate(i*[2,6,0])
polyhedrify_points([[2,2,2], [2,8,8], [7,2,2], [7,8,8]]);
Degenerate faces and degenerate polyhedra are not documented in OpenSCAD.
So I am not sure if the above will remain possible in all future versions.
Maybe someone can tell. I am using 2015.032.
Martin
www.panohero.de

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

