<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="/pattern.xsl"?>
<pattern id="">
  <name>
    Mapping
  </name>
  <relatedPatterns>
    <relatedPattern ref="">
      <patternLink>Controller</patternLink>
    </relatedPattern>
    <relatedPattern ref="">
      <patternLink>Jig</patternLink>
    </relatedPattern>
  </relatedPatterns>
  <diagram>
  <web>
  <img src="DiagramMapp.gif" width="400"/>
  </web>
  <latex>
    <img src="DiagramMapp.pdf" width="400"/>
	</latex>
  </diagram>
  <what>
    <paragraph>
      Use a function in a new domain and range.
    </paragraph>
  </what>
  <when>
    <paragraph>
      <latex>\index{function|(}</latex>
      <latex>\index{function!domain|(}</latex>
      <latex>\index{function!range|(}</latex>
      <latex>\index{transformation!mapping|(}</latex>
      A function accepts inputs and produces a value. Geometric functions such
      as <math latex="\afFunc{f}{x} = \afFunc{sin}{x}">sine</math>, <math
      latex="\afFunc{f}{x} = \afFunc{cos}{x}">cosine</math>, <math
      latex="\afFunc{f}{x} = x^2">x*x</math> and <math latex="\afFunc{f}{x} =
      1/x">1/x</math> are extremely common in parametric modeling. In fact, they
      form an indispensable base for much modeling work. These functions all
      naturally defined over their own domains and ranges. Use this pattern when
      you want to use a function in the domain and range specific to a model.
    </paragraph>
    <paragraph>
      The terms <em>domain</em> and <em>range</em> need to be explained. The
      domain of a function is the set of input values over which it is defined
      or used. The range of a function is the set of output values it
      generates. For example, we might chose to use a domain of <math
      latex="0">0</math> to <math latex="360">360</math> degrees for the <math
      latex="\afFunc{sin}{x}">sin</math> function. This corresponds to its natural
      repetitive cycle. The range generated by <math
      latex="\afFunc{sin}{x}">sin</math> over this domain is <math
      latex="-1">-1</math> to <math latex="1">1</math>.
  <latex>

\begin{tikzpicture}[domain=0:6.2832,
  dimension/.style={|-|,black,thin}] 
  \draw[very thin,color=gray, xstep = 0.7854, ystep = 1] (-0.1,-1.1) grid (6.4,1.1); 
  \draw[->] (-0.2,0) -- (6.5,0) node[right] {$x$}; 
  \draw[->] (0,-1.2) -- (0,1.2) node[above] {$f(x)$}; 
  \draw[color=red, thick] plot (\x,{sin(\x r)}) node[below=6mm] {$f(x) = \sin(x)$}; 
  \drDim{(0,-1)}{(6.2832,-1)}{-8mm}{Domain $= 0$ : $360$}{0.5}{3mm}
  \drDim{(6.2832,-1)}{(6.2832,1)}{-12mm}{Range $= -1$ : $1$}{0.5}{5mm}
\end{tikzpicture} 

  </latex>

<web>
  <diagram>
    <img src="MappingFunctionDomainRange.jpg" width="400"/>
  </diagram>
</web>
    </paragraph>
  </when>
  <why>
    <paragraph>
      Much form-making in design comes directly from relatively simple
      functions, for many reasons. The repetitive use of simple functions can
      unify a design across its parts and across design scales. If the ease and
      cost of fabrication is a concern, simple functions can help control
      complexity and/or cost (but do not necessarily do so). In contrast, the
      so-called <em>free-form</em> curves and surfaces provide interfaces to
      more complex functions, but cede some control of the form-making process
      to the underyling algorithms.
    </paragraph>
    <paragraph>
      Simple functions come with natural domains and ranges. It is much, much
      easier to think about a function in its natural domain and range than in
      some transformed version.
    </paragraph>
    <paragraph>
      To use a function in a model requires reframing it so that it
      makes sense in the model. Reframing turns out to be a
      suprisingly difficult and error-prone process for many
      designers. Yet, there is a universal method of precisely seven
      parameters that works for almost all reframing tasks. Further
      this method is based on one simple equation---essentially the
      same equation that defines a one-dimensional <em>affine map</em> or,
      equivalently, an <em>affine function</em>.
    </paragraph>
    <paragraph>
      The term "affine map" is extremely common in linear algebra and
      its dependent fields (computer graphics and geometric
      modeling). It has a precise mathematical meaning, and we use
      this meaning here---precision of language is important! An
      affine map is a <em>linear transformation</em> followed by a
      translation. In turn, a linear transformation preserves the
      operations of vector
      addition<latex>\index{vector!addition}</latex> and scalar
      multiplication<latex>\index{vector!scalar
      multiplication}</latex> --- you can add or multiply before or
      after the transformation and the result is the same.  In one
      dimension (for instance, the real number line), the only linear
      transformation is scaling. A 1D affine map changes a function's
      scale and moves it along the real number line. The function
      <math latex = "\afFunc{f}{x}">f(x)</math> becomes <math latex =
      "\afFunc{g}{x}">g(x)</math> under the affine map.
    </paragraph>
    <paragraph>
      <latex>

\begin{tikzpicture}[domain=0:6.2832,
  dimension/.style={|-|,black,thin}] 
  \draw[very thin,color=gray, xstep = 0.7854, ystep = 1] (-0.1,-1.1) grid (6.4,1.1); 
  \draw[->] (-0.2,0) -- (6.5,0) node[right] {$x$}; 
  \draw[->] (0,-1.2) -- (0,1.2) node[above] {$\afFunc{f}{x}$}; 
  \draw[color=blue] plot (\x,{sin(\x r)}) node[below=6mm] {$\afFunc{f}{x} = \sin(x)$}; 
  \draw[color=red, domain=0.7854:3.9270, thick] plot (\x,{1.5*sin(2.0*(\x-0.7854) r)}) node[below=15mm] {$\afFunc{g}{x} = 1.5\sin(2(x-45))$}; 
  \drDim{(0.7854,-1)}{(3.9270,-1)}{-13mm}{New Domain $= 45$ : $225$}{0.5}{3mm}
  \drDim{(0,-1)}{(6.2832,-1)}{-23mm}{Domain $= 0$ : $360$}{0.5}{3mm}
  \drDim{(6.2832,-1)}{(6.2832,1)}{-12mm}{Range $= -1$ : $1$}{0.5}{5mm}
  \drDim{(6.2832,-1.5)}{(6.2832,1.5)}{-22mm}{New Range $= -1.5$ : $1.5$}{0.5}{5mm}
\end{tikzpicture} 

      </latex>
      <web>
	<diagram>
	  <img src="MappingAffineMapQualitative.jpg" width="400"/>
	</diagram>
      </web>
    </paragraph>


    <paragraph>
      The problem for modeling is that determining the new function
      <math latex = "\afFunc{g}{x})">g(x)</math> is not easy. If you
      watch a modeler trying to get such a mapping to "work" you will
      see much trial and error. Looking at the function in the figure
      above $\afFunc{g}{x} = 1.5\sin(2(x-45))$ gives some indication
      why the task is so hard in practice. Which number does what?
      Why? 
    </paragraph>

    <paragraph>
      This pattern replaces all of the function-specific changes with
      a uniform structure and set of parameters. You never have to
      work with a function in any but its simplest
      form. <patternName>Mapping</patternName> separates where the
      <em>model</em> uses a function from where the function is defined. 
    </paragraph>
  </why>
  <how>
    <paragraph>
      Consider two rectangles, called the <em>function</em> and the
      <em>model</em> respectively. The function rectangle<latex>\index{rectangle}</latex> is given by
      the domain and range of the function represented within it. The
      model rectangle can be any size and location you choose. The
      goal is to place the original function into the model. The basic
      idea is to always use the function rectangle when computing the
      function. To find a point on the function in the model, map from
      the model domain to the function domain (blue arrow 1 below),
      compute the function (red and green arrows in the function box)
      and them map from the result back to the model range (blue arrow
      2 below).
    </paragraph>

    <paragraph>
      <latex>

\begin{drGen}{0.4}{domain=0:6.2832}

  \pgfmathsetmacro{\figD}{2.6} 
  \pgfmathsetmacro{\figSin}{sin(\figD r)} %
  \pgfmathsetmacro{\figFnXScale}{0.5}
  \pgfmathsetmacro{\figFnYScale}{1} %
  \pgfmathsetmacro{\figFnDL}{0}
  \pgfmathsetmacro{\figFnDU}{6.2832} %
  \pgfmathsetmacro{\figFnRL}{-1}
  \pgfmathsetmacro{\figFnRU}{1} %
  \pgfmathsetmacro{\figMdDL}{7}
  \pgfmathsetmacro{\figMdDU}{14} %
  \pgfmathsetmacro{\figMdRL}{1}
  \pgfmathsetmacro{\figMdRU}{5} %
  \pgfmathsetmacro{\figGapOffset}{0.1}
  \pgfmathsetmacro{\figArrowOffset}{2}
  \pgfmathsetmacro{\figMdXScale}{(\figMdDU-\figMdDL)/(\figFnDU-\figFnDL)}
  \pgfmathsetmacro{\figMdYScale}{(\figMdRU-\figMdRL)/(\figFnRU-\figFnRL)}

{ % function box
  \pgftransformxscale{\figFnXScale}
  \pgftransformyscale{\figFnYScale}

  \draw[color=black] plot (\x,{sin(\x r)}) node[below=4mm] {\textsf{function}}; 
  \draw (\figFnDL,\figFnRL) rectangle (\figFnDU,\figFnRU); 

  \drLiSeg{(\figD,\figFnRL)}{(\figD,\figSin)}{vector,red}
  \drLiSeg{(\figD,\figSin)}{(\figFnDL,\figSin)}{vector,green}
  \drPtOpt{(\figD,\figSin)}{emphPointo}
}

{ % connector arrows
  % model to function
  \drLiSeg{(\figMdDL+\figD*\figMdXScale,\figFnRL-\figGapOffset)}{(\figMdDL+\figD*\figMdXScale,\figFnRL-\figArrowOffset)}{blue}
  \drLiSeg{(\figMdDL+\figD*\figMdXScale,\figFnRL-\figArrowOffset)}{(\figD*\figFnXScale,\figFnRL-\figArrowOffset)}{blue}
  \drLaLi{(\figMdDL+\figD*\figMdXScale,\figFnRL-\figArrowOffset)}{(\figD*\figFnXScale,\figFnRL-\figArrowOffset)}{\textsf{(1)}}{0.5}{-6mm}
  \drLiSeg{(\figD*\figFnXScale,\figFnRL-\figArrowOffset)}{(\figD*\figFnXScale,\figFnRL-\figGapOffset)}{vector,blue}
  % function to model
  \drLiSeg{(\figFnDL-\figGapOffset,\figSin*\figFnYScale)}{(\figFnDL-\figArrowOffset,\figSin)}{blue}
  \drLiSeg{(\figFnDL-\figArrowOffset,\figSin*\figFnYScale)}{(\figFnDL-\figArrowOffset,\figMdRL+\figMdYScale*\figSin)}{blue}
  \drLiSeg{(\figFnDL-\figArrowOffset,\figMdRL+\figMdYScale*\figSin)}{(\figMdDL-\figGapOffset,\figMdRL+\figMdYScale*\figSin)}{vector,blue}
  \drLaLi{(\figFnDL-\figArrowOffset,\figMdRL+\figMdYScale*\figSin)}{(\figMdDL-\figGapOffset,\figMdRL+\figMdYScale*\figSin)}{\textsf{(2)}}{0.5}{-6mm}
}

{ % model box
  \pgftransformxshift{\figMdDL cm} 
  \pgftransformyshift{\figMdRL cm} 
  \pgftransformxscale{\figMdXScale}
  \pgftransformyscale{\figMdYScale}

  \draw[color=orange, thick] plot (\x,{sin(\x r)}) node[below=8mm] {\textsf{model} \hspace{6mm}\quad}; 
  \draw (0,-1.0) rectangle (6.2832,1.0); 

  \drLiSeg{(\figD,\figSin)}{(\figD,-1)}{vector,red, dashed}
  \drLiSeg{(0,\figSin)}{(\figD,\figSin)}{vector,green}
  \drPtOpt{(\figD,\figSin)}{emphPointo}
}
\end{drGen} 

      </latex>
      <web>
	<diagram>
	  <img src="MappingAffineMapQualitative.jpg" width="400"/>
	</diagram>
      </web>
    </paragraph>

    <paragraph>
      What follows gives precise definition to the diagram.  Variables
      relating to a domain start with or have within a <math
      latex="d">d</math>; those over the range start with or have
      within an <math latex="r">r</math>. In one dimension, an affine
      map has a single equation, which we introduce first over the
      domain interval <math latex="0">0</math> to <math
      latex="1">1</math>.  Imagine a function with parameter <math
      latex="d">d</math> over this interval. An affine map from the
      interval <math latex="0">0</math> to <math latex="1">1</math> to
      the interval <math latex="\lbrack r_l,
      r_u\rbrack">[Rl,Ru]</math> with parameter <math
      latex="d">d</math> has the equation
	<latex>
	  \[\afFn{r}(d)= r_l + d(r_u - r_l), 0 \leq d \leq 1\]
	</latex>
	<web>
	  r(d)=Rl+d(Ru-Rl), 0 &lt;= d &lt;= 1
	</web> 
	Reversing the map to go from the range (<math
	latex="r">r</math>) to the domain (<math latex="d">d</math>) gives 
	<latex>
	  \[\afFn{d}(r)=\frac{r-r_l}{r_u-r_l},r_l\leq r \leq r_u \]
      </latex>
      <web>
	d(r)=(r-Rl)/(Ru-Rl), Rl &lt;= r &lt;= Ru
      </web>
      </paragraph>
      <paragraph>
      The map has domain <math latex="d">D</math> with bounds
      <math latex="0">0</math> to <math latex="1">1</math> and range
      <math latex="r">R</math> with bounds <math
      latex="r_l">Rl</math> and <math
      latex="r_u">Ru</math>.
    </paragraph>
    <paragraph>
    <web>
      <diagram>
    <img src="MappingAffineMapGeneral.jpg" width="400"/>
      </diagram>
    </web>
    </paragraph>
    <paragraph>
      Generalizing, to any domain produces the maps between <math
      latex="d">d</math> and <math latex="r">r</math> as follows:
    </paragraph>
    <paragraph>
      <latex>
	\[\afFn{d}(r)=\frac{(r-r_l)(d_u-d_l)}{r_u-r_l} + d_l,r_l\leq r \leq r_u\]
      </latex>
      <web>
	d(r)=((r-Rl)*(Du-Dl))/(Ru-Rl) + Dl, Rl &lt;= r &lt;= Ru
      </web>
    </paragraph>
    <paragraph>
      <latex>
	\[\afFn{r}(d)=\frac{(d-d_l)(r_u-r_l)}{d_u-d_l} + r_l,d_l\leq d \leq d_u\]
      </latex>
      <web>
	r(d)=((d-Dl)*(Ru-Rl))/(Du-Dl) + Rl, Dl &lt;= d &lt;= Du
      </web>
    </paragraph>
    <paragraph>
     Mathematically, these are simple equations, but require attention
     every time they are used. This purpose of this pattern is to
     abstract these equations so that designers can freely use generic
     and simple functions in their models.
    </paragraph>

    <paragraph> 
      WARNING. When using affine maps to apply a function, there are actually two
      maps to consider. One goes between the domain of the model and its
      domain in the function. The other goes between the range of the function and
      its range in the model. 
    </paragraph>

    <paragraph>
      Since the range of the function is determined by the function itself, this means
      that mapping between function and model can be described by exactly seven parameters: the
      lower and upper bounds of the function's domain (<math latex="\afWV{fd}_l">FDl</math> and
      <math latex="\afWV{fd}_u">FDu</math>); the lower and upper bounds of the model's domain
      (<math latex="\afWV{md}_l">MDl</math> and <math latex="\afWV{md}_u">MDu</math>); the lower and
      upper bounds of the model's range (<math latex="\afWV{mr}_l">MRl</math> and <math
      latex="\afWV{mr}_u">MRu</math>); and the functional parameter itself.
    </paragraph>
    <paragraph>
      These seven parameters describe every possible situation in
      which you want to use a function in a model. <em>Every possible
      situation!</em> Applying them though takes some insight. The
      archetypal problem is this: you have a value in the model and
      need to find the corresponding value of the function in the
      model. Giving more detail to the diagram above, the solution has
      three parts: (1) an affine map from the model to the function;
      (2) an application of the function; and (3) an affine map from
      the result of the function to the result in the model.  The
      following diagram demonstrates this flow, showing how the
      various parameters and bounds relate.
    </paragraph>

    <paragraph>
      <latex>
\begin{drGen}{0.4}{domain=0:6.2832}

  \pgfmathsetmacro{\figD}{2.6} 
  \pgfmathsetmacro{\figSin}{sin(\figD r)} %
  \pgfmathsetmacro{\figFnDL}{0}
  \pgfmathsetmacro{\figFnDU}{6.2832} %
  \pgfmathsetmacro{\figFnRL}{-1}
  \pgfmathsetmacro{\figFnRU}{1} %
  \pgfmathsetmacro{\figMdDL}{14}
  \pgfmathsetmacro{\figMdDU}{21} %
  \pgfmathsetmacro{\figMdRL}{3}
  \pgfmathsetmacro{\figMdRU}{7} %
  \pgfmathsetmacro{\figFnXScale}{(\figFnDU-\figFnDL)/(6.2832-0)}
  \pgfmathsetmacro{\figFnYScale}{(\figFnRU-\figFnRL)/(1-(-1))} %
  \pgfmathsetmacro{\figMdXScale}{(\figMdDU-\figMdDL)/(\figFnDU-\figFnDL)}
  \pgfmathsetmacro{\figMdYScale}{(\figMdRU-\figMdRL)/(\figFnRU-\figFnRL)}
  \pgfmathsetmacro{\figGapOffset}{0.1}
  \pgfmathsetmacro{\figBoxOffset}{1}
  \pgfmathsetmacro{\figTextXOffset}{2.5}
  \pgfmathsetmacro{\figTextYOffset}{1.5}
  \pgfmathsetmacro{\figLabelXOffset}{1.25}
  \pgfmathsetmacro{\figLabelYOffset}{0.5}
  \pgfmathsetmacro{\figTextVecLen}{0.5}
  \pgfmathsetmacro{\figFnBoxXOffset}{2*\figBoxOffset/\figFnXScale}
  \pgfmathsetmacro{\figFnBoxYOffset}{\figBoxOffset/\figFnYScale}
  \pgfmathsetmacro{\figMdBoxXOffset}{\figBoxOffset/\figMdXScale}
  \pgfmathsetmacro{\figMdBoxYOffset}{2*\figBoxOffset/\figMdYScale}
  \pgfmathsetmacro{\figArrowOffset}{3}


{ % function box
   \pgftransformxshift{0 cm} 
   \pgftransformyshift{1 cm} 
  \pgftransformxscale{0.5}
  \pgftransformyscale{1.5}

  \draw[color=black] plot (\x,{sin(\x r)}) node[below=4mm] {}; 
%  \draw (\figFnDL,\figFnRL) rectangle (\figFnDU,\figFnRU); 

  \drLiSeg{(\figD,\figFnRL-\figFnBoxYOffset)}{(\figD,\figSin)}{vector,red}
  \drLiSeg{(\figD,\figSin)}{(\figFnDL-\figFnBoxXOffset,\figSin)}{vector,green}
  \drPtOpt{(\figD,\figSin)}{emphPointo}

  \drLa{\textsf{function}}{(\figFnDL-7,\figFnRL-\figFnBoxYOffset)}

  \drLiSeg{(\figFnDU+\figFnBoxXOffset,\figFnRL-\figFnBoxYOffset)}{(\figFnDU+\figFnBoxXOffset+\figArrowOffset,\figFnRL-\figFnBoxYOffset)}{blue}
  \drLiSeg{(\figFnDU+\figFnBoxXOffset+\figArrowOffset,\figFnRL-\figFnBoxYOffset)}{(\figFnDU+\figFnBoxXOffset+\figArrowOffset,\figSin)}{blue}
  \drLiSeg{(\figFnDU+\figFnBoxXOffset+\figArrowOffset,\figSin)}{(\figD+8*\figGapOffset,\figSin)}{vector,blue}
   \drLaLi{(\figFnDU+\figFnBoxXOffset+\figArrowOffset,\figFnRL-\figFnBoxYOffset)}{(\figFnDU+\figFnBoxXOffset+\figArrowOffset,\figSin)}{\textsf{(2)}}{0.5}{14mm}

  \drLiSeg{(\figFnDL,\figFnRL-\figFnBoxYOffset)}{(\figFnDU,\figFnRL-\figFnBoxYOffset)}{red}
  \drPtOpt{(\figD,\figFnRL-\figFnBoxYOffset)}{emphPointo}
  \drPtOpt{(\figFnDL,\figFnRL-\figFnBoxYOffset)}{emphPointo}
  \drPtOpt{(\figFnDU,\figFnRL-\figFnBoxYOffset)}{emphPointo}
  \drLiSeg{(\figFnDL,\figFnRL-\figFnBoxYOffset)}{(\figFnDL,0)}{dashed, thin}
  \drLiSeg{(\figFnDU,\figFnRL-\figFnBoxYOffset)}{(\figFnDU,0)}{dashed, thin}
  \drLaLi{(\figFnDL,\figFnRL-\figFnBoxYOffset-\figTextYOffset)}{(\figFnDU,\figFnRL-\figFnBoxYOffset-\figTextYOffset)}{$\afWV{fd}_l$}{0.0}{-6mm}
  \drLaLi{(\figFnDL,\figFnRL-\figFnBoxYOffset-\figTextYOffset)}{(\figFnDU,\figFnRL-\figFnBoxYOffset-\figTextYOffset)}{$\afWV{fd}$}{0.5}{-6mm}
  \drLaLi{(\figFnDL,\figFnRL-\figFnBoxYOffset-\figTextYOffset)}{(\figFnDU,\figFnRL-\figFnBoxYOffset-\figTextYOffset)}{\hspace{1mm}$\afWV{fd}_u$}{0.99}{-6mm}
  \drLaLi{(\figFnDL,\figFnRL-\figFnBoxYOffset-\figTextYOffset-0.25*\figLabelYOffset)}{(\figFnDU,\figFnRL-\figFnBoxYOffset-\figTextYOffset-0.5*\figLabelYOffset)}{\footnotesize{\textsf{domain}}}{0.5}{-0.5mm}
  \drLiSeg{(\figFnDU-\figTextVecLen,\figFnRL-\figFnBoxYOffset-\figTextYOffset-0.25*\figLabelYOffset)}{(\figFnDU,\figFnRL-\figFnBoxYOffset-\figTextYOffset-0.25*\figLabelYOffset)}{vector, red}
  \drLiSeg{(\figFnDL+\figTextVecLen,\figFnRL-\figFnBoxYOffset-\figTextYOffset-0.25*\figLabelYOffset)}{(\figFnDL,\figFnRL-\figFnBoxYOffset-\figTextYOffset-0.25*\figLabelYOffset)}{vector, red}

  \drLiSeg{(\figFnDL-\figFnBoxXOffset, \figFnRU)}{(\figFnDL-\figFnBoxXOffset, \figFnRL)}{green}
  \drPtOpt{(\figFnDL-\figFnBoxXOffset, \figFnRU)}{emphPointo, green}
  \drPtOpt{(\figFnDL-\figFnBoxXOffset, \figSin)}{emphPointo, green}
  \drPtOpt{(\figFnDL-\figFnBoxXOffset, \figFnRL)}{emphPointo, green}
  \drLiSeg{(\figFnDU/4,\figFnRU)}{(\figFnDL-\figFnBoxXOffset,\figFnRU)}{dashed, thin}
  \drLiSeg{(\figFnDU*3/4,\figFnRL)}{(\figFnDL-\figFnBoxXOffset,\figFnRL)}{dashed, thin}
  \drLaLi{(\figFnDL-\figFnBoxXOffset-\figTextXOffset, \figFnRU)}{(\figFnDL-\figFnBoxXOffset-\figTextXOffset, \figFnRL)}{$\afWV{fr}_u$}{0.0}{-6mm}
  \drLaLi{(\figFnDL-\figFnBoxXOffset-\figTextXOffset, \figFnRU)}{(\figFnDL-\figFnBoxXOffset-\figTextXOffset, \figFnRL)}{$\afWV{fr}$}{0.5}{-6mm}
  \drLaLi{(\figFnDL-\figFnBoxXOffset-\figTextXOffset, \figFnRU)}{(\figFnDL-\figFnBoxXOffset-\figTextXOffset, \figFnRL)}{\hspace{1mm}$\afWV{fr}_l$}{0.99}{-6mm}
  \drLaLiSl{(\figFnDL-\figFnBoxXOffset-\figTextXOffset-\figLabelXOffset, \figFnRL)}{(\figFnDL-\figFnBoxXOffset-\figTextXOffset-\figLabelXOffset, \figFnRU)}{}{\footnotesize{\textsf{range}}}{0.5}{0.3mm}
  \drLiSeg{(\figFnDL-\figFnBoxXOffset-\figTextXOffset-\figLabelXOffset, \figFnRU-0.5*\figTextVecLen)}{(\figFnDL-\figFnBoxXOffset-\figTextXOffset-\figLabelXOffset, \figFnRU)}{vector, green}
  \drLiSeg{(\figFnDL-\figFnBoxXOffset-\figTextXOffset-\figLabelXOffset, \figFnRL+0.5*\figTextVecLen)}{(\figFnDL-\figFnBoxXOffset-\figTextXOffset-\figLabelXOffset, \figFnRL)}{vector, green}
}

{ % connector arrows
 \pgfmathsetmacro{\figFnRParam}{(\figSin-\figFnRL)/(\figFnRU-\figFnRL)}
  \pgfmathsetmacro{\figMdRLoc}{\figMdRL+\figFnRParam*(\figMdRU-\figMdRL)}
  % model to function
  \drLiSeg{(\figMdDL+\figD*\figMdXScale,\figFnRL-\figGapOffset)}{(\figMdDL+\figD*\figMdXScale,\figFnRL-\figArrowOffset-\figLabelYOffset-\figTextYOffset)}{blue}
  \drLiSeg{(\figMdDL+\figD*\figMdXScale,\figFnRL-\figArrowOffset-\figLabelYOffset-\figTextYOffset)}{(0.5*\figD*\figFnXScale,\figFnRL-\figArrowOffset-\figLabelYOffset-\figTextYOffset)}{blue}
  \drLaLi{(\figMdDL+\figD*\figMdXScale,\figFnRL-\figArrowOffset-\figLabelYOffset-\figTextYOffset)}{(0.5*\figD*\figFnXScale,\figFnRL-\figArrowOffset-\figLabelYOffset-\figTextYOffset)}{\textsf{(1)}}{0.5}{-6mm}
  \drLiSeg{(0.5*\figD*\figFnXScale,\figFnRL-\figArrowOffset-\figLabelYOffset-\figTextYOffset)}{(0.5*\figD*\figFnXScale,\figFnRL-\figArrowOffset-2*\figLabelYOffset)}{vector,blue}
  % function to model
  \drLiSeg{(\figFnDL-\figBoxOffset-\figTextXOffset,\figSin/\figFnYScale+1)}{(\figFnDL-\figBoxOffset-\figTextXOffset-0.5*\figArrowOffset,\figSin/\figFnYScale+1)}{blue}
  \drLiSeg{(\figFnDL-\figBoxOffset-\figTextXOffset-0.5*\figArrowOffset,\figSin/\figFnYScale+1)}{(\figFnDL-\figBoxOffset-\figTextXOffset-0.5*\figArrowOffset,\figMdRLoc)}{blue}
  \drLiSeg{(\figFnDL-\figBoxOffset-\figTextXOffset-0.5*\figArrowOffset,\figMdRLoc)}{(\figMdDL-\figMdBoxXOffset-\figTextXOffset-\figLabelXOffset, \figMdRLoc)}{vector,blue}
  \drLaLi{(\figFnDL-\figBoxOffset-\figTextXOffset-0.5*\figArrowOffset,\figMdRLoc)}{(\figMdDL-\figMdBoxXOffset-\figTextXOffset-\figLabelXOffset, \figMdRLoc)}{\textsf{(3)}}{0.5}{-6mm}
}

 { % model box

  \pgfmathsetmacro{\figMdRangeShift}{\figMdRL-\figFnRL*\figMdYScale}  
  \pgftransformxshift{\figMdDL cm} 
  \pgftransformyshift{\figMdRangeShift cm} 
  \pgftransformxscale{\figMdXScale}
  \pgftransformyscale{\figMdYScale}

  \draw[color=orange, thick] plot (\x,{sin(\x r)}) node[above=5mm] {\textsf{model} \hspace{6mm}\quad}; 
%  \draw (0,-1.0) rectangle (6.2832,1.0); 

  \drLiSeg{(\figD,\figSin)}{(\figD,\figFnRL-0.5*\figMdBoxYOffset)}{vector,red, dashed}
  \drLiSeg{(-\figMdBoxXOffset,\figSin)}{(\figD,\figSin)}{vector,green}
  \drPtOpt{(\figD,\figSin)}{emphPointo}
}

{
  \pgfmathsetmacro{\figFnDParam}{\figD/(\figFnDU-\figFnDL)}
  \pgfmathsetmacro{\figMdDLoc}{\figMdDL+\figFnDParam*(\figMdDU-\figMdDL)}
  \drLiSeg{(\figMdDL,\figMdRL-\figMdBoxYOffset)}{(\figMdDU,\figMdRL-\figMdBoxYOffset)}{red}
  \drPtOpt{(\figMdDL,\figMdRL-\figMdBoxYOffset)}{emphPointo}
  \drPtOpt{(\figMdDU,\figMdRL-\figMdBoxYOffset)}{emphPointo}
  \drPtOpt{(\figMdDLoc,\figMdRL-\figMdBoxYOffset)}{emphPointo}
  \pgfmathsetmacro{\figFnMdRC}{\figMdRL+0.5*(\figMdRU-\figMdRL)}
  \drLiSeg{(\figMdDL,\figMdRL-\figMdBoxYOffset)}{(\figMdDL,\figFnMdRC)}{dashed, thin}
  \drLiSeg{(\figMdDU,\figMdRL-\figMdBoxYOffset)}{(\figMdDU,\figFnMdRC)}{dashed, thin}
  \drLaLi{(\figMdDL,\figMdRL-\figMdBoxYOffset-\figTextYOffset)}{(\figMdDU,\figMdRL-\figMdBoxYOffset-\figTextYOffset)}{$\afWV{md}_l$}{0.0}{-6mm}
  \drLaLi{(\figMdDL,\figMdRL-\figMdBoxYOffset-\figTextYOffset)}{(\figMdDU,\figMdRL-\figMdBoxYOffset-\figTextYOffset)}{$\afWV{md}$}{0.5}{-6mm}
  \drLaLi{(\figMdDL,\figMdRL-\figMdBoxYOffset-\figTextYOffset)}{(\figMdDU,\figMdRL-\figMdBoxYOffset-\figTextYOffset)}{\hspace{1mm}$\afWV{md}_u$}{0.99}{-6mm}
  \drLaLi{(\figMdDL,\figMdRL-\figMdBoxYOffset-\figTextYOffset-\figLabelYOffset)}{(\figMdDU,\figMdRL-\figMdBoxYOffset-\figTextYOffset-\figLabelYOffset)}{\footnotesize{\textsf{domain}}}{0.5}{-0.5mm}
  \drLiSeg{(\figMdDU-3*\figTextVecLen,\figMdRL-\figMdBoxYOffset-\figTextYOffset-\figLabelYOffset)}{(\figMdDU,\figMdRL-\figMdBoxYOffset-\figTextYOffset-\figLabelYOffset)}{vector, red}
  \drLiSeg{(\figMdDL+3*\figTextVecLen,\figMdRL-\figMdBoxYOffset-\figTextYOffset-\figLabelYOffset)}{(\figMdDL,\figMdRL-\figMdBoxYOffset-\figTextYOffset-\figLabelYOffset)}{vector, red}

  \pgfmathsetmacro{\figFnRParam}{(\figSin-\figFnRL)/(\figFnRU-\figFnRL)}
  \pgfmathsetmacro{\figMdRLoc}{\figMdRL+\figFnRParam*(\figMdRU-\figMdRL)}
  \drLiSeg{(\figMdDL-\figMdBoxXOffset, \figMdRU)}{(\figMdDL-\figMdBoxXOffset, \figMdRL)}{green}
  \drPtOpt{(\figMdDL-\figMdBoxXOffset, \figMdRU)}{emphPointo, green}
  \drPtOpt{(\figMdDL-\figMdBoxXOffset, \figMdRLoc)}{emphPointo, green}
  \drPtOpt{(\figMdDL-\figMdBoxXOffset, \figMdRL)}{emphPointo, green}
  \pgfmathsetmacro{\figFnMdMax}{\figMdDL+0.25*(\figMdDU-\figMdDL)}
  \pgfmathsetmacro{\figFnMdMin}{\figMdDL+0.75*(\figMdDU-\figMdDL)}
  \drLiSeg{(\figFnMdMax,\figMdRU)}{(\figMdDL-\figMdBoxXOffset,\figMdRU)}{dashed, thin}
  \drLiSeg{(\figFnMdMin,\figMdRL)}{(\figMdDL-\figMdBoxXOffset,\figMdRL)}{dashed, thin}
  \drLaLi{(\figMdDL-\figMdBoxXOffset-\figTextXOffset, \figMdRU)}{(\figMdDL-\figMdBoxXOffset-\figTextXOffset, \figMdRL)}{$\afWV{mr}_u$}{0.0}{-6mm}
  \drLaLi{(\figMdDL-\figMdBoxXOffset-\figTextXOffset, \figMdRU)}{(\figMdDL-\figMdBoxXOffset-\figTextXOffset, \figMdRL)}{$\afWV{mr}$}{0.5}{-6mm}
  \drLaLi{(\figMdDL-\figMdBoxXOffset-\figTextXOffset, \figMdRU)}{(\figMdDL-\figMdBoxXOffset-\figTextXOffset, \figMdRL)}{\hspace{1mm}$\afWV{mr}_l$}{0.99}{-6mm}
  \drLaLiSl{(\figMdDL-\figMdBoxXOffset-\figTextXOffset-0.5*\figLabelXOffset, \figMdRL)}{(\figMdDL-\figMdBoxXOffset-\figTextXOffset-0.5*\figLabelXOffset, \figMdRU)}{}{\footnotesize{\textsf{range}}}{0.5}{0.3mm}
  \drLiSeg{(\figMdDL-\figMdBoxXOffset-\figTextXOffset-0.5*\figLabelXOffset, \figMdRU-2*\figTextVecLen)}{(\figMdDL-\figMdBoxXOffset-\figTextXOffset-0.5*\figLabelXOffset, \figMdRU)}{vector, green}
  \drLiSeg{(\figMdDL-\figMdBoxXOffset-\figTextXOffset-0.5*\figLabelXOffset, \figMdRL+2*\figTextVecLen)}{(\figMdDL-\figMdBoxXOffset-\figTextXOffset-0.5*\figLabelXOffset, \figMdRL)}{vector, green}
}

\end{drGen} 

      </latex>
      <web>
	<diagram>
	  <img src="MappingAffineMapQualitative.jpg" width="400"/>
	</diagram>
      </web>
    </paragraph>

    <paragraph>
      For example, consider a roof whose profile is taken from a
      <em>sine</em> curve. The roof spans from a point <math
      latex="\afPt[P]">P</math> in the model to another point <math
      latex="\afPt[Q]">Q</math>. A point <math
      latex="\afPt[M]">M</math> with parameter <math
      latex="m">m</math> gives the location of the roof point along
      the line between these two points. The maximum root height is
      given by a parameter. Over the span of the roof, it goes through
      two complete cycles of the <math latex="\afFn{sine}">sine</math>
      function. Then the following are the six mapping parameter
      settings. The seventh parameter is <math>m</math>, which gives
      the parametric location of a varying point on the roof.
    </paragraph>
    <paragraph>
      <math latex="\afFunc{f}{x} = \afFunc{sin}{x}">f(x) = sin(x)</math> 
    </paragraph>
    <paragraph>
      <math latex="\afWV{fd}_l = 0.0">FDl = 0.0</math>
    </paragraph>
    <paragraph>
      <math latex="\afWV{fd}_u = 720.0">FDu = 720.0</math>
    </paragraph>
    <paragraph>
      <math latex="\afWV{fr}_l = -1.0">FRl = -1.0</math> (defined by the function and thus computed automatically)
    </paragraph>
    <paragraph>
      <math latex="\afWV{fr}_u = 1.0">FRu = 1.0</math> (defined by the function and thus computed automatically)
    </paragraph>
    <paragraph>
      <math latex="\afWV{md}_l = 0.0">MDl = 0.0</math> (<math latex="\afPt[M]">M</math> is  parameterized by <math latex="m">m</math> over the domain <math latex="0">0</math> to <math latex="1">1</math>)
    </paragraph>
    <paragraph>
      <math latex="\afWV{md}_u = 1.0">MDu = 1.0</math>
    </paragraph>
    <paragraph>
      <math latex="\afWV{mr}_l = 0.0">MRl = 0.0</math> (the height is added to the <math latex="z">z</math>-value of <math latex="\afPt[M]">M</math>)
    </paragraph>
    <paragraph>
      <math latex="\afWV{mr}_u = \afWV{height}">MRu = height</math> (height is chosen in the model)
    </paragraph>


    <paragraph>
      In summary, the whole process comprises these three steps:
      <ol>
	<li>
	  Given a model domain value, find the equivalent domain value in the function. 
	</li>
	<li>
	  Apply the function to get a value in the function's range.
	</li>
	<li>
	  Find the equivalent model range value. 
	</li>
      </ol>
    </paragraph>
  </how>
  <samples>
    <sample id="Reciprocal">
      <name>Reciprocal</name>
      <when>
	<paragraph>
	  Feather a curve. Make a curve taper gently.
	</paragraph>
      </when>
      <how>
	<paragraph>
	  The multiplicative reciprocal is the function <math
	  latex="\afFunc{f}{x} = 1/x">f(x) = 1/x</math>. It is seductive as it
	  provides a simple function that tapers to a non-zero value
	  (is asymptotic to the <math latex="x">x</math>-axis), making
	  it possible to feather effects on a curve or surface. It has
	  a trap as it increases exponentially as its argument
	  approaches zero and is undefined at zero. Thus it is
	  important to set the function domain so that zero and values
	  close to it are not included in the function. In general,
	  using this function produces poor results. It is included
	  here to demonstrate that sometimes the function domain
	  choice is crucial.
	</paragraph>
	<paragraph>
	  Here are the parameter settings for a useful mapping. The model point <math latex="\afPt[M]">M</math> is parametric over the domain <math latex="0">0</math> to <math latex="1">1</math>.
	</paragraph>
	
	<paragraph>
	  <math latex="\afFunc{f}{x} = 1/x">f(x) = 1/x</math> 
	</paragraph>
	<paragraph>
	  <math latex="\afWV{fd}_l = 0.25">FDl = 0.25</math>
	</paragraph>
	<paragraph>
	  <math latex="\afWV{fd}_u = 100.0">FDu = 100.0</math>
	</paragraph>
	<paragraph>
	  <math latex="\afWV{fr}_l = 0.01">FRl = 0.01</math> (defined by the function and thus computed automatically)
	</paragraph>
	<paragraph>
	  <math latex="\afWV{fr}_u = 4.0">FRu = 4.0</math> (defined by the function and thus computed automatically)
	</paragraph>
	<paragraph>
	  <math latex="\afWV{md}_l = 0.0">MDl = 0.0</math> (<math latex="\afPt[M]">M</math> is  parameterized by <math latex="m">m</math> over the domain <math latex="0">0</math> to <math latex="1">1</math>)
	</paragraph>
	<paragraph>
	  <math latex="\afWV{md}_u = 1.0">MDu = 1.0</math>
	</paragraph>
	<paragraph>
	  <math latex="\afWV{mr}_l = 0.0">MRl = 0.0</math> (the height is added to the <math latex="z">z</math>-value of <math latex="\afPt[M]">M</math>)
	</paragraph>
	<paragraph>
	  <math latex="\afWV{mr}_u = \afWV{height}">MRu = height</math> (height is chosen in the model)
	</paragraph>
      </how>
      
      <a href="Samples/MappReverseX/MappReverseX.gct">Click to download MappReverseX.gct</a>
      <animation src="Samples/MappReverseX/AnimationReverseX.swf"/>
    </sample>
    <sample id="SineAndCosine">
      <name>Sine and Cosine</name>
      <when>
	<paragraph>
	  Use sine and cosine functions in complete periodic cycles.
	</paragraph>
      </when>
      <how>     
	<paragraph>
	  The basic trigonometric functions <math
	  latex="\afFunc{sin}{x}">sin(x)</math> and <math
	  latex="\afFunc{cos}{x}">cos(x)</math> provide repeating
	  periods of <math latex="360^\circ">360 degrees</math> and
	  periods of <math latex="180^\circ">180 degrees</math>
	  between function minima and maxima. This makes such
	  functions suitable for repetitive design elements. The
	  functions both have domains from <math
	  latex="-\infty">-&#8734;</math> to <math
	  latex="\infty">&#8734;</math> and ranges from <math
	  latex="-1">-1</math> to <math latex="1">1</math>. Choosing a
	  finite part of the domain such that the function starts and
	  ends at a minimum, maximum or zero-crossing yields clean
	  control over the end-conditions in the model.
	</paragraph>


    <paragraph>
         Here are sample parameter settings. The model point <math
         latex="\afPt[M]">M</math> is assumed to be parametric over
         the range <math latex="0">0</math> to <math
         latex="1">1</math>. In this case, <math
         latex="\afPt[M]">M</math> is bound to a circle, and vertical lines from each instance of <math
         latex="\afPt[M]">M</math> have length given by the function result.
    </paragraph>

	<paragraph>
	  <math latex="\afFunc{f}{x} = \afFunc{cos}{x}">f(x) = cos(x)</math> 
	</paragraph>
	<paragraph>
	  <math latex="\afWV{fd}_l = 0.0">FDl = 0.0</math>
	</paragraph>
	<paragraph>
	  <math latex="\afWV{fd}_u = 1080.0">FDu = 1080.0</math> (yields three complete cycles)
	</paragraph>
	<paragraph>
	  <math latex="\afWV{fr}_l = -1.0">FRl = -1.0</math> (defined by the function and thus computed automatically)
	</paragraph>
	<paragraph>
	  <math latex="\afWV{fr}_u = 1.0">FRu = 1.0</math> (defined by the function and thus computed automatically)
	</paragraph>
	<paragraph>
	  <math latex="\afWV{md}_l = 0.0">MDl = 0.0</math> (<math latex="\afPt[M]">M</math> is  parameterized by <math latex="m">m</math> over the domain <math latex="0">0</math> to <math latex="1">1</math>)
	</paragraph>
	<paragraph>
	  <math latex="\afWV{md}_u = 1.0">MDu = 1.0</math>
	</paragraph>
	<paragraph>
	  <math latex="\afWV{mr}_l = \afWV{heightMinimum}">MRl = heightMinimum</math> (the minimum length of the lines on  <math latex="\afPt[M]">M</math>)
	</paragraph>
	<paragraph>
	  <math latex="\afWV{mr}_u = \afWV{heightMaximum}">MRu = heightMaximum</math>  (the maximum length of the lines on  <math latex="\afPt[M]">M</math>)
	</paragraph>

	<paragraph>
	  When sampling periodic functions and those with minima or
	  maxima within the chosen domain, the choice of sampling
	  interval is crucial if the sampled points will be used to
	  regenerate the mapped function in the model. Samples must be
	  chosen to include the minima and maxima.  Not doing this can
	  dramatically affect the shape of the reconstructed curve.
	</paragraph>
      </how>

      <a href="Samples/MappCosine/MappCosine.gct">Click to download MappCosine.gct</a>
      <animation src="Samples/MappCosine/AnimationCosine.swf"/>
    </sample>
    <sample id="FunctionParts">
      <name>Function Parts</name>
      <when>
	<paragraph>
	  Choosing a small part of a function can yield an intended form.
	</paragraph>
      </when>
      <how>
	<paragraph>
	  Simple functions can yield surprisingly rich forms. A
	  classic example in three dimensions is Foster and Partner's
	  extensive use of parts of a torus a generator of form
	  <latex>(see Chapter \ref{sec:BradyPeters:brady})</latex>.
	</paragraph>
	<paragraph>
	  The function is the sine function: <math
	  latex="\afFunc{f}{x} = \afFunc{sin}{x}">f(x) =
	  sin(x)</math>. The trick is that an appropriate choice of
	  function domain can yield local segments of the sine curve
	  that do not display the archetypal repetition of the entire
	  curve.
	</paragraph>
    <paragraph>
         Here are sample parameter settings. The model point <math
         latex="\afPt[M]">M</math> is assumed to be parametric over
         the range <math latex="0">0</math> to <math
         latex="1">1</math>. In this case, the model range minimum and
         maximum would be chosen by the modeler to suit the
         application to hand. The figures on the side bar vary only by
         <math latex="FDu = 180.0">FDu = 180.0</math> the upper
         function domain bound.
      <latex>\index{function|)}</latex>
      <latex>\index{function!domain|)}</latex>
      <latex>\index{function!range|)}</latex>
      <latex>\index{transformation!mapping|)}</latex>
    </paragraph>
    <paragraph>
      <math latex="\afFunc{f}{x} = \afFunc{sin}{x}">f(x) = sin(x)</math> 
    </paragraph>
    <paragraph>
      <math latex="\afWV{fd}_l = 45.0^\circ">FDl = 45.0 degrees</math> (increases in steps of <math latex="22.5^\circ">22.5</math>
    </paragraph>
    <paragraph>
      <math latex="\afWV{fd}_u = 180.0^\circ">FDu = 180.0 degrees</math> 
    </paragraph>
    <paragraph>
      <math latex="\afWV{fr}_l = -1.0">FRl = 0.0</math> (defined by the function and therefore can be computed automatically)
    </paragraph>
    <paragraph>
      <math latex="\afWV{fr}_u = 1.0">FRu = 1.0</math> (defined by the function and therefore can be computed automatically)
    </paragraph>
    <paragraph>
      <math latex="\afWV{md}_l = 0.0">MDl = 0.0</math> (<math latex="\afPt[M]">M</math> is  parameterized by <math latex="m">m</math> over the domain <math latex="0">0</math> to <math latex="1">1</math>)
    </paragraph>
    <paragraph>
      <math latex="\afWV{md}_u = 1.0">MDu = 1.0</math>
    </paragraph>
    <paragraph>
      <math latex="\afWV{mr}_l = \afWV{heightMinimum}">MRu = heightMinimum</math> (minimum height is chosen in the model)
    </paragraph>
    <paragraph>
      <math latex="\afWV{mr}_u = \afWV{heightMaximum}">MRu = heightMaximum</math> (maximum height is chosen in the model)
    </paragraph>
      </how>
      <a href="Samples/MappSinePart/MappSinePart.gct">Click to download MappSinePart.gct</a>
      <animation src="Samples/MappSinePart/AnimationSinePart.swf"/>
    </sample>
    <web>
    <sample id="InteractiveMappingControl">
      <name>Interactive mapping control</name>
      <when>
	<paragraph>
	  Use a <patternLink>Controller</patternLink> to consistently
	  express the six mapping parameters.
	</paragraph>
      </when>
      <how>
	<paragraph>
	  Complete here an example of mapping function and
	  frames. Explain the generic mapping function and the mapping
	  control fames. Debug these.
	</paragraph>
      </how>
    </sample>
    </web>
    <web>
    <sample id="SineRoof">
      <name>SineRoof</name>
      <when>
	<paragraph>
	  Create a roof surface controlled by two sine curve mappings.
	</paragraph>
      </when>
      <how>
	<paragraph>
	  You have a site in which has certain boundaries and
	  height. You want to create a sine-like roof that fits into
	  this site. Create a sine curve function. In order to create
	  this roof too need to have
	  <patternLink>Jig</patternLink> as
	  loft curves for the roof. In this sample, you have two
	  curves to create the roof, one at the start and another one
	  at the end point of the site. These curves can be created as
	  two worlds from one function( you have different dimension
	  for start and end of the site) first step is to divide
	  worlds' domain (world one and two) to the number of samples
	  that you want. Find their equivalents in the function's
	  domain(see SinePart sample from
	  <patternName>Mapping</patternName>) To have this world's
	  range you can create new coordinate systems for start and
	  end point of the site and assign this values to these
	  coordinate systems. ( Create new coordinate system that
	  represents the site boundaries in a way that you want) Apply
	  Sine function to find function range points(FRV's). Find
	  parametric equivalents for function ranges in each world's
	  range.  Create a surface from these two sine-like curves.
	</paragraph>
      </how>
      <a href="Samples/MappSineRoof/MappSineRoof.gct">Click to download MappSineRoof.gct</a>
      <animation src="Samples/MappSineRoof/AnimationSineRoof.swf"/>
    </sample>
    </web>
  </samples>
</pattern>

