Provide a detailed summary of the following web content, including what type of content it is (e.g. news article, essay, technical report, blog post, product documentation, content marketing, etc). If the content looks like an error message, respond 'content unavailable'. If there is anything controversial please highlight the controversy. If there is something surprising, unique, or clever, please highlight that as well: Title: Convex Hulls – The Metapict Blog Site: soegaard.github.io The Metapict Blog Jens Axel Søgaard, jensaxel@soegaard.net 1 Introduction 2 Arrows 3 Regular polygons 4 Venn Diagrams 5 Simple Block Diagrams - Passes in Racket 6 Clock 7 Convex Hull 7.1 Convex Hull - A first algorithm 7.2 Convex Hull - An incremental algorithm Index 1. Introduction This blog features small programs using Metapict to draw figures and images. Write to Jens Axel Søgaard at jensaxel@soegaard.net with comments and wishes for new topics. 2. Arrows First let’s work on images of size 200x200 and let us keep the default user window which has an \(x\) -range from -1 and 1 and an \(y\) -range from -1 to 1. Given a curve c , the form draw-arrow is used to draw the curve and arrow head(s). Let’s define some curves we can turn into arrows. Here ( arc C A B ) draws a circular arc from \(A\) to \(B\) with center \(C\) . > ( draw   ( draw-arrow   c1 )           ( draw-arrow   c2 )           ( draw-double-arrow   c3 ) ) The default behavior is to draw an arrow head at the end of the curve. Use draw-double-arrow to draw arrow heads at both at the beginning and end of the curve. The discussion below goes into detail with the shape of the default arrow head, but let’s demonstrate that there are alternative arrow heads available. > ( draw   ( draw-arrow   c1   #:head   arrow-head                          #:tail   line-head )           ( draw-arrow   c2   #:head   harpoon-up                          #:tail   harpoon-down )           ( draw-arrow   c3   #:head   hook-head                          #:tail   reverse-hook-head ) ) Here “ah” is short for “arrow head”. Several parameters affect the size and shape of the default arrow head. The most important is ahlength which holds the length of the arrowhead. > ( draw   ( my-arrow   0.04   c1 )           ( my-arrow   0.08   c2 )           ( my-arrow   0.16   c3 ) ) The unit used by ahlength is user coordinates. This can at times be inconvenient, so you can use ( px x ) to compute the size of \(x\) pixels expressed in user coordinates. > ( draw   ( my-arrow   ( px    4 )   c1 )           ( my-arrow   ( px    8 )   c2 )           ( my-arrow   ( px   16 )   c3 ) ) Now, let’s look closer at the default arrow head: The default value for the parameter ahangle is 45 (degrees). Let’s try different values for the parameter ahangle . And to make room for several arrow heads, we will reduce the pict size. If you have two arrows pointing to the same point, and you feel the overlap of the two arrow heads is too large, consider using a smaller value for ahangle . The parameter ahflankangle controls the “flank angle”. The default is 10 (degrees). > ( ahangle   45 ) > ( define   ( head   angle )       ( ahflankangle   angle )       ( draw-arrow   ( curve   ( pt   0   0 )   --   ( pt   1   0 ) ) ) ) > ( beside   ( head   5 )   ( head   10 )   ( head   15 )   ( head   20 )   ( head   25 ) ) The parameter ahtailcurvature controls the “tail curvature”. The default is 2. > ( ahflankangle   10 ) > ( define   ( head   curvature )       ( ahtailcurvature   curvature )       ( draw-arrow   ( curve   ( pt   0   0 )   --   ( pt   1   0 ) ) ) ) > ( beside   ( head   2 )   ( head   4 )   ( head   8 )   ( head   16 )   ( head   32 ) ) Finally, the parameter ahratio controls the size of the indentation relative to the length of the arrow head. The default value is 0.9. > ( ahtailcurvature   2 ) > ( define   ( head   ratio )       ( ahratio   ratio )       ( draw-arrow   ( curve   ( pt   0   0 )   --   ( pt   1   0 ) ) ) ) > ( beside   ( head   1 )   ( head   0.9 )   ( head   0.8 )   ( head   0.7 )   ( head   0.6 ) ) We can get a boring, standard arrow head like this: > ( ahflankangle   0 ) > ( ahtailcurvature   0 ) > ( ahratio   1 ) > ( draw-arrow   ( curve   ( pt   0   0 )   --   ( pt   1   0 ) ) ) Let’s set our parameters back to the default: > ( ahlength   ( px   4 ) ) > ( ahangle   45 ) > ( ahflankangle   10 ) > ( ahtailcurvature   2 ) > ( ahratio   0.89 ) > ( draw-arrow   ( curve   ( pt   0   0 )   --   ( pt   1   0 ) ) ) The parameters are convenient to use to set the appearance of all arrows in a figure. If you need special values for a few arrows, then pass the settings as keyword arguments. > ( draw   ( draw-arrow          c1   #:length          ( px   8 ) )           ( draw-arrow          c2   #:length-ratio    1 )           ( draw-double-arrow   c3   #:head-angle      30 ) ) Apropos options, let’s play with colors and filling of the arrow heads. > ( ahlength   ( px   8 ) ) > ( draw   ( draw-arrow   c1   #:color   "red" )           ( draw-arrow   c2   #:fill-head   #f )           ( draw-arrow   c3                   #:stem-color   "blue"                   #:head-color   "cyan"                   #:head-outline-color   "darkgreen" ) ) 3. Regular polygons In this example we will see several ways of drawing regular polygons. We begin by importing metapict and setting the “curve pict size”. When a curve is drawn by draw , the curve is drawn on a pict with this size. Let’s draw a little test curve to see this. > ( draw   ( point   "red"      ( pt   -1    0 ) )           ( point   "violet"   ( pt    1    1 ) )           ( point   "blue"     ( pt    0   -1 ) )           ( curve   ( pt   -1   0 )   --   ( pt   1   1 )   --   ( pt   0   -1 ) ) ) We see that the default user coordinates has an \(x\) -range \[\text{from } x_\text{min}=-1 \text{ to } x_\text{max}=1, \] and an \(y\) -range given by \[\text{from } y_\text{min}=-1 \text{ to } y_\text{max}=1. \] We will stick with this default window for now. We can manually draw a regular polygon with \(n=3\) sides: > ( draw   ( color   "gray"   ( draw   ( circle   1 ) ) )           ( curve      ( pt   1   0 )                  --   ( pt   ( cosd   120 )   ( sind   120 ) )                  --   ( pt   ( cosd   240 )   ( sind   240 ) )                  --   cycle ) ) Here ( cosd d ) and ( sind d ) computes the cosine and sine respectively to \(d\) degrees. The function call ( pt@d r θ ) will return the point \(P\) that a distance \(r\) from the origin \(O(0,0);\) the angle between the \(x\) -axis and \(P\) will be \(θ\) degrees. The d in pt@d stands for degrees. Using this function, we can write our example as: In a similar fashion we can draw a regular polygon with \(n=4\) sides: We begin to see a pattern. The points on the regular polygon with \(n\) sides can be computed like this: In order to draw the polygon, we need to add the path connector -- between each point – and append -- cycle . Since curve is a macro, we can’t apply curve to our path description, instead we use the function version named curve* . And we can now draw a regular polygon with \(n=6\) sides: > ( draw   ( regular   6 ) ) 4. Venn Diagrams In this section we are drawing Venn diagrams. First we will set the size of the image and the window in user coordinates. Let’s begin by drawing two circles with radius 5. > ( def   r   5 ) > ( def   s   ( /   r   1.8 ) ) > ( def   c1   ( circle   ( pt   ( -   s )   0 )   r ) ) > ( def   c2   ( circle   ( pt      s    0 )   r ) ) > ( draw   c1   c2 ) Now let’s pick some nice colors: The call ( color-med f color1 color2 ) interpolates between the two colors. Let’s also pick a font: > ( def   font   ( make-similar-font   ( new-font )                                  #:size   15                                  #:face   "Arial" ) ) We are now ready to tackle the problem of filling the inside of both circles. The function fill is used to fill a curve. The pen is used for outlines and the brush is used for areas. Setting brushcolor will fill the inside with a solid color. The rule used to determine whether a point \(P\) is in the interior: Given a point \(P\) , consider a ray from \(P\) towards infinity. For each intersection between the ray and t