discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

How to draw a polygon one line at a time?

J
jamcultur
Sun, Jun 16, 2019 8:40 PM

I'm working on a program to generate a polygon based on values set in the
customizer. I don't know ahead of time how many points the polygon will
have, and there could be hundreds of them, so I'd like to generate the
polygon one line segment at a time. Is there a way to do this?
Thank you!

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

I'm working on a program to generate a polygon based on values set in the customizer. I don't know ahead of time how many points the polygon will have, and there could be hundreds of them, so I'd like to generate the polygon one line segment at a time. Is there a way to do this? Thank you! -- Sent from: http://forum.openscad.org/
A
adrianv
Mon, Jun 17, 2019 1:54 AM

jamcultur wrote

I'm working on a program to generate a polygon based on values set in the
customizer. I don't know ahead of time how many points the polygon will
have, and there could be hundreds of them, so I'd like to generate the
polygon one line segment at a time. Is there a way to do this?

I don't understand what you're trying to do here.  I mean, you could form a
convex polygon as a union of triangles formed relative to a center point.
But maybe it makes more sense to somehow build up the list of points
somehow?  You don't indicate clearly where the polygon points come from.
Programming in OpenSCAD doesn't permit you do create a list by extending it
a point at a time: you need to do it either with a loop all at once, or
recursively.

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

jamcultur wrote > I'm working on a program to generate a polygon based on values set in the > customizer. I don't know ahead of time how many points the polygon will > have, and there could be hundreds of them, so I'd like to generate the > polygon one line segment at a time. Is there a way to do this? I don't understand what you're trying to do here. I mean, you could form a convex polygon as a union of triangles formed relative to a center point. But maybe it makes more sense to somehow build up the list of points somehow? You don't indicate clearly where the polygon points come from. Programming in OpenSCAD doesn't permit you do create a list by extending it a point at a time: you need to do it either with a loop all at once, or recursively. -- Sent from: http://forum.openscad.org/
J
jamcultur
Mon, Jun 17, 2019 3:05 AM

adrianv wrote

jamcultur wrote

I'm working on a program to generate a polygon based on values set in the
customizer. I don't know ahead of time how many points the polygon will
have, and there could be hundreds of them, so I'd like to generate the
polygon one line segment at a time. Is there a way to do this?

I don't understand what you're trying to do here.  I mean, you could form
a
convex polygon as a union of triangles formed relative to a center point.
But maybe it makes more sense to somehow build up the list of points
somehow?  You don't indicate clearly where the polygon points come from.
Programming in OpenSCAD doesn't permit you do create a list by extending
it
a point at a time: you need to do it either with a loop all at once, or
recursively.

The polygon may not be convex, so the union of triangles relative to a
central point wouldn't work. The polygon points are calculated based on user
input from the customizer. I could build a list of points based on the
user's input, but I don't know ahead of time how long that list will be. It
is a shame the OpenSCAD doesn't permit what I need to do.

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

adrianv wrote > jamcultur wrote >> I'm working on a program to generate a polygon based on values set in the >> customizer. I don't know ahead of time how many points the polygon will >> have, and there could be hundreds of them, so I'd like to generate the >> polygon one line segment at a time. Is there a way to do this? > > I don't understand what you're trying to do here. I mean, you could form > a > convex polygon as a union of triangles formed relative to a center point. > But maybe it makes more sense to somehow build up the list of points > somehow? You don't indicate clearly where the polygon points come from. > Programming in OpenSCAD doesn't permit you do create a list by extending > it > a point at a time: you need to do it either with a loop all at once, or > recursively. The polygon may not be convex, so the union of triangles relative to a central point wouldn't work. The polygon points are calculated based on user input from the customizer. I could build a list of points based on the user's input, but I don't know ahead of time how long that list will be. It is a shame the OpenSCAD doesn't permit what I need to do. -- Sent from: http://forum.openscad.org/
A
arnholm@arnholm.org
Mon, Jun 17, 2019 6:19 AM

On 2019-06-16 22:40, jamcultur wrote:

I'm working on a program to generate a polygon based on values set in
the
customizer. I don't know ahead of time how many points the polygon will
have, and there could be hundreds of them, so I'd like to generate the
polygon one line segment at a time. Is there a way to do this?
Thank you!

Construct an array of points, where consecutive points define each
segment. For a polygon with N edge segments you need N points. Make sure
to organise them as required by OpenSCAD (can't remember if that is CCW
or CW right now).

Carsten Arnholm

On 2019-06-16 22:40, jamcultur wrote: > I'm working on a program to generate a polygon based on values set in > the > customizer. I don't know ahead of time how many points the polygon will > have, and there could be hundreds of them, so I'd like to generate the > polygon one line segment at a time. Is there a way to do this? > Thank you! Construct an array of points, where consecutive points define each segment. For a polygon with N edge segments you need N points. Make sure to organise them as required by OpenSCAD (can't remember if that is CCW or CW right now). Carsten Arnholm
NH
nop head
Mon, Jun 17, 2019 7:12 AM

You can make variable length lists with list comprehensions. It is hard to
understand your problem without knowing a bit more about how the user input
needs converting to vertices.

If the user has to input a list of points then you can pass that list to
polygon, possibly modified.

On Mon, 17 Jun 2019 at 04:06, jamcultur nyponen@gmail.com wrote:

adrianv wrote

jamcultur wrote

I'm working on a program to generate a polygon based on values set in

the

customizer. I don't know ahead of time how many points the polygon will
have, and there could be hundreds of them, so I'd like to generate the
polygon one line segment at a time. Is there a way to do this?

I don't understand what you're trying to do here.  I mean, you could form
a
convex polygon as a union of triangles formed relative to a center

point.

But maybe it makes more sense to somehow build up the list of points
somehow?  You don't indicate clearly where the polygon points come from.
Programming in OpenSCAD doesn't permit you do create a list by extending
it
a point at a time: you need to do it either with a loop all at once, or
recursively.

The polygon may not be convex, so the union of triangles relative to a
central point wouldn't work. The polygon points are calculated based on
user
input from the customizer. I could build a list of points based on the
user's input, but I don't know ahead of time how long that list will be. It
is a shame the OpenSCAD doesn't permit what I need to do.

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


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

You can make variable length lists with list comprehensions. It is hard to understand your problem without knowing a bit more about how the user input needs converting to vertices. If the user has to input a list of points then you can pass that list to polygon, possibly modified. On Mon, 17 Jun 2019 at 04:06, jamcultur <nyponen@gmail.com> wrote: > adrianv wrote > > jamcultur wrote > >> I'm working on a program to generate a polygon based on values set in > the > >> customizer. I don't know ahead of time how many points the polygon will > >> have, and there could be hundreds of them, so I'd like to generate the > >> polygon one line segment at a time. Is there a way to do this? > > > > I don't understand what you're trying to do here. I mean, you could form > > a > > convex polygon as a union of triangles formed relative to a center > point. > > But maybe it makes more sense to somehow build up the list of points > > somehow? You don't indicate clearly where the polygon points come from. > > Programming in OpenSCAD doesn't permit you do create a list by extending > > it > > a point at a time: you need to do it either with a loop all at once, or > > recursively. > > The polygon may not be convex, so the union of triangles relative to a > central point wouldn't work. The polygon points are calculated based on > user > input from the customizer. I could build a list of points based on the > user's input, but I don't know ahead of time how long that list will be. It > is a shame the OpenSCAD doesn't permit what I need to do. > > > > -- > Sent from: http://forum.openscad.org/ > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
NH
nop head
Mon, Jun 17, 2019 10:25 AM

The winding order doesn't seem to matter for polygons for me but it does
for faces of polyhedra.

On Mon, 17 Jun 2019 at 11:11, arnholm@arnholm.org wrote:

On 2019-06-16 22:40, jamcultur wrote:

I'm working on a program to generate a polygon based on values set in
the
customizer. I don't know ahead of time how many points the polygon will
have, and there could be hundreds of them, so I'd like to generate the
polygon one line segment at a time. Is there a way to do this?
Thank you!

Construct an array of points, where consecutive points define each
segment. For a polygon with N edge segments you need N points. Make sure
to organise them as required by OpenSCAD (can't remember if that is CCW
or CW right now).

Carsten Arnholm


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

The winding order doesn't seem to matter for polygons for me but it does for faces of polyhedra. On Mon, 17 Jun 2019 at 11:11, <arnholm@arnholm.org> wrote: > On 2019-06-16 22:40, jamcultur wrote: > > I'm working on a program to generate a polygon based on values set in > > the > > customizer. I don't know ahead of time how many points the polygon will > > have, and there could be hundreds of them, so I'd like to generate the > > polygon one line segment at a time. Is there a way to do this? > > Thank you! > > Construct an array of points, where consecutive points define each > segment. For a polygon with N edge segments you need N points. Make sure > to organise them as required by OpenSCAD (can't remember if that is CCW > or CW right now). > > Carsten Arnholm > > > > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
AC
A. Craig West
Mon, Jun 17, 2019 10:58 AM

Mostly the winding direction has to be consistent. Either all clockwise, or
all counterclockwise, when looked at from the outside.

On Mon, 17 Jun 2019, 06:26 nop head, nop.head@gmail.com wrote:

The winding order doesn't seem to matter for polygons for me but it does
for faces of polyhedra.

On Mon, 17 Jun 2019 at 11:11, arnholm@arnholm.org wrote:

On 2019-06-16 22:40, jamcultur wrote:

I'm working on a program to generate a polygon based on values set in
the
customizer. I don't know ahead of time how many points the polygon will
have, and there could be hundreds of them, so I'd like to generate the
polygon one line segment at a time. Is there a way to do this?
Thank you!

Construct an array of points, where consecutive points define each
segment. For a polygon with N edge segments you need N points. Make sure
to organise them as required by OpenSCAD (can't remember if that is CCW
or CW right now).

Carsten Arnholm


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

Mostly the winding direction has to be consistent. Either all clockwise, or all counterclockwise, when looked at from the outside. On Mon, 17 Jun 2019, 06:26 nop head, <nop.head@gmail.com> wrote: > The winding order doesn't seem to matter for polygons for me but it does > for faces of polyhedra. > > On Mon, 17 Jun 2019 at 11:11, <arnholm@arnholm.org> wrote: > >> On 2019-06-16 22:40, jamcultur wrote: >> > I'm working on a program to generate a polygon based on values set in >> > the >> > customizer. I don't know ahead of time how many points the polygon will >> > have, and there could be hundreds of them, so I'd like to generate the >> > polygon one line segment at a time. Is there a way to do this? >> > Thank you! >> >> Construct an array of points, where consecutive points define each >> segment. For a polygon with N edge segments you need N points. Make sure >> to organise them as required by OpenSCAD (can't remember if that is CCW >> or CW right now). >> >> Carsten Arnholm >> >> >> >> >> _______________________________________________ >> OpenSCAD mailing list >> Discuss@lists.openscad.org >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
RP
Ronaldo Persiano
Mon, Jun 17, 2019 11:12 AM

jamcultur nyponen@gmail.com wrote:

The polygon may not be convex, so the union of triangles relative to a
central point wouldn't work. The polygon points are calculated based on
user
input from the customizer. I could build a list of points based on the
user's input, but I don't know ahead of time how long that list will be. It
is a shame the OpenSCAD doesn't permit what I need to do.

It is hard to understand what you want from this short description. If your
intention is to do a continuous user interaction using the customizer, be
aware that is not the customizer function. With customizer the user may set
any of a list of parameters and the code is executed for that set. It is
not a substitute to the input command of interactive languages.

However, some very crude interaction with growing lists of points may be
done with customizer. The code bellow is a very simple example of it.

point_x = [] ;
point_y = [] ;

m = min([len(point_x),len(point_y)]);
points=[for(i=[0:m-1])
[point_x[i],point_y[i]]];

echo(points);
polygon(points);

The parameters point_x and point_y are simple lists of the coordinates of a
point list. In customizer, you can insert new points by inserting a value
in the first list and a value in the second list.

jamcultur <nyponen@gmail.com> wrote: > The polygon may not be convex, so the union of triangles relative to a > central point wouldn't work. The polygon points are calculated based on > user > input from the customizer. I could build a list of points based on the > user's input, but I don't know ahead of time how long that list will be. It > is a shame the OpenSCAD doesn't permit what I need to do. > It is hard to understand what you want from this short description. If your intention is to do a continuous user interaction using the customizer, be aware that is not the customizer function. With customizer the user may set any of a list of parameters and the code is executed for that set. It is not a substitute to the input command of interactive languages. However, some very crude interaction with growing lists of points may be done with customizer. The code bellow is a very simple example of it. point_x = [] ; point_y = [] ; m = min([len(point_x),len(point_y)]); points=[for(i=[0:m-1]) [point_x[i],point_y[i]]]; echo(points); polygon(points); The parameters point_x and point_y are simple lists of the coordinates of a point list. In customizer, you can insert new points by inserting a value in the first list and a value in the second list.
J
jamcultur
Mon, Jun 17, 2019 2:25 PM

The sides of the polygon are cubic Bezier curves that are calculated based on
input from the user. There is no continuous interaction with the user. The
number of sides of the polygon and the number of points in each Bezier curve
vary depending on what the user specifies in the customizer. Thanks for the
sample code. I will give it a try.

Ronaldo wrote

jamcultur <

nyponen@

> wrote:

The polygon may not be convex, so the union of triangles relative to a
central point wouldn't work. The polygon points are calculated based on
user
input from the customizer. I could build a list of points based on the
user's input, but I don't know ahead of time how long that list will be.
It
is a shame the OpenSCAD doesn't permit what I need to do.

It is hard to understand what you want from this short description. If
your
intention is to do a continuous user interaction using the customizer, be
aware that is not the customizer function. With customizer the user may
set
any of a list of parameters and the code is executed for that set. It is
not a substitute to the input command of interactive languages.

However, some very crude interaction with growing lists of points may be
done with customizer. The code bellow is a very simple example of it.

point_x = [] ;
point_y = [] ;

m = min([len(point_x),len(point_y)]);
points=[for(i=[0:m-1])
[point_x[i],point_y[i]]];

echo(points);
polygon(points);

The parameters point_x and point_y are simple lists of the coordinates of
a
point list. In customizer, you can insert new points by inserting a value
in the first list and a value in the second list.


OpenSCAD mailing list

Discuss@.openscad

The sides of the polygon are cubic Bezier curves that are calculated based on input from the user. There is no continuous interaction with the user. The number of sides of the polygon and the number of points in each Bezier curve vary depending on what the user specifies in the customizer. Thanks for the sample code. I will give it a try. Ronaldo wrote > jamcultur &lt; > nyponen@ > &gt; wrote: > >> The polygon may not be convex, so the union of triangles relative to a >> central point wouldn't work. The polygon points are calculated based on >> user >> input from the customizer. I could build a list of points based on the >> user's input, but I don't know ahead of time how long that list will be. >> It >> is a shame the OpenSCAD doesn't permit what I need to do. >> > > It is hard to understand what you want from this short description. If > your > intention is to do a continuous user interaction using the customizer, be > aware that is not the customizer function. With customizer the user may > set > any of a list of parameters and the code is executed for that set. It is > not a substitute to the input command of interactive languages. > > However, some very crude interaction with growing lists of points may be > done with customizer. The code bellow is a very simple example of it. > > point_x = [] ; > point_y = [] ; > > m = min([len(point_x),len(point_y)]); > points=[for(i=[0:m-1]) > [point_x[i],point_y[i]]]; > > echo(points); > polygon(points); > > > The parameters point_x and point_y are simple lists of the coordinates of > a > point list. In customizer, you can insert new points by inserting a value > in the first list and a value in the second list. > > _______________________________________________ > OpenSCAD mailing list > Discuss@.openscad > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org -- Sent from: http://forum.openscad.org/
J
jamcultur
Mon, Jun 17, 2019 3:10 PM

That worked. The growing list of points was exactly what I needed. Thank you!

Ronaldo wrote

jamcultur <

nyponen@

> wrote:

The polygon may not be convex, so the union of triangles relative to a
central point wouldn't work. The polygon points are calculated based on
user
input from the customizer. I could build a list of points based on the
user's input, but I don't know ahead of time how long that list will be.
It
is a shame the OpenSCAD doesn't permit what I need to do.

It is hard to understand what you want from this short description. If
your
intention is to do a continuous user interaction using the customizer, be
aware that is not the customizer function. With customizer the user may
set
any of a list of parameters and the code is executed for that set. It is
not a substitute to the input command of interactive languages.

However, some very crude interaction with growing lists of points may be
done with customizer. The code bellow is a very simple example of it.

point_x = [] ;
point_y = [] ;

m = min([len(point_x),len(point_y)]);
points=[for(i=[0:m-1])
[point_x[i],point_y[i]]];

echo(points);
polygon(points);

The parameters point_x and point_y are simple lists of the coordinates of
a
point list. In customizer, you can insert new points by inserting a value
in the first list and a value in the second list.


OpenSCAD mailing list

Discuss@.openscad

That worked. The growing list of points was exactly what I needed. Thank you! Ronaldo wrote > jamcultur &lt; > nyponen@ > &gt; wrote: > >> The polygon may not be convex, so the union of triangles relative to a >> central point wouldn't work. The polygon points are calculated based on >> user >> input from the customizer. I could build a list of points based on the >> user's input, but I don't know ahead of time how long that list will be. >> It >> is a shame the OpenSCAD doesn't permit what I need to do. >> > > It is hard to understand what you want from this short description. If > your > intention is to do a continuous user interaction using the customizer, be > aware that is not the customizer function. With customizer the user may > set > any of a list of parameters and the code is executed for that set. It is > not a substitute to the input command of interactive languages. > > However, some very crude interaction with growing lists of points may be > done with customizer. The code bellow is a very simple example of it. > > point_x = [] ; > point_y = [] ; > > m = min([len(point_x),len(point_y)]); > points=[for(i=[0:m-1]) > [point_x[i],point_y[i]]]; > > echo(points); > polygon(points); > > > The parameters point_x and point_y are simple lists of the coordinates of > a > point list. In customizer, you can insert new points by inserting a value > in the first list and a value in the second list. > > _______________________________________________ > OpenSCAD mailing list > Discuss@.openscad > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org -- Sent from: http://forum.openscad.org/