PythonScad    
  


   PythonScad   3D-    PythonScad.   18   ,   ,      , ,  ,   .      OpenSCAD  PythonScad,       .          ,     .         3D-.    ,    ,     ,       .





 

PythonScad    



 1:   PythonScad

.1.    PythonSCAD

PythonSCAD      (IDE),       OpenSCAD   Python.

1.  OpenSCAD

1.   :https://openscad.org/ (https://openscad.org/)   OpenSCAD

2.      (  .exe ).

3.      .

2.  Python 3.11

1.   :https://www.python.org/downloads/release/python-3110/ (https://www.python.org/downloads/release/python-3110/)   Python 3.11

2.      (  .exe ).

3.      .

3.  PythonSCAD

1.   :https://pythonscad.org/download.php (https://pythonscad.org/download.php)

2.      (  .exe ).

3.      .

4.    :

5.    .

6.     ( ).

7.  .



4.  PythonSCAD

       .

 :

 Windows:  OpenSCAD         .

 macOS:    Applications.

 Linux:        pythonscad  .

 :

 :



   "Edit" ? "Preferences" (  Ctrl+P).

 :

General:

  .

    .

Editor:

      .

/  .

 .

3D View:

    3D-.

     .

Render:

   (     ).

 :

        (, ,    ..).

   ():

  Preferences  ,         ,    Python   .

5.  

 :

OpenSCAD   ,        .

  ,     

use <library_path>  include <library_path>

:

use <path_to_library>;

:

    .            .



   OpenSCAD     .              ,      .



.2.  PythonSCAD








. 1.    PythonScad.



 PythonSCAD   ,     3D-.      :




. 2.   PythonSCAD.

1.  

  PythonSCAD    :

  ()      .








. 3.    PythonSCAD.

  ()   3D- .






. 4.    PythonSCAD.

  ()       .








. 5.   PythonSCAD.



      PythonSCAD:

2.    

 

 ,     PythonSCAD.

   .

     .

  (3D-)

 3D-   .

  (),  ( )   (Shift + ).

     .

 

   .

      .

3.    

 ""

New    .

Open    .

Save / Save As   .

Export   3D-   STL, OFF, DXF.

 ""

Undo / Redo     .

Find / Replace       .








. 6.    PythonSCAD.

 ""

/  (, , 3D-)








. 7.    PythonScad.






. 8.    PythonScad.








. 9.    PythonScad.



  

[>] Preview (F5)    .

[img] Render (F6)    ( ,  ).

[save] Export STL     STL.






. 10.    PythonSCAD

4.  (Preferences)

  .

 .

  .






. 11.    PythonSCAD



 PythonSCAD       ,    ,    3D-.

.3.    PythonSCAD(OpenSCAD)

PythonSCAD      3D-.     (CSG)    .

 1:

   (Constructive Solid Geometry, CSG)            (  , ,   .)     (, , ).         (CAD),   PythonSCAD, Blender  .

 2:

   (CAD)    ,       ,    ,  ,      . CAD-  , ,       ,   ,        .

1. : 

cube(size, center=true/false);  .

cube([10, 20, 30]); //  10?20?30

sphere(.....);  .

sphere(10); //  10

cylinder(h, r1, r2);  .

polyhedron(points, faces);  .

2. :  (CSG-)

union() {.....}   .

difference() {.....}      .

intersection() {.....}   .

difference() {



cube(20);



sphere(15);



}

3. :

translate([x, y, z])  .

translate([10, 0, 0]) cube(5);

rotate([x, y, z])  .

rotate([0, 0, 45]) cube(10);

scale([x, y, z])  .

scale([2, 1, 1]) cube(10);

mirror([x, y, z])  .

mirror([1, 0, 0]) cube(10);

resize([x, y, z])   .

resize([20, 30, 10]) sphere(10);



4. :  

module name() {  }    ().

module my_shape() {

cube(10);

}

my_shape();



for (i=[start:step:end]) {  }  .

for (i=[0:10:30]) {

translate([i, 0, 0]) sphere(5);

}



if (condition) {  }  .

function name(args) = expression; .

function square(x) = x * x;

   PythonSCAD(OpenSCAD).    ,   color(), hull(), minkowski(), projection(),      .



1.4.     PythonSCAD(Python)

1.  

from openscad import*    

cu = cube(x, y, z)  "cu"     "cube([z, y, z])"

cu = cube(5) //   5

cy = cylinder(h, r1, r2)  "cy"     "cylinder(h, r1, r2)"

cy = cylinder(10, 5, 5) //  10   5

show([cu,cy])   

2.   (CSG-)

fusion = union([.....]) 

fusion = union([cu,cy]) //    

diff = .difference(.....) 

diff = cy.difference(cu) //    

inter = .intersection(.....) 

inter = cu.intersection(sp)

3. 

rotated=.rotate([.....]) 

rotated=cu.rotate([10,20,30]) //     X, Y, Z  10, 20, 30  

= .translate([.....]) 

cu = cu.translate([1, 2, 3]) //     X, Y, Z  1, 2, 3 

4.   

_ = .color(".....") 

cu_red = cu.color("red") //    

['name']="....."  

cu['name']="_" //   "cu"  "_"

show(.....) 

show(cu) //   "cu"

       OpenSCAD  PythonSCAD(Python)

from openscad import *

obj = scad("""

.....

""")

obj.show()



1.5.     (OpenSCAD)

1.   

 

cube([10, 20, 30]);








. 15.  





sphere(10);








. 12.  



cylinder(10, 5, 5);








. 16.  



2.  

 

union() {

sphere(10);

cube([10, 20, 30]);

}








. 17.     





difference() {

sphere(10);

cube([10, 20, 30]);

}






. 18.  





intersection() {

sphere(10);

cube([10, 20, 30]);

}








. 18.   



    (Python)



1.   



from openscad import *

cu = cube(5)

show(cu)








. 19.  



from openscad import *

cy = cylinder(10, 5, 5)

show(cy)








. 20.  



from openscad import *

sp = sphere(5)

show(sp)








. 21.  



2.  

 

from openscad import *

sp = sphere(5)

cu = cube(6)

fusion = union([sp,cu])

show(fusion)








. 22.     



from openscad import *

sp = sphere(5)

cu = cube(6)

diff = cu.difference(sp)

show(diff)








. 23.     





from openscad import *

sp = sphere(5)

cu = cube(6)

inter = cu.intersection(sp)

show(inter)








. 24.   



1.6.    PythonSCAD

 1:  

 ,       10 .

) cube(10);

) sphere(10);

) cylinder(10);

) cube(5);

 2:  

 ,     5 .

) sphere(5);

) cube(5);

) cylinder(5);

) sphere(10);

 3:  

 ,     20    3 .

) cylinder(h=20, r=3);

) cylinder(h=10, r=3);

) cylinder(h=20, r=5);

) sphere(20, 3);

 4:  

 ,       10   5    X.

) translate([5, 0, 0]) cube(10);

) rotate([5, 0, 0]) cube(10);

) scale([5, 0, 0]) cube(10);

) mirror([5, 0, 0]) cube(10);

 5:  

 ,       10   45    Z.

) rotate([0, 0, 45]) cube(10);

) rotate([0, 45, 0]) cube(10);

) translate([0, 45, 0]) cube(10);

) scale([0, 45, 0]) cube(10);

 6:  

 ,    : (0,0,0), (10,0,0)  (0,10,0).

) points = [[0,0,0], [10,0,0], [0,10,0]];

) points = [0,0,0], [10,0,0], [0,10,0];

) points = (0,0,0), (10,0,0), (0,10,0);

) points = {0,0,0}, {10,0,0}, {0,10,0};

 7:   for

  for,    5     10 ,    20       X.

) for (i = [0:4]) { translate([i * 20, 0, 0]) cube(10); }

) for (i = [0:5]) { translate([i * 20, 0, 0]) cube(10); }

) for (i = [0:4]) { translate([i * 10, 0, 0]) cube(10); }

) for (i = [0:4]) { rotate([i * 20, 0, 0]) cube(10); }

 8:   foreach

  foreach,     5 ,   ,     6.

) foreach(point = points) { translate(point) sphere(5); }

) foreach(point = points) { rotate(point) sphere(5); }

) foreach(point = points) { scale(point) sphere(5); }

) foreach(point = points) { mirror(point) sphere(5); }

 9:  

     5    20 ,      90    X.

) intersection() { cylinder(h=20, r=5); rotate([90, 0, 0]) cylinder(h=20, r=5); }

) union() { cylinder(h=20, r=5); rotate([90, 0, 0]) cylinder(h=20, r=5); }

) difference() { cylinder(h=20, r=5); rotate([90, 0, 0]) cylinder(h=20, r=5); }

) intersection() { cylinder(h=20, r=5); rotate([0, 90, 0]) cylinder(h=20, r=5); }

 10:  

       10 ,      5    X.

) union() { cube(10); translate([5, 0, 0]) cube(10); }

) intersection() { cube(10); translate([5, 0, 0]) cube(10); }

) difference() { cube(10); translate([5, 0, 0]) cube(10); }

) union() { cube(10); rotate([5, 0, 0]) cube(10); }

 11: OpenSCAD

  OpenSCAD?

)     3D-   

)     2D-

)    3D-

)    3D-

) -   

 12:   

   ?

) %  

) transparency()

) alpha(0.5)

) transparent()

) opacity(50%)

 13: 3D-

   3D-?

)  F5

)  Shift + P

)  Ctrl + Z

)  Ctrl + R

)  Alt + P



 14:  3D-

     3D-?

) .stl

) .png

) .svg

) .obj

) .jpeg

 15:    

    ?

) mirror()

) invert()

) flip()

) reverse()

) reflect()

 16: 

     STL?

) >

) >

) >

) >



1.7.    PythonSCAD

 1: 

      ?

) from openscad import *

) union()

) difference()

) From OpenSCAD Import()

 2: 

   ?

) cu = cube()

) c = cube()

) cy = cylinder()

) cube()

 3:

     ?

) 

) 

 4: 

   ?

) v = cylinder(6, 10, 5)

) cy = cylinder()

) sp = sphere()

) cylinder()

 5: 

     ?

) cu_red = cu.color("red")

) cu_red = cu.color("green")

) color("red")

) color(3, 8, 0)

 6: 

  ?

) fusion = union([])

) diff = .difference()

) difference()

)  

 7: 

  ?

) diff = .difference()

) difference()

) Union()

) c = diff()

 8: 

    ""?

) ['name']=""

) name = 

) name = ""

) Figurename = Grinch

 9: 

  ?

) rotated=.rotate([])

) tr = .translate([])

) rotate()

) translate()

 10: 

  ?

) tr = .translate([])

) t = translate()

) rotated=.rotate([])

) r = rotate

 11:

    PythonSCAD?

) OpenSCAD

) Python

) Blender

) C++

)  3-D

) 3-D MAX

 12:

   difference  intersection?

) difference     ,  intersection       

)        PythonSCAD

) intersection     ,  difference       

)      

 13:

  Python   PythonSCAD?

) 3.11

) 4.11

) 3.15

) 6.10

 14:

      ?

) Cube

) Sphere

) Cylinder

) Polyhedron

 15:Python

  Python?

) Python               .

) Python   3D-      3D-.            .

) Python   3D-      3D-.            .

) Python            Windows.   ,    ,      -.

 16:F5

    F5    PythonSCAD?

) 

)  

)  

) 



 2:  

2.1.   "" (cube)  PythonSCAD(OpenSCAD)

 cube  PythonSCAD(OpenSCAD)      ( ,     ).         3D-     CSG-.



:

cube(size, center=true/false);



size   .   :

     ,       ,   .

         X, Y  Z (,   ).

center=true/false  ,  ,       .   true,        ,  false,          .

:    

cube(10); //      10








. 1. 

:    

cube([10, 20, 30]); //    10x20x30








. 2. 

:   

cube(10, center=true); //    10,    








. 3.  

       10?10?10,        .

 4:   

cube(10, center=false); //    10,       








. 4.   

       10?10?10,          .



 

    $fn    , ,      .

 5:    

$fn = 100; //     

cube([10, 20, 30], center=true);






. 5.    

 cube  PythonSCAD(OpenSCAD)     ,       ,   ,   .



2.1.   "" (cube)  PythonSCAD(Python)

 cube  PythonSCAD(OpenSCAD)      ( ,     ).         3D-     CSG-.

:

cu = cube(size)



size   .   :



     ,       ,   .

         X, Y  Z (,   ).



:    

cu = cube(5)

show(cu) //      5






. 6.    

:    

cu = cube([10, 20, 30])

show(cu) //    10x20x30






. 7.    



 cube  PythonSCAD(Python)     ,       ,   ,   .

:   

cu = cube([10, 10, 10], center=True)

show(cu) //    10,    






.8.   

 :   

cu = cube([10, 10, 10], center=False)

show(cu) //    10,       








. 9.   

 

    $fn    , ,      .

:    

c=cube(10);



mask=cube([30,1,30],center=True)



demo = [

c.fillet(2,fn=5)

]

show(demo)








. 10.    

 cube  PythonSCAD(Python)     ,       ,   ,   .



2.2.   "" (sphere)  PythonSCAD(OpenSCAD)

 sphere    3D-  PythonSCAD(OpenSCAD).     ,          .

:

sphere(r, $fn=100);



r   .     .

$fn  ,    ,    .   ,     .   ,     100.



:    10

sphere(10); //    10








. 11.    10

:    

sphere(10, $fn=50); //    10    (50 )








. 12.    

      ,        50   100.

:    

sphere(10, $fn=200); //    10    (200 )








. 13.    

       ,     .

: 

difference() {

sphere(10);

translate([-10, -10, 0]) cube([20, 20, 20]);

}






. 14. 

     ,   .     ,   .

:   

sphere(10, center=true); //    10,    






. 15.   

  center=true,       ,    ,        Z=0.

   sphere     ,   ,         PythonSCAD(OpenSCAD).



2.2.   "" (sphere)  PythonSCAD(Python)

:

sp = sphere(r)



r   .     .

:    10

sp = sphere(10)

show(sp)








. 16.    10

:    

sp = sphere(10)

fil = sp.fillet(1)

show(fil)






. 17.    

      ,        50   100.

:    

sp = sphere(10)

fil = sp.fillet(100)

show(fil)








. 18.    

       ,     .

: 

sp = sphere(10)

cu = cube(20)

cu = cu.translate([-10, -10, 0])

diff = sp.difference(cu)

cu = cu.translate([20, 20, 10])

show(diff)








. 19. 

   sphere     ,   ,         PythonSCAD(Python).



2.3.   "" (cylinder)  PythonSCAD(OpenSCAD)

 cylinder  PythonSCAD(OpenSCAD)      .     ,       .



cylinder(h, r, center);

cylinder(h, r1, r2, center);



h   .

r    (     ).

r1     (  ).

r2     (  ).

center=true/false   true,     Z (  false).

$fn   ,   .



: 

cylinder(h=20, r=10);








. 20.  

   20   10.

   Z=0,     Z=20.

: 

cylinder(h=20, r=10, center=true);








. 21.  

   Z,     Z=0 (   Z=-10,   Z=10).

: ( )

cylinder(h=30, r1=5, r2=15);








. 22.  (   )

  r1=5,   r2=15,  30.

  .

: ( )

cylinder(h=30, r1=15, r2=5);








. 23.  ( )

  15,  5,    .

:  ($fn)

cylinder(h=30, r=10, $fn=100);








. 24.   ($fn)

$fn=100   ,    .

:  (  $fn)

cylinder(h=30, r=10, $fn=6);








. 25.   (  $fn)

   6-  ( ).



 cylinder  PythonSCAD(OpenSCAD)    ,    .    ,         3D.



2.3.   "" (cylinder)  PythonSCAD(Python)

 cylinder  PythonSCAD(OpenSCAD)      .     ,       .



cy = cylinder(h, r1, r2)



h   .

r    (     ).

r1     (  ).

r2     (  ).

 

: 

cy = cylinder(20, 10)

show(cy)








. 26. 

: ( )

cy = cylinder(h=30, r1=5, r2=15)

show(cy)






. 27.  ( )

: ( )

cy = cylinder(h=30, r1=15, r2=5)

show(cy)






. 28.  ( )



 cylinder 

PythonSCAD(Python)

   ,    .    ,         3D.



2.4.    OpenSCAD: 

polygon



polyhedron

 OpenSCAD           :

polygon    2D-.

polyhedron    3D- .

polygon  2D-

    ,        .

:

polygon(points, paths);

points    [x, y],   .

paths ()     (     ).

 

: 

polygon(points=[[0,0], [10,0], [5,10]]);






. 29. 

    (0,0), (10,0), (5,10).

:    

polygon(points=[[0,0], [10,0], [12,5], [5,10], [-2,5]], paths=[[0,1,2,3,4]]);






. 30.    

      .

:    ( )

polygon(

points=[[0,0], [10,0], [10,10], [0,10], [3,3], [7,3], [7,7], [3,7]],

paths=[[0,1,2,3,0], [4,5,6,7,4]]

);






. 31.    ( )

     .

 2D-  3D

 2D-    3D   linear_extrude:

linear_extrude(height=5) polygon(points=[[0,0], [10,0], [5,10]]);

     5.

2. 

polyhedron

 3D- 

      ,      .



:

polyhedron(points, faces, convexity);

points     [x, y, z].

faces   ,      .

convexity (,   10)       ( ).

 

:  ()

polyhedron(

points=[[0,0,0], [10,0,0], [5,10,0], [5,5,10]],

faces=[[0,1,2], [0,1,3], [1,2,3], [2,0,3]]

);






. 32.  ()

     .

:   polyhedron ( cube)

polyhedron(

points=[[0,0,0], [10,0,0], [10,10,0], [0,10,0], [0,0,10], [10,0,10], [10,10,10], [0,10,10]],

faces=[[0,1,2,3], [4,5,6,7], [0,1,5,4], [1,2,6,5], [2,3,7,6], [3,0,4,7]]

);








. 33.   polyhedron ( cube)

  ( cube(10),     ).

:  

polyhedron(

points=[[0,0,0], [10,0,0], [10,10,0], [0,10,0], [5,5,10]],

faces=[[0,1,2,3], [0,1,4], [1,2,4], [2,3,4], [3,0,4]]);






. 34.  

    .



 polygon  polyhedron     2D  3D .  ,    (cube, sphere, cylinder)     .



   OpenSCAD: 

polygon

 

polyhedron

 OpenSCAD           :

polygon    2D-.

polyhedron    3D- .

1. 

polygon

 2D-

    ,        .



:

po = polygon(points, paths);

points    [x, y],   .

paths ()     (     ).

 

: 

po = polygon(points=[[0,0], [10,0], [5,10]])

show(po)






. 35. 

    (0,0), (10,0), (5,10).

:    

po = polygon([[0,0], [10,0], [12,5], [5,10], [-2,5]],[[0,1,2,3,4]])

show(po)






. 36.    

      .

:    ( )

po = polygon([[0,0], [10,0], [10,10], [0,10], [3,3], [7,3], [7,7], [3,7]],[[0,1,2,3,0], [4,5,6,7,4]]

)

show(po)






. 37.    ( )

     .

 2D-  3D

 2D-    3D   linear_extrude:

po = polygon(points=[[0,0], [10,0], [5,10]])

l = po.linear_extrude(5)

show(l)








. 38. 

     5.

2. polyhedron  3D- 

      ,      .



:

polyhedron(points, faces, convexity);

points     [x, y, z].

faces   ,      .

convexity (,   10)       ( ).

 

:  ()

po = polyhedron([[0,0,0], [10,0,0], [5,10,0], [5,5,10]],[[0,1,2], [0,1,3], [1,2,3], [2,0,3]]

)

show(po)






. 39.  ()

     .

:   polyhedron ( cube)

po = polyhedron([[0,0,0], [10,0,0], [10,10,0], [0,10,0], [0,0,10], [10,0,10], [10,10,10],[0,10,10]],

[[0,1,2,3], [4,5,6,7], [0,1,5,4], [1,2,6,5],[2,3,7,6], [3,0,4,7]])

show(po)






. 40.   polyhedron ( cube)

  ( cube(10),     ).

: 

po = polyhedron([[0,0,0], [10,0,0], [10,10,0], [0,10,0], [5,5,10]],[[0,1,2,3], [0,1,4], [1,2,4], [2,3,4], [3,0,4]])

show(po)








. 41.  

    .



 polygon  polyhedron     2D  3D .  ,    (cube, sphere, cylinder)     .



 1:  

       PythonSCAD(OpenSCAD)?

1)sphere()

2)circle()

3)ellipse()

4)ball()

5)round()

 2: 

     ?

1)r

2)d

3)size

4)radius

5)length

 3:  

     PythonSCAD(OpenSCAD)?

1)cube()

2)rectangle()

3)square()

4)block()

5)box()

 4:  

    10 x 20 x 30?

1)cube([10,20,30])

2)cube(10,20,30)

3)cube(size=[10,20,30])

4)cube({10,20,30})

5)cube<10,20,30>

 5:  

    50   10?

1)cylinder(h=50, r=10)

2)cylinder(10,50)

3)cylinder(radius=10, height=50)

4)cylinder(h=10, r=50)

5)cylinder(d=10, h=50)

 6:  

      (    )?

1)r1, r2

2)d1, d2

3)scale

4)radius_top, radius_bottom

5)trunc

 7:  

   ?

1)cylinder(r1=10, r2=0, h=20)

2)pyramid()

3)cylinder(10,0,20)

4)trapezoid()

5)cone()

 8:  2D-

   2D-?

1)square()

2)rectangle()

3)box2D()

4)shape()

5)plane()

 9:  2D-

   15x25?

1)square([15,25])

2)square(15,25)

3)rect([15,25])

4)square({15,25})

5)square<15,25>

 10:  

   ?

1)polyhedron(points, faces)

2)polyhedron()

3)polygon()

4)mesh()

5)shape3D()

 11:  2D-

   2D-?

1)circle()

2)sphere()

3)round()

4)ellipse()

5)disc()

 12:  2D-

    2D-?

1)circle(d=20)

2)circle(radius=20)

3)circle(r=20)

4)circle(diameter=20)

5)circle(20)

 13:  2D-

   2D-?

1)scale([1,2]) circle(10)

2)ellipse_shape()

3)oval()

4)ellipse(10,20)

5)circle([10,20])

 14:  

       ?

1)difference()

2)subtract()

3)union()

4)intersect()

5)add()

 15:  

     ?

1)intersection()

2)merge()

3)blend()

4)unite()

5)overlap()

 16:   

    ?

1)union()

2)merge()

3)sum()

4)group()

5)combine()

 1: 

     PythonSCAD(OpenSCAD)?

1)cu = cube(size)

2)c = cube(x, y, z)

3)c = coil(size)

4)sp = sphere(radius)

 2: 

     ?

1)(r)

2)(radius)

3)(size)

4)(tall)

 3: 

       PythonSCAD(OpenSCAD)?

1)cu = cube(Size)

2)cu = sphere(r)

3)c = cylinder(h, r)

4)sp = sphere(r)

 4:  

    10 x 20 x 30?

1)cu = cube(10, 20, 30)

2)cube(10, 20, 30)

3)cu.cube(10, 20, 30)

4)cube = cu(10, 20, 30)

 5:  

    50   10?

1)cy = cylinder(50, 10, 10)

2)cy = cylinder(50, 10)

3)cylinder(10, 50)

4)cy = cylinder(10, 50)

 6:  

      (    )?

1)r1 r2

2)h

3)L1 L2

4)W

 7:  

   ?

1)cy = cylinder(r1=10, r2=0, h=20)

2)sp = sphere(r1=10, r2=0, h=20)

3)c = conus(r1=10, r2=0, h=20)

4)tr = trapezoid(r1=10, r2=0, h=20)

 8:  2D-

   2D-?

1)sq = square()

2)b = box2D()

3)p = plane()

4)c = coil()

 9:  2D-

   15x25?

1)sq = square([15,25])

2)square([15,25])

3)sq = ([15,25])

4)sq = square[15,25]

 10:  

   ?

1)poly = polyhedron(point, path)

2)poly = polyhedron

3)poly = (point, path)

4)polyhedron(point, path)

 11:  2D-

   2D-?

1)c = circle()

2)c = circle

3)circle()

4)c = ()

 12:  2D-

    2D-?

1)c = circle(20)

2)circle(20)

3)c = (20)

4)c = circle

 13:  2D-

   2D-?

1)c = circle(10) cc = c.scale([1,2])

2)0 = oval()

3)cc = c.scale([1,2])

4)c = circle(10)

 14:  

       ?

1)diff = difference()

2)fusion = union()

3)union()

4)difference()

 15:  

     ?

1)inter = .intersection()

2)m = merge()

3)b = blend()

4)u = union()

 16:   

    ?

1)fusion = union()

2)diff = .difference()

3)inter = .intersection()

4)b = blend()



 3:   

 (

union

)  

PythonSCAD

(

OpenSCAD

)

 PythonSCAD(OpenSCAD)  union()          .    ,   ,    3D-.



union() {

1;

2;



}

   union()    .

 union()    ,   OpenSCAD    ,       {}.

 

 1:    

union() {

cube([10, 10, 10]);

translate([5,5,10])

cylinder(10, 5);

}






.1.     

 10?10?10    10   5    .

    [5,5,0],     .

 2:  union() ( )

cube([10,10,10]);

translate([5,5,10])

cylinder(10, 5);






.2.   union() ( )

OpenSCAD     ,   union().

 3:  

union() {

cube([10, 10, 10]);

translate([5,5,20])

cylinder(10, 5);

translate([5,5,15])

sphere(5);

}






.3.   

        .

 4:  difference()

  union()  difference()    :

difference() {

union() {

cube([20,20,10]);

translate([5,5,0]) cylinder(h=10, r=10);

}

translate([10,10,-1]) cylinder(h=12, r=5);

}






.4.   difference()

   .

    .



union()        .    ,      {}.     difference()  intersection().



 (union)  PythonSCAD(Python)

 PythonSCAD(Python)  union()          .    ,   ,    3D-.



from openscad import *



x = 1



y = 2



fusion = union([x,y])



show(fusion)

   union()    .

 union()    ,   OpenSCAD    ,       {}.

 

 1:    

from openscad import *



cu = cube(10)



cy = cylinder(10, 5)



fusion = union([cu,cy])



show(fusion)






. 5.     

 10?10?10    10   5    .

 2:  union() ( )

from openscad import *



cu = cube(10)



cy = cylinder(12, 5)



cy = cy.translate([5, 5, 0])



show([cu, cy])






. 6.   union() ( )

OpenSCAD     ,   union().

 3:  

from openscad import *



sp = sphere(5)



cu = cube(10)



cy = cylinder(20)



fusion = union([cu,cy,sp])



show(fusion)






. 7.   

,        .



4:





difference()

from openscad import *



cu = cube([20, 20, 10])



cy = cylinder(10, 10)



cy2 = cylinder(12, 5)



cu = cu.translate([5,5,0])



cy = cy.translate([10,10,0])



cy2 = cy2.translate([10,10,-1])



fusion = union([cu, cy])



diff = fusion.difference(cy2)



show(diff)






. 8.   difference()





union()        .    ,      {}.     difference()  intersection().





(difference) 



PythonSCAD(OpenSCAD)

 difference()  OpenSCAD          .      (Boolean operations),     3D-      .



difference() {

_;

__1;

__2;



}

    difference()  .

     .

 

 1:  

difference() {

cube([20, 20, 10]); // :  20?20?10

translate([10,10,-1]) //   ,    

cylinder(h=12, r=5); //    12   5

}






. 9.   

   ,   .

 2:  

difference() {

cube([30, 30, 10]); //  

translate([10,10,-1]) cylinder(h=12, r=5); //  

translate([20,20,-1]) cylinder(h=12, r=5); //  

}






. 10.   

 30?30?10    .

 3:     

difference() {

cube([30, 30, 10], center=true); //   ()

cube([20, 20, 12], center=true); //   () 

}






. 11.      

   ,     .



difference()   ,   .  ,    ,   .      union()  intersection().





(difference) 



PythonSCAD(Python)

 difference()  OpenSCAD          .      (Boolean operations),     3D-      .



from openscad import *

x = 1

y = 2

diff = x.difference(y)

show(diff)

    difference()  .

     .

 

 1:  

from openscad import *

cu = cube([3, 3, 2]) //    3x3x2

cy = cylinder(4, 1) //     

cy = cy.translate([1.5 , 1.5 , -1]) //     

diff = cu.difference(cy) //       

show(diff)






. 12.   

   ,   .

 2:  

from openscad import *

cu = cube([3, 7, 2]) //  

cy = cylinder(4, 1) //  

cy = cy.translate([1.5 , 1.5 , -1]) //   

cy2 = cylinder(4, 1) //   

cy2 = cy2.translate([1.5 , 5 , -1]) //   

diff = cu.difference([cy, cy2]) //        

show(diff)






. 13.   

 3:     

from openscad import *

x = cube([3, 3, 1]) //   ()

y = cube([2, 2, 1.2]) //   () 

y = y.translate([0.5 , 0.5 , 0.1]) //   

diff = x.difference(y) //  

show(diff)






. 14.      

   ,     .



difference()   ,   .  ,    ,   .





(intersection) 



PyhtonSCAD(OpenSCAD)

 intersection()     ()      .      (Boolean operations),        .



intersection() {

1;

2;



}

   .

 ,   , .

 

 1:   

intersection() {

cube([20, 20, 20], center=true); //  20x20x20

sphere(r=15); //   15

}






. 15.    

  ,     .

 2:   

intersection() {

cylinder(h=30, r=10); //  

cube([20, 20, 15], center=true); //  ()

}






. 16.    

  ,   .

 3:  

intersection() {

cube([30,30,10]); //   

translate([10,10,0]) sphere(15); //  

translate([15,0,0]) cylinder(h=10, r=10); //  

}






. 17.   

      .

 4:  difference()

  intersection()   difference(),       :

intersection() {

difference() {

cube([30,30,10]);

translate([5,5,-1]) cylinder(h=12, r=10);

}

translate([10,10,0]) sphere(15);

}






. 18.   difference()

    .

     .



intersection()       .      .     union()  difference().





(intersection) 



PyhtonSCAD(Python)

 intersection()     ()      .      (Boolean operations),        .



from openscad import *

x = 1

y = 2

inter = x.intersection(y)

show(inter)

   .

 ,   , .

 

 1:   

from openscad import *

cu = cube(20)

sp = sphere(15)

inter = cu.intersection(sp)

show(inter)






. 19.    

  ,     .

 2:   

from openscad import *

cu = cube([20, 20, 15])

cy = cylinder(30, 10)

inter = cu.intersection(cy)

show(inter)






. 20.    

  ,   .

 3:  

from openscad import *

cu = cube([30,30,10])

sp = sphere(15)

cu = cu.translate([10,10,0])

cy = cylinder(10, 10)

cy = cy.translate([15,0,0])

inter = sp.intersection([cy, cu])

show(inter)






. 21.   

      .

 4:  difference()

  intersection()   difference(),       :

from openscad import *

cu = cube([30,30,10])

sp = sphere(15)

cy = cylinder(12, 10)

cy = cy.translate([15,0,-1])

sp = sp.translate([10,10,0])

diff = cu.difference(cy)

inter = diff.intersection(sp)

show(inter)






. 22.   difference()

    .

     .



intersection()       .      .     union()  difference().



 1: 

     ?

1)sphere()

2)circle()

3)ball()

4)round()

 2:

     ?

1)r

2)d

3)radius

4)length

 3: 

   ?

1)cube()

2)rectangle()

3)block()

4)square()

5)box()

 4:

    10x20x30?

1)cube([10,20,30])

2)cube(10,20,30)

3)cube(size=[10,20,30])

4)cube({10,20,30})

5)cube<10,20,30>

 5: 

    50   10?

1)cylinder(h=50, r=10)

2)cylinder(10,50)

3)cylinder(radius=10, height=50)

4)cylinder(h=10, r=50)

5)cylinder(d=10, h=50)

 6:

      (    )?

1)r1, r2

2)scale

3)d1, d2

4)radius_top, radius_bottom

5)trunc

 7:

   ?

1)cylinder(r1=10, r2=0, h=20)f

2)trapezoid()

3)cone()

4)pyramid()

5)cylinder(10,0,20)

 8: 

   2D-?

1)square()

2)rectangle()

3)box2D()

4)shape()

5)plane()

 9:

   15x25?

1)square([15,25])

2)square(15,25)

3)rect([15,25])

4)square({15,25})

5)square<15,25>

 10: 

   ?

1)polyhedron()

2)polygon()

3)polyhedron(points, faces)

4)mesh()

5)shape3D()

 11: 

   2D-?

1)circle()

2)sphere()

3)round()

4)ellipse()

5)disc()

 12: 2D-

    2D-?

1)circle(d=20)

2)circle(radius=20)

3)circle(r=20)

4)circle(diameter=20)

5)circle(20)

 14:

       ?

1)difference()

2)union()

3)intersect()

4)add()

5)subtract()

 15:

     ?

1)intersection()

2)merge()

3)blend()

4)unite()

5)overlap()

 16:

    ?

1)union()

2)merge()

3)sum()

4)group()

5)combine()

 1: 

     ?

1)sp = sphere(r)

2)r = round()

3)x = cube()

4)l = coil()

 2:

     ?

1)r

2)x

3)v

4)w

 3: 

   ?

1)cu = cube()

2)sp = sphere()

3)cy = cylinder()

4)tr = trasnparent()

 4:

    10x20x30?

1)cu = cube([10, 20, 30])

2)cu = cube(10, 20, 30)

3)sp = sphere([10, 20, 30])

4)cy = cylinder(10, 20, 30)

 5: 

    50   10?

1)cy = cylinder(50, 10)

2)cy = cube(50, 10)

3)cy = sphere(50, 10)

4)r = round(5)

 6:

      (    )?

1)r1, r2

2)v1, v2

3)h

4)g

 7:

   ?

1)cy =cylinder(10, 5 ,0)

2)cy =cylinder(10, 0 ,5)

3)cy =cylinder(10, 5)

4)cy =cylinder(10, 5 ,5)

 8:

       ?

1)

2)

 9:

    ?

1)diff = fusion.difference(.....)

2)fusion = union([diff, x])

3)diff = x.difference(.....)

4)c = coil()

 10:

     ?

1)fusion = union([cu, sp])

2)diff = sp.difference()cu

3)inter = sp.intersection(cu)

4)c = cu.coil(sp)

 11:

     ?

1)fusion = union([cy, sp])

2)inter = cy.intersection(cu, sp)

3)diff = cy.difference(cu)

4)c = cu.coil(sp)

 12:

     ?

1)diff = cy.difference(cu)

2)c = coil()

3)fusion = union([cy, sp])

4)inter = cy.intersection(cu, sp)

 13:

   ,   ?

1)inter = cy.intersection(cu, sp)

2)fusion = union([cy, sp])

3)c = coil()

4)diff = cy.difference(cu)

 14:

       ?

1)diff = .difference()

2)fusion = union([])

3)inter = .intersection()

4)c = coil()

 15:

     ?

1)inter = intersection()

2)c = coil()

3)diff = difference()

4)fusion = union()

 16:

    ?

1)fusion = union()

2)c = coil()

3)diff = difference()

4)inter = intersection()

 4:  



(rotate) 



PythonSCAD(OpenSCAD)

 rotate()          (X, Y, Z).       3D-.



rotate([_X, _Y, _Z]) ;

_X     X ( ).

_Y     Y ( ,   ).

_Z     Z ( ).

    ()     (  )   (  ).

       :

rotate(, [x, y, z]) ;

 [x, y, z]      (1   , 0  ).

 

 1:   Z

rotate([0, 0, 45]) cube([10, 20, 5]);








. 1.    Z

   45   Z.

 2:   

rotate([30, 45, 0]) cylinder(h=20, r=5);






. 2.    

   30  X   45  Y.

 3:   

rotate(60, [1, 1, 0]) cube([10, 10, 10]);








. 3.    

   60   XY.

 4:  translate()

    ,      :

translate([10, 0, 0])

rotate([0, 0, 45]) cube([10, 10, 10]);






. 4.   translate()

  ,   .

    (rotate() ? translate()),       ,   .

 5:    (for)

for (i = [0:30:360]) {

rotate([0, 0, i]) translate([20, 0, 0]) sphere(2);

}






. 5.    (for)

  ,   30  .



rotate([x, y, z])       .    ,    translate().   for,    .



(rotate) 



PythonSCAD(Python)

 rotate()          (X, Y, Z).       3D-.



rotated=.rotate([_X, _Y, _Z])

_X     X ( ).

_Y     Y ( ,   ).

_Z     Z ( ).

    ()     (  )   (  ).

 [x, y, z]      (1   , 0  ).

 

 1:   Z

from openscad import *

cu = cube([10, 20, 5])

rotated = cu.rotate([0, 0, 45])

show(rotated)






. 6.    Z

   45   Z.

 2:   

cy = cylinder(20, 5)

rotated = cy.rotate([30, 45, 0])

show(rotated)






. 7.    

   30  X   45  Y.

 3:   

cu = cube([10, 10, 10])

rotated = cu.rotate(60, [1, 1, 0])

show(rotated)








.8.    

   60   XY.

 5:  

translate

()

cu = cube([10, 10, 10])

cu = cu.translate([10, 0, 0])

rotated = cu.rotate([0, 0, 45])

show(rotated)






. 9.   translate()

  ,   .

    (rotate() ? translate()),       ,   .



rotate([x, y, z])       .    ,    translate().   for,    .





(translate) 



PythonSCAD(OpenSCAD)

 translate()      3D-   X, Y  Z.



translate([X, Y, Z]) ;



X     X (   ,   ).

Y     Y (   ,   ).

Z     Z (   ,   ).

 

 1:  

translate([10, 20, 5]) cube([10, 10, 10]);








. 10.   

  10?10?10   10  , 20   5 .

 2:  

translate([0, 0, 15]) sphere(10);






. 11.   

  10   15  .



3:



translate()



rotate()

translate([20, 0, 0])

rotate([0, 0, 45]) cube([10, 10, 10]);






. 12.  translate()  rotate()

  ,  .

    (rotate() ? translate()),   !

 4:    

for

-

for (i = [0:20:60]) {

translate([i, 0, 0]) sphere(5);

}






. 13.     for-

  ,    X  0, 20  40 .



5:



Translate()

translate([10, 0, 0]) {

translate([0, 20, 0]) cube([10, 10, 10]);

}






. 14.  Translate()

    10   X,

     20  Y.



translate([X, Y, Z])    3D-.        rotate().    for    .





(translate) 



PythonSCAD(Python)

 translate()      3D-   X, Y  Z.



x = .translate([x, y, z])

X     X (   ,   ).

Y     Y (   ,   ).

Z     Z (   ,   ).

 

 1:  

from openscad import *

cu = cube([10, 10, 10])

tr = cu.translate([10, 20, 5])

show(tr)






. 15.   

  10?10?10   10  , 20   5 .

 2:  

from openscad import *

sp = sphere(10)

tr = sp.translate([0, 0, 15])

show(tr)






. 16.   

  10   15  .



3:



translate()



rotate()

cu = cube([10, 10, 10])

tr = cu.translate([20, 0, 0])

rotated = tr.rotate([0, 0, 45])

show([rotated])






. 17.  translate()  rotate()

  ,  .

    (rotate() ? translate()),   !

 4:    for





from openscad import *

sp = sphere(5)

result = sp

for i in range(1, 4):

result = result | sp.translate([15 * i, 0, 0])

show(result)






. 18.     for-



5:



translate()

cu = cube([10, 10, 10])

tr = cu.translate([10, 10, 10])

tr2 = tr.translate([10, 0, 0])

show(tr2)






. 19.  translate()

    10   X,

     20  Y.



translate([X, Y, Z])    3D-.        rotate().    for    .





(scale) 



PythonSCAD(OpenSCAD)

 scale()        X, Y  Z.         .



scale([Sx, Sy, Sz]) ;

Sx     X ().

Sy     Y ().

Sz     Z ().

 Sx, Sy, Sz < 1   .

 Sx, Sy, Sz > 1   .

 Sx, Sy, Sz = 1     .

 

 1:    2 

scale([2, 2, 2]) cube([10, 10, 10]);






. 20.     2 

  10?10?10   20?20?20.

 2:   

scale([2, 1, 1]) cylinder(h=10, r=5);






. 21.    

   2   X,      .

 3:  

scale([1, 1, 0.5]) sphere(10);






. 22.   

   2   ,    .

 4:  ( )

scale([-1, 1, 1]) cube([10, 10, 10]);






. 23.   ( )

    X ( ).

  -1   ,     .

 5:  

for (i = [1:0.5:2]) {

scale([i, i, i]) sphere(10);

}






. 24.   

    ,   10  20 .



scale([X, Y, Z])       .  ,    .     translate()  rotate()   .



 (scale)  PythonSCAD(Python)

 scale()        X, Y  Z.         .



scale =  * ([Sx, Sy, Sz])

Sx     X ().

Sy     Y ().

Sz     Z ().

 Sx, Sy, Sz < 1   .

 Sx, Sy, Sz > 1   .

 Sx, Sy, Sz = 1     .

 

 1:    2 

from openscad import *

cu = cube([10, 10, 10])

scale = cu * ([2, 2, 2])

show(scale)






. 25.     2 

  10?10?10   20?20?20.

 2:   

from openscad import *

cy = cylinder(h=10, r=5)

scale = cy * ([2, 1, 1])

show(scale)






. 26.    

   2   X,      .

 3:  

from openscad import *

sp = sphere(10)

scale = sp * ([1, 1, 0.5])

show(scale)






. 27.   

   2   ,    .

 4:  ( )

cu = cube([10, 10, 10])

scale = cu * ([-1, 1, 1])

show(scale)






. 28.   ( )

    X ( ).

  -1   ,     .



 1:

       ?

1)translate()

2)position()

3)moveTo()

4)displace()

5)offset()

 2: 

     15  X, -10  Y  5  Z?

1)translate([15, -10, 5])

2)shift([15, -10, 5])

3)translate(15, -10, 5)

4)move([15, -10, 5])

5)position(15, -10, 5)

 3:

    ?

1)scale()

2)zoom()

3)expand()

4)stretch()

5)resize()

 4:

    2    ?

1)scale([0.5, 0.5, 0.5])

2)scale(0.5, 0.5, 0.5)

3)scale([0.5])

4)resize([0.5, 0.5, 0.5])

5)shrink(0.5)

 5:

     90    Y?

1)rotate([0,90,0])

2)rotate(a=90, v=[0,1,0])

3)rotateY(90)

4)turn([0,90,0])

5)spin(90, [0,1,0])

 6: 

       XY?

1)mirror([0,0,1])

2)reflect([1,1,0])

3)mirror([0,1,0])

4)flip([0,1,0])

5)invert([0,0,1])

 7:  

      ,    ?

1)resize()

2)stretch()

3)scale()

4)expand()

5)adjustSize()

 8: 

   ?

1)% cube([10,10,10])

2)transparency(0.5)

3)opacity(50)

4)fade(50)

5)alpha(0.5)

 9: 

   ,    ?

1)*cube([10,10,10])

2)hide()

3)invisible()

4)disable()

5)remove()

 10: 

     2D-?

1)linear_extrude()

2)push()

3)extrude()

4)stretch_extrude()

5)height_extrude()

 11: 

  2D-  20  ?

1)linear_extrude(height=20)

2)extrude(20)

3)push(20)

4)stretch(20)

5)lift(20)

 12: 

    2D-?

1)rotate_extrude()

2)twist_extrude()

3)spin_extrude()

4)circular_extrude()

5)revolve()

 13:

     ?

1)offset()

2)expand()

3)outline()

4)thicken()

5)hollow()

 14:

     ?

1)minkowski()

2)smooth()

3)round()

4)bevel()

5)soften()

 15:

      ?

1)minkowski() { cube([10,10,10]) sphere(2) }

2)round_cube()

3)smooth_cube(10, 2)

4)soften_cube(10, 2)

5)bevel_cube([10,10,10], 2)

 16: 

     ?

1)clone()

2)repeat()

3)for()

4)array()

5)loop()

 1:

       ?

1)rotated = .rotate()

2)c = coil

3)diff = .difference()

4)inter = .intersection()

 2: 

     15  X, -10  Y  5  Z?

1)tr = .translate([15, -10, 5])

2)translate([15, -10, 5])

3)c = coil([15, -10, 5])

4)rotated = .rotate([15, -10, 5])

 3:

    ?

1)Scale = * ()

2)tr = .translate()

3)c = coil()

4)translate([15, -10, 5])

 4:

    2    ?

1)scale = * -2

2)Sc = scale * -2

3)scale = * 2

4)Sc = scale * 2

 5:

     90    Y?

1)rotated = .rotate([0,90,0])

2)rotated =([0,90,0])

3)x = ([0,90,0])

4)([0,90,0]) = x

 6:

       XY?

1)mr = .mirror([0,0,1])

2)mirror([0,0,1])

3)mr = ([0,0,1])

4)mr = mirror

 7:  

      ,    ?

1)re = .resize([])

2)c = coil([])

3)re = ([])

4)resize([])

 8: 

       ?

1)diff = re.difference(cy)

2)c = re.coil(cy)

3)fusion = union([re, cu])

4)inter = re.intercection(cu)

 9: 

       ?

1)inter = re.intersection(cy)

2)c = cu.coil(re)

3)diff = re.difference(cy)

4)fusion = union([re, cu])

 10: 

     2D-?

1)l=linear_extrude(square(),[[],[], [],[]]);

2)path_extrude()

3)linear_extrude

4)l = linear_extrude()

 11: 

  2D-  20  ?

1)p=path_extrude(square(1),[[0,0,0],[0,0,20]]);

2)rotate_ extrude(square(1),[[0,0,0],[0,0,20]]);

3)l=linear_extrude(square(1),[[0,0,0],[0,0,20]]);

4)e=extrude(square(1),[[0,0,0],[0,0,20]]);

 12: 

    2D-?

1)circle(3).right(10).rotate_extrude(v=[0,0,20],angle=600).show()

2)linear_extrude()

3)path_extrude()

4)extrude()

 13:

     ?

1).offset()

2).clone()

3).array()

4).loop()

 14:

     ?

1).fillet

2).edge

3).core

4).ore

 15:

      ?

1).fillet

2).edge

3).core

4).ore

 16: 

     ?

1)con = .clone()

2)f = for()

3)loo = loop()

4)ar = array()

 5:  



  PythonSCAD(OpenSCAD)     =     : , ,   .  ,  PythonSCAD(OpenSCAD)   ,      .

  :

width = 10;

height = 20;

depth = 30;

cube([width, height, depth]);

      .

 

 1: 

x = 5;

x = 10; //    x,   5

echo(x); //  5






. 1.  

 2: 

y = x + 5; //    x (, 5)

echo(y); //  10






. 2.  



  PythonSCAD(OpenSCAD)      ,   :      (PI, GOLDEN_RATIO),      .

 :

PI = 3.141592;

GOLDEN_RATIO = 1.618;

RADIUS = 50;

circle(RADIUS);



 

     ,      .

 1: 

base_diameter = 40;

height = base_diameter / 2; //    

cylinder(d=base_diameter, h=height);






. 3.  

  (let)

       let().

openscad

let(r = 10) {

circle(r);

}

  r     let().

   echo

 echo()        .

a = 5;

b = a * 2;

echo(" b:", b); // : ECHO: " b:", 10



:

1)  PythonSCAD(OpenSCAD)  .

2)   .

3)     let().

4) echo()   .



  PythonSCAD(Python)         : , ,   .  ,  PythonSCAD(Python)   ,      .

  :

width = 10;

height = 20;

depth = 30;

c = cube([width, height, depth]);

show(c)

      .

 

 1: 

x = 5

x = 10 //    x,   5

cu = cube(x)

show(cu) //    5






. 4.  

 2: 

x = 5

x = 10

y = x + 5 //    x (, 5)

cu = cube(y)

show(cu) //    10






. 5.  





  PythonSCAD(Python)      ,   :      (PI, GOLDEN_RATIO),      .

PI = 3.141592;

GOLDEN_RATIO = 1.618;

RADIUS = 50;

circle(RADIUS);



 

     ,      .

 3: 

base_diameter = 40;

height = base_diameter / 2; //    

cy = cylinder(d=base_diameter, h=height);

show(cy)






. 6.  

  (let)

       example().

 4:  (let)

def example():

x = 10

y = 20

return x + y

result = cube(example())

show(result)






. 7.   (let)

  r     example().



 show()        .

from openscad import *

a = 5

b = a * 2

cu = cube(b)

show(cu) //      b

:

  PythonSCAD(Python)  .    .      let().



    PythonSCAD(OpenSCAD)

PythonSCAD(OpenSCAD)          .            ,  OpenSCAD   .

 1: 

      function,     .        .

function square(x) = x * x;

echo(square(5)); // ECHO: 25






. 8.  

  square(x)      .

 2:   

function sum(a, b) = a + b;

echo(sum(10, 20)); // ECHO: 30






. 9.    

 3:  ( )

function abs_value(x) = x >= 0 ? x : -x;

echo(abs_value(-7)); // ECHO: 7






. 10.   ( )

 abs_value(x)     .

 4: 

OpenSCAD  ,   .



function factorial(n) = (n <= 1) ? 1 : n * factorial(n  1);

echo(factorial(5)); // ECHO: 120






. 11.  

 5:   

function sum_list(lst) = (len(lst) == 0) ? 0 : lst[0] + sum_list([for (i = 1; i < len(lst); i = i + 1) lst[i]]);

echo(sum_list([1, 2, 3, 4, 5])); // ECHO: 15






. 12.   

 6:   

function operation(type, x) = (type == "square") ? x * x : (type == "double") ? x * 2 : x;

echo(operation("square", 4)); // ECHO: 16

echo(operation("double", 4)); // ECHO: 8






. 13.    

 7:   

function diameter(radius) = radius * 2;

module custom_cylinder(r) {

cylinder(d = diameter(r), h = 10);



}

custom_cylinder(15);






. 14.    

 diameter(r)   ,      custom_cylinder.



  ,      .   ,  ,     .       .

         .



 

   ,      .

 1:  

//      

function gear_radius(base_r, teeth, tooth_height) =

base_r + tooth_height * (teeth > 0 ? 1 : 0);

//    

module gear(base_r, teeth, tooth_height) {



difference() {

//   

circle(r = gear_radius(base_r, teeth, tooth_height), $fn = 100);

//    

for(i = [0:teeth-1]) {

angle = i * (360 / teeth);

translate([base_r * cos(angle), base_r * sin(angle)])

rotate(angle)

square([tooth_height * 2, base_r * 0.2], center = true);

}

}

}

//      

gear(base_r = 20, teeth = 12, tooth_height = 3);






. 15.   

  

 gear_radius    ,   .

 gear:

   .

   for    .

    : gear(20, 12, 3),    ,     .

 

     .

 2:    

module gear(base_r, teeth, tooth_height, hole_r = 5) {

difference() {

//   

circle(r = gear_radius(base_r, teeth, tooth_height), $fn = 100);

//  



for(i = [0:teeth-1]) {

angle = i * (360 / teeth);

translate([base_r * cos(angle), base_r * sin(angle)])

rotate(angle)

square([tooth_height * 2, base_r * 0.2], center = true);

}

//  

circle(r = hole_r, $fn = 50);

}

}

//     

gear(base_r = 20, teeth = 16, tooth_height = 3, hole_r = 6);






. 16.     

    ,   ,      .

  ,           .         .



    PythonSCAD(Python)

PythonSCAD(Python)          .            ,  OpenSCAD   .

 1: 

 

def square(x):

return x * x

result = square(5)

print(result)






. 17.  

  square(x)      .

 2:   

def sum(a, b):

return a + b

result = sum(10, 20)

print(result)






. 18.    

 3:  ( )

def absolute_value(x):

if x < 0:

return -x

return x

result = absolute_value(-7)

print(result)






. 19.   ( )

 abs_value(x)     .

 4: 



def factorial(n):

if n < 0:

return "     "

elif n == 0 or n == 1:

return 1

else:

result = 1

for i in range(2, n + 1):

result *= i

return result

result = factorial(5)

print(result)






. 20.  

 5:  

def sum_list(lst):

total = 0

for element in lst:

total += element

return total

result = sum_list([1, 2, 3, 4, 5])

print(result)






. 21.   

    .

 6:   

def operation(type, lst):

return [type(x) for x in lst]

def square(x):

return x * x

def double(x):

return x * 2

number = [4]

squared = operation(square, number)

doubled = operation(double, number)

print(squared)

print(doubled)






. 22.    

 7:   

def cylinder_module(radius, height):

output = f"""

module cylinder_module(r, h) {{

//  

translate([0, 0, 0])

cylinder(r = r, h = h, center = true);

}}

cylinder_module({radius}, {height});

"""

return output

radius = 5

height = 10

cylinder_code = cylinder_module(radius, height)

print(cylinder_code)






. 23.    



  ,      .   ,  ,     .       .

         .



 

   ,      .

 1:   

import math



def gear_radius(base_r, teeth, tooth_height):

"""     ."""

return base_r + tooth_height * (1 if teeth > 0else 0)



def gear(base_r, teeth, tooth_height):

"""    ."""

output = "difference() {\n"

#   

output += f" circle(r = {gear_radius(base_r, teeth, tooth_height)}, $fn = 100);\n"

#    

for i in range(teeth):

angle = i * (360 / teeth)

x = base_r * math.cos(math.radians(angle))

y = base_r * math.sin(math.radians(angle))

output += f" translate([{x}, {y}])\n"

output += f" rotate({angle})\n"

output += f" square([{tooth_height * 2}, {base_r * 0.2}], center = true);\n"

output += "}\n"

return output



#     

gear_code = gear(base_r=20, teeth=12, tooth_height=3)

print(gear_code)






. 24.    

 

1. gear_radius



     .

2. gear



 ,   .



 `difference()`      .

3.  for



  ,      .

4. translate  rotate



      .

5. 



   ,     PythonSCAD.

 

     .

 1:    

def cos(angle):

import math

return math.cos(math.radians(angle))

def sin(angle):

import math

return math.sin(math.radians(angle))

def radians(degrees):

import math

return degrees * (math.pi / 180)

def circle(r, fn=100):

return f'circle(r={r}, $fn={fn})'

def square(size, center=False):

return f'square(size={size}, center={center})'

def translate(vector):

return f'translate({vector})'

def rotate(angle):

return f'rotate(angle={angle})'

def difference(*shapes):

return 'difference() {' + ''.join(shapes) + '}'

def gear_radius(base_r, teeth, tooth_height):

return base_r + tooth_height

def create_gear(base_r, teeth, tooth_height, hole_r=5):

gear_shape = difference(

circle(gear_radius(base_r, teeth, tooth_height), fn=100)

)

for i in range(teeth):

angle = i * (360 / teeth)

x = base_r * cos(angle)

y = base_r * sin(angle)

tooth = translate([x, y, 0])(

rotate(angle)(

square([tooth_height * 2, base_r * 0.2], center=True)

)

)

gear_shape += tooth

#  

central_hole = circle(hole_r, fn=50)

gear_shape += central_hole

return gear_shape

#     

gear_model = create_gear(base_r=20, teeth=16, tooth_height=3, hole_r=6)




  .


   .

   ,     (https://www.litres.ru/book/vitaliy-vitalevich-krylov/pythonscad-v-zadachah-i-primerah-72440416/)  .

      Visa, MasterCard, Maestro,    ,   ,     ,  PayPal, WebMoney, ., QIWI ,       .


