How to draw a polygon one line at a time?

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

How to draw a polygon one line at a time?

jamcultur
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/

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

Re: How to draw a polygon one line at a time?

adrianv
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/

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

Re: How to draw a polygon one line at a time?

jamcultur
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
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: How to draw a polygon one line at a time?

cacb
In reply to this post by jamcultur
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
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: How to draw a polygon one line at a time?

nophead
In reply to this post by jamcultur
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 <[hidden email]> 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
[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: How to draw a polygon one line at a time?

nophead
In reply to this post by cacb
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, <[hidden email]> 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
[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: How to draw a polygon one line at a time?

acwest
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, <[hidden email]> 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, <[hidden email]> 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
[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

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

Re: How to draw a polygon one line at a time?

Ronaldo
In reply to this post by jamcultur


jamcultur <[hidden email]> 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
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: How to draw a polygon one line at a time?

jamcultur
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/

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

Re: How to draw a polygon one line at a time?

jamcultur
In reply to this post by Ronaldo
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/

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