discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Re: all this talk about ellipses has me a bit confused

RW
Raymond West
Thu, Aug 11, 2022 7:34 PM

wrt ovals/ellipse (any list of points in first quadrant), I've put some
code below which will replicate a list of 2d points in the first
quadrant over the other three, in the correct sequence such that it
produces a polygon.

It could probably be made more succinct, but it took me long enough to
get to where it is (not helped by underlining of error messages s;-{ )

// quadrant replication

function reverse(plist)= [for(j=[0:1:len(plist)-1])plist[len(plist)-1-j]];

// pp1=[[10,100],[50,80],[100,20]];   //  test list of points for pp1

  pp1 = [[2.77541, 154.533], [30.5096, 154.918], [55.6412, 151.285],
[77.5501, 142.929], [96.0551, 129.467], [111.303, 111.138], [123.428,
88.7918], [132.34, 63.552], [137.786, 36.4907], [139.527, 8.50528]];  //
longer list of points

 pp2=[for(p=pp1)([p[0],-p[1]])];

       pp2r= reverse(pp2);

 pp3=[for(p=pp1)([-p[0],-p[1]])];

 pp4=[for(p=pp1)([-p[0],p[1]])];

       pp4r=reverse(pp4);

   totalshape= concat(pp1,pp2r,pp3,pp4r);

           polygon(points=totalshape);

wrt ovals/ellipse (any list of points in first quadrant), I've put some code below which will replicate a list of 2d points in the first quadrant over the other three, in the correct sequence such that it produces a polygon. It could probably be made more succinct, but it took me long enough to get to where it is (not helped by underlining of error messages s;-{ ) // quadrant replication function reverse(plist)= [for(j=[0:1:len(plist)-1])plist[len(plist)-1-j]]; // pp1=[[10,100],[50,80],[100,20]];   //  test list of points for pp1   pp1 = [[2.77541, 154.533], [30.5096, 154.918], [55.6412, 151.285], [77.5501, 142.929], [96.0551, 129.467], [111.303, 111.138], [123.428, 88.7918], [132.34, 63.552], [137.786, 36.4907], [139.527, 8.50528]];  // longer list of points  pp2=[for(p=pp1)([p[0],-p[1]])];        pp2r= reverse(pp2);  pp3=[for(p=pp1)([-p[0],-p[1]])];  pp4=[for(p=pp1)([-p[0],p[1]])];        pp4r=reverse(pp4);    totalshape= concat(pp1,pp2r,pp3,pp4r);            polygon(points=totalshape);
AM
Adrian Mariano
Thu, Aug 11, 2022 7:46 PM

I didn't double check by actually running the code, but it looks like
that code will create duplicate points if there are points on the x/y
axes.  This may not matter...or it might, depending on what you're
going to do with the point list.

In the case of the ellipses, I don't want to end up with two points at
one end that are at, say,  [10,1e-12] and [10,-1e-12] or something
like that, so a general implementation would need to test for
approximate equality to zero to avoid creating duplicates.

On Thu, Aug 11, 2022 at 3:35 PM Raymond West raywest@raywest.com wrote:

wrt ovals/ellipse (any list of points in first quadrant), I've put some
code below which will replicate a list of 2d points in the first
quadrant over the other three, in the correct sequence such that it
produces a polygon.

It could probably be made more succinct, but it took me long enough to
get to where it is (not helped by underlining of error messages s;-{ )

// quadrant replication

function reverse(plist)= [for(j=[0:1:len(plist)-1])plist[len(plist)-1-j]];

// pp1=[[10,100],[50,80],[100,20]];  //  test list of points for pp1

pp1 = [[2.77541, 154.533], [30.5096, 154.918], [55.6412, 151.285],

[77.5501, 142.929], [96.0551, 129.467], [111.303, 111.138], [123.428,
88.7918], [132.34, 63.552], [137.786, 36.4907], [139.527, 8.50528]];  //
longer list of points

pp2=[for(p=pp1)([p[0],-p[1]])];

     pp2r= reverse(pp2);

pp3=[for(p=pp1)([-p[0],-p[1]])];

pp4=[for(p=pp1)([-p[0],p[1]])];

     pp4r=reverse(pp4);

 totalshape= concat(pp1,pp2r,pp3,pp4r);

         polygon(points=totalshape);

OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

I didn't double check by actually running the code, but it looks like that code will create duplicate points if there are points on the x/y axes. This may not matter...or it might, depending on what you're going to do with the point list. In the case of the ellipses, I don't want to end up with two points at one end that are at, say, [10,1e-12] and [10,-1e-12] or something like that, so a general implementation would need to test for approximate equality to zero to avoid creating duplicates. On Thu, Aug 11, 2022 at 3:35 PM Raymond West <raywest@raywest.com> wrote: > > > wrt ovals/ellipse (any list of points in first quadrant), I've put some > code below which will replicate a list of 2d points in the first > quadrant over the other three, in the correct sequence such that it > produces a polygon. > > It could probably be made more succinct, but it took me long enough to > get to where it is (not helped by underlining of error messages s;-{ ) > > > // quadrant replication > > function reverse(plist)= [for(j=[0:1:len(plist)-1])plist[len(plist)-1-j]]; > > // pp1=[[10,100],[50,80],[100,20]]; // test list of points for pp1 > > pp1 = [[2.77541, 154.533], [30.5096, 154.918], [55.6412, 151.285], > [77.5501, 142.929], [96.0551, 129.467], [111.303, 111.138], [123.428, > 88.7918], [132.34, 63.552], [137.786, 36.4907], [139.527, 8.50528]]; // > longer list of points > > pp2=[for(p=pp1)([p[0],-p[1]])]; > > pp2r= reverse(pp2); > > pp3=[for(p=pp1)([-p[0],-p[1]])]; > > pp4=[for(p=pp1)([-p[0],p[1]])]; > > pp4r=reverse(pp4); > > totalshape= concat(pp1,pp2r,pp3,pp4r); > > polygon(points=totalshape); > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org