Rounding(?) problem with polygon()

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

Rounding(?) problem with polygon()

cube
Hi,
I'm trying to make a parametric NACA 4digit airfoil shape using
polygon(). I have a function that gives me Y coordinate for every X,
and I'm calculating a vector of X, Y coordinates using a list
comprehension.

My problem is that when I select the X spacing too narrow, the
resulting polygon looks like it's skipping some points -- the lower the
stepping, the more points lost.

MWE is attached to this mail. The step size 0.0035 was chosen so that
the problem is visible enough. With step size 0.05 it still looks OK,
lower than that the problem starts to appear with increasing severity.

To verify that the vector fed as an input to the polygons the correct,
the example also renders spheres at positions of the control points.

When I scale the positions in the vector (set scale variable to 100
int the example), the problem disappears.

Is this intended, or a bug?

I'm using OpenSCAD 2015.03, built from source with Gentoo ebuild.

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

polygon_problem_mwe.scad (534 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Rounding(?) problem with polygon()

Ronaldo
See if you get better results with this:

extra_scale = 100; // increase if needed
step = 0.0035;
scale = 100*extra_scale;

top = [for(x = [0:step:1]) scale * [x,
                                    0.12 * naca_thickness(x)]];

scale(1/extra_scale ) polygon(points=top);

scale(1/extra_scale ) %for(p = top) translate([p[0], p[1], 0]) sphere(scale * 0.005);

2016-04-10 8:51 GMT-03:00 Kuba Marek <[hidden email]>:
Hi,
I'm trying to make a parametric NACA 4digit airfoil shape using
polygon(). I have a function that gives me Y coordinate for every X,
and I'm calculating a vector of X, Y coordinates using a list
comprehension.

My problem is that when I select the X spacing too narrow, the
resulting polygon looks like it's skipping some points -- the lower the
stepping, the more points lost.

MWE is attached to this mail. The step size 0.0035 was chosen so that
the problem is visible enough. With step size 0.05 it still looks OK,
lower than that the problem starts to appear with increasing severity.

To verify that the vector fed as an input to the polygons the correct,
the example also renders spheres at positions of the control points.

When I scale the positions in the vector (set scale variable to 100
int the example), the problem disappears.

Is this intended, or a bug?

I'm using OpenSCAD 2015.03, built from source with Gentoo ebuild.

Kuba Marek

_______________________________________________
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: Rounding(?) problem with polygon()

doug.moen
In reply to this post by cube
This is a known bug, and scaling up is the workaround.


On 10 April 2016 at 07:51, Kuba Marek <[hidden email]> wrote:
Hi,
I'm trying to make a parametric NACA 4digit airfoil shape using
polygon(). I have a function that gives me Y coordinate for every X,
and I'm calculating a vector of X, Y coordinates using a list
comprehension.

My problem is that when I select the X spacing too narrow, the
resulting polygon looks like it's skipping some points -- the lower the
stepping, the more points lost.

MWE is attached to this mail. The step size 0.0035 was chosen so that
the problem is visible enough. With step size 0.05 it still looks OK,
lower than that the problem starts to appear with increasing severity.

To verify that the vector fed as an input to the polygons the correct,
the example also renders spheres at positions of the control points.

When I scale the positions in the vector (set scale variable to 100
int the example), the problem disappears.

Is this intended, or a bug?

I'm using OpenSCAD 2015.03, built from source with Gentoo ebuild.

Kuba Marek

_______________________________________________
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: Rounding(?) problem with polygon()

kintel
Administrator
In reply to this post by cube
On Apr 10, 2016, at 07:51 AM, Kuba Marek <[hidden email]> wrote:
>
> When I scale the positions in the vector (set scale variable to 100
> int the example), the problem disappears.
>
> Is this intended, or a bug?
>
This is a known bug: https://github.com/openscad/openscad/issues/999

 -Marius


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

Re: Rounding(?) problem with polygon()

cube
In reply to this post by Ronaldo
Weird that I didn't find that bug report :-)
Thanks for your answers, the scaling workaround works well enough.

> See if you get better results with this:
>
> extra_scale = 100; // increase if needed
> step = 0.0035;
> scale = 100*extra_scale;
>
> top = [for(x = [0:step:1]) scale * [x,
>                                     0.12 * naca_thickness(x)]];
>
> scale(1/extra_scale ) polygon(points=top);
>
> scale(1/extra_scale ) %for(p = top) translate([p[0], p[1], 0])
> sphere(scale
> * 0.005);
>
> 2016-04-10 8:51 GMT-03:00 Kuba Marek <[hidden email]>:
>
> > Hi,
> > I'm trying to make a parametric NACA 4digit airfoil shape using
> > polygon(). I have a function that gives me Y coordinate for every X,
> > and I'm calculating a vector of X, Y coordinates using a list
> > comprehension.
> >
> > My problem is that when I select the X spacing too narrow, the
> > resulting polygon looks like it's skipping some points -- the lower
> > the stepping, the more points lost.
> >
> > MWE is attached to this mail. The step size 0.0035 was chosen so
> > that the problem is visible enough. With step size 0.05 it still
> > looks OK, lower than that the problem starts to appear with
> > increasing severity.
> >
> > To verify that the vector fed as an input to the polygons the
> > correct, the example also renders spheres at positions of the
> > control points.
> >
> > When I scale the positions in the vector (set scale variable to 100
> > int the example), the problem disappears.
> >
> > Is this intended, or a bug?
> >
> > I'm using OpenSCAD 2015.03, built from source with Gentoo ebuild.
> >
> > Kuba Marek
> > _______________________________________________
> > 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: Rounding(?) problem with polygon()

Ronaldo
Besides, observe that the Naca profile has a very fast variation of the tangent near x=0 and which varies slowly to the right. You may consider a varying discretization on sampling x, starting with a fine discretization for low x and enlaging it for greater x.

2016-04-10 13:30 GMT-03:00 Kuba Marek <[hidden email]>:
Weird that I didn't find that bug report :-)
Thanks for your answers, the scaling workaround works well enough.

> See if you get better results with this:
>
> extra_scale = 100; // increase if needed
> step = 0.0035;
> scale = 100*extra_scale;
>
> top = [for(x = [0:step:1]) scale * [x,
>                                     0.12 * naca_thickness(x)]];
>
> scale(1/extra_scale ) polygon(points=top);
>
> scale(1/extra_scale ) %for(p = top) translate([p[0], p[1], 0])
> sphere(scale
> * 0.005);
>
> 2016-04-10 8:51 GMT-03:00 Kuba Marek <[hidden email]>:
>
> > Hi,
> > I'm trying to make a parametric NACA 4digit airfoil shape using
> > polygon(). I have a function that gives me Y coordinate for every X,
> > and I'm calculating a vector of X, Y coordinates using a list
> > comprehension.
> >
> > My problem is that when I select the X spacing too narrow, the
> > resulting polygon looks like it's skipping some points -- the lower
> > the stepping, the more points lost.
> >
> > MWE is attached to this mail. The step size 0.0035 was chosen so
> > that the problem is visible enough. With step size 0.05 it still
> > looks OK, lower than that the problem starts to appear with
> > increasing severity.
> >
> > To verify that the vector fed as an input to the polygons the
> > correct, the example also renders spheres at positions of the
> > control points.
> >
> > When I scale the positions in the vector (set scale variable to 100
> > int the example), the problem disappears.
> >
> > Is this intended, or a bug?
> >
> > I'm using OpenSCAD 2015.03, built from source with Gentoo ebuild.
> >
> > Kuba Marek
> > _______________________________________________
> > 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: Rounding(?) problem with polygon()

Parkinbot
In reply to this post by cube
You might want to have a look into this NACA-library:
http://www.thingiverse.com/thing:898554
Reply | Threaded
Open this post in threaded view
|

Re: Rounding(?) problem with polygon()

Neon22
In reply to this post by cube
It would be great if you extended the existing NACA library with some more of the NACA algorithms/codes.
Reply | Threaded
Open this post in threaded view
|

Re: Rounding(?) problem with polygon()

cube
In reply to this post by Ronaldo
Yes, that was the plan after I get the rest of my project working :-)

> Besides, observe that the Naca profile has a very fast variation of
> the tangent near x=0 and which varies slowly to the right. You may
> consider a varying discretization on sampling x, starting with a fine
> discretization for low x and enlaging it for greater x.
>
> 2016-04-10 13:30 GMT-03:00 Kuba Marek <[hidden email]>:
>
> > Weird that I didn't find that bug report :-)
> > Thanks for your answers, the scaling workaround works well enough.
> >  
> > > See if you get better results with this:
> > >
> > > extra_scale = 100; // increase if needed
> > > step = 0.0035;
> > > scale = 100*extra_scale;
> > >
> > > top = [for(x = [0:step:1]) scale * [x,
> > >                                     0.12 * naca_thickness(x)]];
> > >
> > > scale(1/extra_scale ) polygon(points=top);
> > >
> > > scale(1/extra_scale ) %for(p = top) translate([p[0], p[1], 0])
> > > sphere(scale
> > > * 0.005);
> > >
> > > 2016-04-10 8:51 GMT-03:00 Kuba Marek <[hidden email]>:
> > >  
> > > > Hi,
> > > > I'm trying to make a parametric NACA 4digit airfoil shape using
> > > > polygon(). I have a function that gives me Y coordinate for
> > > > every X, and I'm calculating a vector of X, Y coordinates using
> > > > a list comprehension.
> > > >
> > > > My problem is that when I select the X spacing too narrow, the
> > > > resulting polygon looks like it's skipping some points -- the
> > > > lower the stepping, the more points lost.
> > > >
> > > > MWE is attached to this mail. The step size 0.0035 was chosen so
> > > > that the problem is visible enough. With step size 0.05 it still
> > > > looks OK, lower than that the problem starts to appear with
> > > > increasing severity.
> > > >
> > > > To verify that the vector fed as an input to the polygons the
> > > > correct, the example also renders spheres at positions of the
> > > > control points.
> > > >
> > > > When I scale the positions in the vector (set scale variable to
> > > > 100 int the example), the problem disappears.
> > > >
> > > > Is this intended, or a bug?
> > > >
> > > > I'm using OpenSCAD 2015.03, built from source with Gentoo
> > > > ebuild.
> > > >
> > > > Kuba Marek
> > > > _______________________________________________
> > > > 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: Rounding(?) problem with polygon()

cube
In reply to this post by Neon22
I'd like to do that, but what I have is a new implementation rather than
an extension :-)
So far it can do all 4 digit codes (based on wikipedia) with
regular discretization in X axis and output to a list or polygon.
Is there a way I can make a pull request to the thingieverse?
Anyway I'm planning to put my code up on github sometime soon.

> It would be great if you extended the existing NACA library with some
> more of the NACA algorithms/codes.
>
>
>
> --
> View this message in context:
> http://forum.openscad.org/Rounding-problem-with-polygon-tp17020p17033.html
> 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