package OSCADml

  1. Overview
  2. Docs
OCaml DSL for 3D solid modelling in OpenSCAD

Install

Dune Dependency

Authors

Maintainers

Sources

OSCADml-0.2.2.tbz
sha256=8c0eeb5055dd16bb0f9b25b4d21d5312c431969fd0871fc045df2f93147ae39a
sha512=b28bd304ef3196193ba6fe33f51f0f1e2c6bb3cd41c47335a513d9fb4b1f5eca8bcbabcf8683d9b35e3cbd4f3dabe2c7bcc8f5c4b087f96a7ac70117fc4babfa

doc/polar_rose.html

Polar Rose

open OCADml
open OSCADml

Define a function that takes a radius r and angle a, and returns a z coordinate. This rose function is ported from the examples given in the plot function OpenSCAD library.

let rose ~r ~a =
  let open Float in
  let x =
    pow
      ( (r *. cos a *. cos (r *. 8. *. pi /. 180.))
      +. (r *. sin a *. sin (r *. 35. *. pi /. 180.)) )
      2.
    /. -300.
  in
  ((15. +. (5. *. sin (r *. 10. *. pi /. 180.))) *. exp x) +. 1.

Starting from the origin, step outward radially with r_step increments up to a maximal radius of max_r. For each of these radii, rose will be evaluated with angles revolving around the z-axis, evaluating to the height off of the XY plane that that position should be.

let mesh = Mesh.polar_plot ~r_step:0.2 ~max_r:22. rose

As the generated mesh contains quite a large number of points due to the relatively low value of r_step (megabytes), we'll take advantage of the include trick provided by the optional ?incl parameter to Scad.to_file. This will produce a pair of .scad scripts, one named "incl_polar_rose.scad", and another named "polar_rose.scad" that simply includes it. By loading the later into OpenSCAD rather than the former, we can avoid the sluggishness that can result when the editor attempts to handle large files.

let () = Scad.to_file ~incl:true "polar_rose.scad" (Scad.of_mesh mesh)

OCaml

Innovation. Community. Security.