discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Create [x,y] - 2D values from a formula to a polygon

Jan Öhman
Sat, Mar 26, 2022 7:45 PM

Hi! (Hope I describe it correctly)My wish is to create 2D contours to be able to produce a polygon.

To manually create a square, this works:
p1a = [ 0,  0];p2a = [ 0, 50];p3a = [30, 50];p4a = [30,  0];color("cyan")    polygon([p1a, p2a, p3a, p4a]);
Started trying to manually round the corners (it also works)
xSize = 30;ySize = 50;radie = 5;rad1 = radie/3.5;
p01b = [ radie,  0];p02b = [  rad1, rad1];p03b = [     0, radie];p04b = [     0, ySize-radie];p05b = [  rad1, ySize-rad1];p06b = [ radie, ySize];p07b = [ xSize-radie, ySize];p08b = [ xSize-rad1, ySize-rad1];p09b = [ xSize, ySize-radie];p10b = [ xSize, radie];p11b = [ xSize-rad1, rad1];p12b = [ xSize-radie, 0];
polygon([p01b, p02b, p03b, p04b, p05b, p06b, p07b, p08b, p09b, p10b, p11b, p12b ]);
But I want more rounded corners. (it is possible, but quickly becomes many x, y-values, (only for the corners)

Do not know how to set up an equation that creates desired [x, y] values that are adapted to the instruction .: polygon([]);
In this case, two equations are needed

  • straight line equation y=kx+m and the 
  • circle equation      rr = (x-x0)(x-x0) + (y-y0)*(y-y0)
    r= radius and x0, y0 is the middle of the circle.
    Maybe only the start and stop values are needed for the corners? (then a straight line is created between the corners automatically) No problem adding an extra corner later?

But how to do this?

Hi! (Hope I describe it correctly)My wish is to create 2D contours to be able to produce a polygon. To manually create a square, this works: p1a = [ 0,  0];p2a = [ 0, 50];p3a = [30, 50];p4a = [30,  0];color("cyan")    polygon([p1a, p2a, p3a, p4a]); Started trying to manually round the corners (it also works) xSize = 30;ySize = 50;radie = 5;rad1 = radie/3.5; p01b = [ radie,  0];p02b = [  rad1, rad1];p03b = [     0, radie];p04b = [     0, ySize-radie];p05b = [  rad1, ySize-rad1];p06b = [ radie, ySize];p07b = [ xSize-radie, ySize];p08b = [ xSize-rad1, ySize-rad1];p09b = [ xSize, ySize-radie];p10b = [ xSize, radie];p11b = [ xSize-rad1, rad1];p12b = [ xSize-radie, 0]; polygon([p01b, p02b, p03b, p04b, p05b, p06b, p07b, p08b, p09b, p10b, p11b, p12b ]); But I want more rounded corners. (it is possible, but quickly becomes many x, y-values, (only for the corners) Do not know how to set up an equation that creates desired [x, y] values that are adapted to the instruction .: polygon([]); In this case, two equations are needed - straight line equation y=kx+m and the  - circle equation      r*r = (x-x0)*(x-x0) + (y-y0)*(y-y0) r= radius and x0, y0 is the middle of the circle. Maybe only the start and stop values are needed for the corners? (then a straight line is created between the corners automatically) No problem adding an extra corner later? But how to do this?