Various Things in MetaPost
habr.com
habr.com
For those who may not know much about MetaPost, it was originally written by Donald Knuth's student John Hobby, to a great extent based (both syntax and code of the program itself) on METAFONT, written by Knuth for designing fonts, as the companion to TeX. The idea is to describe shapes—either shapes of letters (glyphs in the typeface) in case of METAFONT, or other shapes in case of MetaPost—by telling the computer how to draw them, i.e. writing a program that describes the shape. The program automatically computes intersections of lines, joins points using “most pleasing curves” (Hobby splines), etc. See for example Figure 6 in this post whose code is simply
beginfig(6);
draw sphere.c(1.2cm);
draw sphere.c(2.4cm) shifted (2cm, 0);
endfig;
after the author has defined the sphere.c function (macro) with shading and shadows etc (https://github.com/jemmybutton/fiziko/blob/2ccb6e1/fiziko.mp...).It's really a fantastic way to draw for certain people, but it requires you to think about the shape to a greater level of detail (enough to write a program basically) than simply drawing it, so it's not for everyone. The syntax of other similar programs like TikZ and Asymptote has also been greatly influenced by that of METAFONT/MetaPost.
BTW the author of this post here (jemmybutton / Sergey Slyusarev) is also the author of [Fancy Euclid's “Elements” in TeX] that was posted here a while ago: https://news.ycombinator.com/item?id=20019616
Thank you for putting this together, and for sharing it!
I see the greater hurdle in marrying the sampling-based nature of SDF rendering with MetaPost's vector graphics. You'd probably need a rasterized image at high resolution (which includes the "hatch direction" information for each pixel) and then approximate it with vector strokes.
With all that said, MetaPost probably isn't the best tool to deal with "real" 3D problems, and implementing (and re-implementing) these algorithms in some conventional 3D software could be a better option.