Creating pie (pizza slice) shape (need a dynamic length array)

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

Re: Creating pie (pizza slice) shape (need a dynamic length array)

kintel
Administrator
On Sep 30, 2014, at 07:05 AM, QuackingPlums <[hidden email]> wrote:

>
> Can anyone explain why? There are no errors in the output window.
>
This is a bug - and it has since been fixed. The latest development snapshots should work.

About code quoting: This is email, so as long as the plain-text content is good, you’re free to use any standard html which email readers understand. You’re probably better off using plain text though.

 -Marius

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
Reply | Threaded
Open this post in threaded view
|

Re: Creating pie (pizza slice) shape (need a dynamic length array)

prochat
This post has NOT been accepted by the mailing list yet.
This post was updated on .
In reply to this post by clothbot
Same in 3D:

module cylinder_slice(r=3.0,h=10, a=30) {
  $fn=64;
  intersection() {
    cylinder(h=h,r=r);
    cube([r,r,h]);
    rotate(a-90) cube(r);
  }
}

cylinder_slice(r=40,h=10,a=15);
Reply | Threaded
Open this post in threaded view
|

Re: Creating pie (pizza slice) shape (need a dynamic length array)

DarioPellegrini
I wrote this code a while ago. It works with any angle by dynamically adding
the necessary (small) number of subtracting triangles.

module circular_sector(r, theta) {
    overlap = 10;
    dtheta = 360 - theta;
    n = ceil(dtheta/90);
    a = (dtheta+overlap*(n-1))/n;
    difference() {
        circle(r);
        for (i=[0:1:n-1]) rotate([0,0,theta+i*(a-overlap)])
polygon([[0,0],[2*r,0],[2*r*cos(a),2*r*sin(a)]]);
    }
}



--
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: Creating pie (pizza slice) shape (need a dynamic length array)

Parkinbot
In reply to this post by nophead
It seems there are many versions of pie out there.
In OpenScad it is always a good idea to avoid Boolean ops. Thus the
following version is more basic. While it doesn't explicitly account for $fs
(indeed polygon() seems to enforce it), it copes well with $fn, $fa, and any
- also negative - angles.

pieSlice(10, 10, 23, $fa=3);

module pieSlice(r=10, start_angle=0, end_angle=45)
{
  polygon(pie(r, start_angle, end_angle));

  function pie(r=40, a1=0, a2=150) =
    let(start = a1%360)
    let(end = (a2%360-start)>=0?a2%360:a2%360+360)
    let(fa = $fn==0?$fa:360/$fn)
    let(step = (end-start)/ceil((end-start)/fa)- 1e-7)
    r*[[0,0], for(i=[start:step:end]) [cos(i), sin(i)]];
}



--
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: Creating pie (pizza slice) shape (need a dynamic length array)

runsun
Add my version for completeness. It's part of my lib so I'll only post the
function signature here
'cos the lib needs to be downloaded anyway.

It takes a different approach, requiring any 3 points (PQR) in the 3D space.

function arcPts(  
                pqr
                , n=6 // # of points produced
                , rad= undef  // radius, default = dPQ
                , a = undef    // angle, default = aPQR
                , a2 = undef  // a 2nd angle, if given, start from a pt
defined by a and rad
                                    // , then move upward away from plane
PQR
                , ratio= 1     // If given, replace rad.
                )

See the following pic for demo, which is generated with  this code
<https://bitbucket.org/runsun/scadx/src/master/demos/demo_arcPts.scad>  .
<http://forum.openscad.org/file/t602/180916-demo_arcPts.png>










-----

$  Runsun Pan, PhD $ libs: scadx , doctest , faces ( git ), offline doc ( git ), runscad.py ( 2 , git ), editor of choice: CudaText  ( OpenSCAD lexer );&nbsp;$ Tips ;&nbsp;$ Snippets

--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
$ Runsun Pan, PhD
$ libs: scadx, doctest, faces(git), offline doc(git), runscad.py(2,git), editor of choice: CudaText ( OpenSCAD lexer); $ Tips; $ Snippets
Reply | Threaded
Open this post in threaded view
|

Re: Creating pie (pizza slice) shape (need a dynamic length array)

TLC123
In reply to this post by Peter Uithoven

                module slice(r = 10, deg = 30) {
                fn=$fn!=0?$fn :round(deg/10);  degn=(deg%360);
                step=degn/fn;   start=min(degn ,0);  end=max(degn,0);
                polygon(
                    concat(
                        [[0,0]],
                        [for(i=[start:step:end+step])  
                            [cos(min(end,i))*r,sin(min(end,i))*r]]  ));}

                slice(10, 130);



--
Sent from: http://forum.openscad.org/

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

Re: Creating pie (pizza slice) shape (need a dynamic length array)

tp3
On 09/16/2018 05:38 PM, TLC123 wrote:
>                  polygon(
>                      concat(
>                          [[0,0]],
>                          [for(i=[start:step:end+step])
>                              [cos(min(end,i))*r,sin(min(end,i))*r]]  ));} >
The concat() is not needed anymore with the latest list comprehension
updates. It's possible to combine multiple generator expressions
or just simple values, e.g.:

polygon([
        [0,0],
        for(i=[start:step:end+step]) [cos(min(end,i))*r,sin(min(end,i))*r]
]);

ciao,
   Torsten.

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

Re: Creating pie (pizza slice) shape (need a dynamic length array)

TLC123
Oh thanks. That really makes things more elegant.

                module slice(r = 10, deg = 30) {
                fn=$fn!=0?$fn :round(deg/10);         degn=(deg%360);
                step=degn/fn;   start=min(degn ,0);  end=max(degn,0);
                polygon(r*[[0,0], for(i=[start:step:end]) [cos(i),
sin(i)]]);     }

                slice(10, 130);



--
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: Creating pie (pizza slice) shape (need a dynamic length array)

JordanBrown
In reply to this post by DarioPellegrini
While we're tossing around implementations...

I honestly don't know whether I originally wrote this, or if I picked it up somewhere and modified it.  I don't find any Google hits on any of the comments, so maybe I wrote it.

It's longer than the other answers suggested, but part of that is a couple of general-purpose functions.

It's only two objects (a circle and a quadrilateral) and one boolean (either intersection or difference).

// polar to rectangular (default:  map-style, a=0 north, a=90 east)
// p2r([rho, theta]) = [ x, y ]
// axis is the angle of the axis, math-style (axis=0 east)
// clockwise tells orientation of angle: true is, well, clockwise (map-style)
// while false is counter-clockwise (math-style)
function p2r(p, axis=90, clockwise=true) =
    let (r = p[0])
    let (a = (clockwise ? -p[1] : p[1]) + axis)
    [ r * cos(a), r * sin(a) ];
    
// positive modulus:  all results are positive
function posmod(a, b) = a - (floor(a/b)*b);
    
// A quadrilateral that encloses an arc of the specified radius and angle, for angle
// less or equal to 180.
// The theoretical minimum is r*sqrt(2), but since larger doesn't hurt why not avoid
// the sqrt and any possibility of zero-thickness surfaces?
// Set $_arcpoly_show to display the polygon.
module _arcpoly(r, a) {
    r2 = r*2;
    poly = [ [0,0], p2r([r2, a/2], axis=0, clockwise=false), [r2, 0], p2r([r2, -a/2], axis=0, clockwise=false) ];
    if ($_arcpoly_show) #polygon(poly);
    else polygon(poly);
}

// A sector of a circle, of the specified radius and angle.
// Centered around the X axis.
module sector(r, a) {
    norma = posmod(a, 360);
    if (norma <= 180) {
        intersection() {
            circle(r);
            _arcpoly(r, norma);
        }
    } else {
        difference() {
            circle(r);
            mirror([1, 0, 0]) _arcpoly(r, 360-norma);
        }
    }
}


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