I was given a homework assignment in one of my courses that asked us to google the Metapost language and find the use for the equation solving feature in the language. After going through the first dozen or so pages of the Metapost user manual I found only one reason as to why it's useful and it's that "allows many programs to be written in a largely declarative style." Besides stating that it makes the programming more "declarative" (which from what I understood means that we tell the language what to do as opposed to how to do it) I couldn't think of any other reason why the equations solving is useful. Can anyone help me out?
1
There are 1 best solutions below
Related Questions in METAPOST
- How to use postscripts from metapost as images in graphviz?
- Algorithm to traverse edges of a hex grid between two points
- makefile for metapost: how to compile file-N.pdf
- How to convert numeric parameter to text in a MetaPost macro
- Strange Metapost parenthesis bug
- MetaPost output an empty picture when using label
- Strings in mpost for loop
- METAPOST: using loop variables in labels
- Metapost Equations
- Asymptote: resizing the picture (including pen widths and font sizes)
- Is it possible to include one MetaPost file into another?
- Should I buy a book on both LaTeX and MetaPost, or just MetaPost?
- How to generate a polygon number figure using metapost?
- How to view output .mp files from Functional MetaPost
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Here is an illustration of how solving equations in MetaPost — and declarative programming, for that matter — might be useful.
Suppose we want to draw a die:
To do that, let us first define a macro which will draw a single face of the die: a square with number
son it.Now we can draw it and get the picture:
Next, we need an upper face and a right face. To draw them, we will have to compose an affine transformation to skew them. This can be tricky since the only readily available primitive transformation for skewing is
slanted awhich transforms a point(x, y)into(x + ay, y). Here is our picture slanted 1:We will then (or rather, before that) have to scale by one of the coordinates:
The same approach does not work for the third face right away:
After a bit of experimentation, we find the right code:
But why all the tedium? We know exactly what transformation we need. One natural way to express it is by using primitives. But if that proves unintuitive, as our last line was, it may be more comfortable to just specify which points of the plane transform to which.
This basically tells MetaPost: there is a transform
t, under which the three points we specified move to the other three points we specified. Turns out this uniquely determines a plane transformation, and we get the same picture:Putting all that together (the code is
beginfig (7)at end of post) allows us to finally see our die:In this simple case, the “coordinates and equations” approach is comparable in difficulty to the “primitive transformations” approach. Now, imagine we wanted a slight tilt for our cube. With the same declarative approach, it would be still possible without invoking three-dimensional geometry (the code is
beginfig (8)at end of post):The complete program is below.