Issue with scaling, increase face count for accuracy

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

Issue with scaling, increase face count for accuracy

Katt
Hi guys;

I am using the following code to generate an stl image.

//*******CODE START************//
n=5;

//nverts control smoothing of the cad model
nverts=100;

//scales the x-coordinate
scalex=1;

//Compute the 'y' for a given x, n
function f(x)= pow(x,n)/ (pow(x,n)+pow((1-x),n)) + 0.5;

//Generate a symmetric model
verts=concat([for(i=[0:nverts-1]) [scalex*i/nverts, f(i/nverts)]],
[for(i=[nverts-1:-1:0]) [scalex*i/nverts, -f(i/nverts)]] );

linear_extrude(height = 0.5){
//Join the vertices to form the required polygon    
polygon(verts);
}

nverts1 = 100;
scalex1 = -2;

function f1(x)=0.5;
verts1=concat([for(i=[0:nverts1-1]) [scalex1*i/nverts1, f1(i/nverts1)]],
[for(i=[nverts1-1:-1:0]) [scalex1*i/nverts1, -f1(i/nverts1)]] );

linear_extrude(height = 0.5){
polygon(verts1);
}

nverts2 = 100;
scalex2 = 2.0;

function f2(x)=1.5;
verts2=concat([for(i=[0:nverts2-1]) [0.99+scalex2*i/nverts2,
f2(i/nverts2)]], [for(i=[nverts2-1:-1:0]) [0.99+scalex2*i/nverts2,
-f2(i/nverts2)]] );

linear_extrude(height = 0.5){
polygon(verts2);
}

//*******CODE END************//


1. The stl shall ideally be symmetric and looks symmetric but when I zoom
close I see steps on one side but not on the other which means the stl is
not really symmetric. Why is this so and how to make it accurate? You can
see them at the curves.

2. The scale is imprecise. That is, for example, "scalex1 and scalex2" are
set to 2 (meaning the ends shall end at 1 and at 3) but they are only
approximate? What is causing this imperfection.
Because of this, I had to use a scaling number 0.99 instead of 1 in the
following in the code adjusting segments else would disjoin the stl:
verts2=concat([for(i=[0:nverts2-1]) [*0.99*+scalex2*i/nverts2,
f2(i/nverts2)]], [for(i=[nverts2-1:-1:0]) [*0.99*+scalex2*i/nverts2,
-f2(i/nverts2)]] );

3. I would like to get a more precise geometry by probably increasing the
number of faces of the stl model. Any idea how to do it?
<http://forum.openscad.org/file/t2047/fn.png>
I am interested in the normal vectors on these faces and I am guessing that
they are approximate and not accurate enough. Any thoughts on this?

Thanks



--
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: Issue with scaling, increase face count for accuracy

MichaelAtOz
Administrator
Interesting...I'll have to look deeper, but the non-symetricality goes away
with the latest snapshot v's with 2015.03-2. Try the snapshot  here
<http://www.openscad.org/downloads.html#snapshots>  .

For Q3, nverts=200; // etc works.

I'll have to think about Q2.




-----
Admin - PM me if you need anything, or if I've done something stupid...

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.

The TPP is no simple “trade agreement.”   Fight it! http://www.ourfairdeal.org/   time is running out!
--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Admin - PM me if you need anything,
or if I've done something stupid...

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work.
Obviously inclusion of works of previous authors is not included in the above.


The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out!
Reply | Threaded
Open this post in threaded view
|

Re: Issue with scaling, increase face count for accuracy

MichaelAtOz
Administrator
In reply to this post by Katt
RE Q2, if you do echo(verts), you see that it goes from 0..0.99, so remove
the -1's and it goes 0..1.





-----
Admin - PM me if you need anything, or if I've done something stupid...

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.

The TPP is no simple “trade agreement.”   Fight it! http://www.ourfairdeal.org/   time is running out!
--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Admin - PM me if you need anything,
or if I've done something stupid...

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work.
Obviously inclusion of works of previous authors is not included in the above.


The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out!
Reply | Threaded
Open this post in threaded view
|

Re: Issue with scaling, increase face count for accuracy

MichaelAtOz
Administrator
Re the asymmetry, OpenSCAD 2015.03-2 had a bug with small numbers.
As you are working in that space, e.g. [0.06, 0.500001],[0.07,
0.500002],[0.08, 0.500005],[0.09, 0.500009], it was not able to consistently
deal with such small scales.
It is fixed in the snapshots.



-----
Admin - PM me if you need anything, or if I've done something stupid...

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.

The TPP is no simple “trade agreement.”   Fight it! http://www.ourfairdeal.org/   time is running out!
--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Admin - PM me if you need anything,
or if I've done something stupid...

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work.
Obviously inclusion of works of previous authors is not included in the above.


The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out!