home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / lout2.lzh / LOUT2 / DOC / TR.FIG / s5 < prev    next >
Text File  |  1994-01-25  |  9KB  |  297 lines

  1. @Section
  2.    @Title { Lengths, angles, and points }
  3. @Begin
  4. @PP
  5. We already know that two lengths placed side by side define a point.  This is 
  6. only the simplest of a number of such geometrical combinations.
  7. @PP
  8. The symbol @Code "@Distance" returns the length of the line joining two
  9. points:
  10. @ID @Code "{0 0} @Distance {3 cm  4 cm}"
  11. is equivalent to the length {@Code "5 cm"}.  The result of @Code "@Distance"
  12. is never negative.  Notice that braces must enclose the two points.  The
  13. symbol @Code "@XDistance" returns the distance in the @Eq { x } direction
  14. from one point to another:
  15. @ID {
  16. @Code "{" & @Eq { x sub 1 ``` y sub 1 } & @Code "}  @XDistance  {"
  17. & @Eq { x sub 2 ``` y sub 2 } & @Code "}"
  18. }
  19. has for its result the length @Eq { x sub 2 - x sub 1 }, and so may be
  20. negative.  There is an analogous @Code "@YDistance" symbol.
  21. @PP
  22. The symbol @Code "@Angle" returns the angle @Eq {theta} from one point to
  23. another:
  24. @ID {
  25. @Code "{" & @Eq { x sub 1 ``` y sub 1 } & @Code "}  @Angle  {"
  26. & @Eq { x sub 2 ``` y sub 2 } & @Code "}"
  27. ||7ct
  28. @Fig {
  29. @Figure
  30.    arrow { forward }
  31.    shape { 4 cm 0 0 0 4 cm 3 cm }
  32. { 4c @Wide 3c @High }
  33. // {4 cm 3 cm} ** 0.4 ++ { 0.5 cm 0 } @MarkOf @Eq { (x sub 1 & , y sub 1 & ) }
  34. // {4 cm 3 cm} ** 0.4 @BaseOf @Circle margin { 0.05c } paint { black } {}
  35. // {4 cm 3 cm} ** 0.8 ++ { 0.5 cm 0 } @MarkOf @Eq { (x sub 2 & , y sub 2 & ) }
  36. // {4 cm 3 cm} ** 0.8 @BaseOf @Circle margin { 0.05c } paint { black } {}
  37. // { 1 cm 0.2 cm } ** 0.7 @BaseOf @Eq { theta }
  38. }
  39. }
  40. The result will be 0 if the two points are equal.  The symbol @Code "<<"
  41. returns the point at a given distance and angle from @Eq { (0, 0) }:
  42. @ID {
  43. @Code "{" & @Eq { length }  @Code "<<"  @Eq { theta } & @Code "}"
  44. ||7ct
  45. @Fig {
  46. @Figure
  47.    arrow { forward }
  48.    shape { 4 cm 0 0 0 4 cm 3 cm }
  49. { 4c @Wide 3c @High }
  50. // {4 cm 3 cm} ** 0.5 -- {1.5 cm 0} @BaseOf @I length
  51. // {4 cm 3 cm} ** 0.8 @BaseOf @Circle margin { 0.05c } paint { black } {}
  52. // { 1 cm 0.2 cm } ** 0.7 @BaseOf @Eq { theta }
  53. }
  54. }
  55. For example, @Code "{ 5 cm << 45 dg }" is the point 5 cm
  56. from @Eq { (0, 0) } at 45 degrees.
  57. @PP
  58. Points may be added, subtracted, and multiplied by a number:
  59. @ID @Tab
  60.      vmargin { 0.5vx }
  61.      @Fmta { @Col A ! @Col is ! @Col B }
  62. {
  63. @Rowa
  64.    A { @Code "{" & @Eq {x sub 1 ``` y sub 1} & @Code "}  ++  {" &
  65. @Eq {x sub 2 ``` y sub 2} & @Code "}" }
  66.    B { @Eq { (x sub 1 + x sub 2 & , y sub 1 + y sub 2 & ) } }
  67. @Rowa
  68.    A { @Code "{" & @Eq {x sub 1 ``` y sub 1} & @Code "}  --  {" &
  69. @Eq {x sub 2 ``` y sub 2} & @Code "}" }
  70.    B { @Eq { (x sub 1 - x sub 2 & , y sub 1 - y sub 2 & ) } }
  71. @Rowa
  72.    A { @Code "{" & @Eq {x sub 1 ``` y sub 1} & @Code "}  **  " & @Eq {k} }
  73.    B { @Eq { (x sub 1 & k, y sub 1 & k) } }
  74. }
  75. For example,
  76. @ID {
  77. @Code "{" & @Eq {x sub 1 ``` y sub 1} & @Code "} ** 0.2  ++  " &
  78. @Code "{" & @Eq {x sub 2 ``` y sub 2} & @Code "} ** 0.8"
  79. }
  80. is the point eight tenths of the way from 
  81. @Eq { (x sub 1 & , y sub 1 & ) } to
  82. @Eq { (x sub 2 & , y sub 2 & ) } on the line joining them:
  83. @LP
  84. @ID @Fig {
  85. @Figure
  86.    shape {
  87.       {xsize 0} ** 0.3 ++ {0 ysize} @Label P1
  88.       {xsize 0} ++ {0 ysize} ** 0.4 @Label P2
  89.       P1 ** 0.2 @Label FP1
  90.       P2 ** 0.8 @Label FP2
  91.       0 0 P1 P2 0 0 [] FP1 FP1 ++ FP2 FP2
  92.    }
  93. { 6c @High 9c @Wide }
  94. // P1 ++ {0.3 cm 0} @BaseOf @Eq { (x sub 1 & , y sub 1 & ) }
  95. // P2 ++ {0.3 cm 0} @BaseOf @Eq { (x sub 2 & , y sub 2 & ) }
  96. // FP1 ++ FP2 ++ {0.3 cm 0} @BaseOf
  97. @Eq { (0.2x sub 1 & + 0.8x sub 2 & , 0.2y sub 1 & + 0.8y sub 2 & ) }
  98. }
  99. When using {@Code "**"}, the point must be on the left and the number on
  100. the right.  It would be more convenient to name these symbols
  101. {@Code "+"}, {@Code "-"}, and {@Code "*"}, but these names
  102. are often taken by equation formatters, and @Code "-" appears in
  103. lengths, so we don't.  There are @Code "@Max" and @Code "@Min" symbols:
  104. @ID @Tab
  105.      vmargin { 0.5vx }
  106.      @Fmta { @Col A ! @Col is ! @Col B }
  107. {
  108. @Rowa
  109.   A { @Code "{" & @Eq {x sub 1 ``` y sub 1} & @Code "}  @Max  {" &
  110. @Eq {x sub 2 ``` y sub 2} & @Code "}" }
  111.   B { @Eq { (max(x sub 1 & , x sub 2 & ), max(y sub 1 & , y sub 2 & )) } }
  112. @Rowa
  113.   A { @Code "{" & @Eq {x sub 1 ``` y sub 1} & @Code "}  @Min  {" &
  114. @Eq {x sub 2 ``` y sub 2} & @Code "}" }
  115.   B { @Eq { (min(x sub 1 & , x sub 2 & ), min(y sub 1 & , y sub 2 & )) } }
  116. }
  117. Note carefully that these apply to points, not to numbers.
  118. @PP
  119. The result of adding two points together depends on where the origin is
  120. at the time, as well as on the points themselves.  This can lead to
  121. unexpected results, as the author has found to his cost more than
  122. once.  Within the @Code shape option of {@Code "@Figure"}, the origin is
  123. the lower left corner of the result of the {@Code "@Figure"}.  In cases
  124. like the example on page {@PageOf sumpoints}, where points are added
  125. outside of any {@Code "@Figure"} symbol, the origin is usually at the
  126. bottom left corner of the figure as a whole.  A label always denotes a
  127. particular point on the printed page, regardless of where the origin
  128. happens to be.
  129. @PP
  130. The symbol @Code "@Prev" within the @Code "shape" option of @Code
  131. "@Figure" denotes the previous point of the shape, ignoring points within
  132. {@Code {"[" &0.5s "]"}}.  This makes it easy to specify each point
  133. relative to the previous one:
  134. @ID {
  135. @Code {
  136. "   shape {"
  137. "      0 0"
  138. "      { 2 cm << 30 }"
  139. "      @Prev ++ { 2 cm << 90 }"
  140. "      @Prev ++ { 2 cm << 150 }"
  141. "      @Prev ++ { 2 cm << 210 }"
  142. "      @Prev ++ { 2 cm << 270 }"
  143. "      0 0"
  144. "   }"
  145. }
  146. ||7ct
  147. @Fig { ||2.5c
  148. @Figure
  149.    shape {
  150.       0 0
  151.       { 2 cm << 30 }
  152.       @Prev ++ { 2 cm << 90 }
  153.       @Prev ++ { 2 cm << 150 }
  154.       @Prev ++ { 2 cm << 210 }
  155.       @Prev ++ { 2 cm << 270 }
  156.       0 0
  157.    }
  158. { 4c @Wide 4c @High }
  159. }
  160. }
  161. @PP
  162. Fig provides a @Code "@Label" symbol for attaching a label to a point in
  163. a shape, like this:
  164. @ID @Code "{xsize ysize} ** 0.5 @Label CTR"
  165. The point may then be referred to more concisely by its label,
  166. {@Code CTR}.  For example, the large arrow appearing in Section 2 was
  167. built like this:
  168. @ID {
  169. @Code {
  170. "@Figure"
  171. "   shape {"
  172. "      {0 ysize} ** 0.4 @Label SB"
  173. "      {0 ysize} ** 0.6 @Label ST"
  174. "      {xsize 0} ** 0.7 @Label HB"
  175. "      SB"
  176. "      SB ++ HB"
  177. "      HB"
  178. "      {xsize 0} ++ {0 ysize} ** 0.5"
  179. "      HB ++ {0 ysize}"
  180. "      HB ++ ST"
  181. "      ST"
  182. "      SB"
  183. "   }"
  184. "   paint { grey }"
  185. "{ 6c @Wide 2c @High }"
  186. }
  187. ||7ct
  188. @Fig {
  189. @Figure
  190.    shape {
  191.       {0 ysize} ** 0.4 @Label SB
  192.       {0 ysize} ** 0.6 @Label ST
  193.       {xsize 0} ** 0.7 @Label HB
  194.       SB
  195.       SB ++ HB
  196.       HB
  197.       {xsize 0} ++ {0 ysize} ** 0.5
  198.       HB ++ {0 ysize}
  199.       HB ++ ST
  200.       ST
  201.       SB
  202.    }
  203.    paint { grey }
  204. { 6c @Wide 2c @High }
  205. // @ShowLabels
  206. }
  207. }
  208. Incidentally, the labels of a figure can be displayed as above by putting
  209. the symbol @Code "@ShowLabels" at the end of the figure.  Labels can
  210. save a lot of effort.  They should contain only digits, upper-case
  211. letters and {@Code "@"}, because Fig and Lout use labels of their own
  212. made from lower-case letters.
  213. @PP
  214. The standard shapes have standard labels; for example, the labels
  215. of @Code "@Ellipse" are
  216. @LP
  217. @ID {
  218. @Code {
  219. "@Ellipse"
  220. "{ 3c @Wide 2c @High }"
  221. }
  222. ||7ct
  223. @Fig {
  224. @Ellipse { 3c @Wide 2c @High }
  225. // @ShowLabels
  226. }
  227. }
  228. There is a symbol, {@Code "::"}, for @I relabelling an object.
  229. Each label in the right parameter is relabelled in the following way:
  230. @LP
  231. @ID {
  232. @Code {
  233. "E1:: @Ellipse"
  234. "{ 3c @Wide 2c @High }"
  235. }
  236. ||7ct
  237. @Fig {
  238. E1:: @Ellipse { 3c @Wide 2c @High }
  239. // @ShowLabels
  240. }
  241. }
  242. Within the right parameter of @Code "::" the original names hold sway;
  243. but afterwards the names are changed by prefixing the label
  244. and @Code "@" to them.  These composite labels may be used exactly like
  245. other labels.  Relabelling can be nested to arbitrary depth:
  246. @LP
  247. @ID {
  248. 5c @Wide @Code {
  249. "A::"
  250. "{   1:: @Ellipse"
  251. "    { 3c @Wide 2c @High }"
  252. "    //1c"
  253. "    2:: @Box"
  254. "    { 3c @Wide 2c @High }"
  255. "}"
  256. }
  257. ||7ct
  258. @Fig {
  259. A::
  260. {   1:: @Ellipse { 3c @Wide 2c @High }
  261.     //1c
  262.     2:: @Box { 3c @Wide 2c @High }
  263. }
  264. // @ShowLabels
  265. }
  266. }
  267. The right parameter of @Code "::" may be any object.
  268. @PP
  269. The six standard shapes ({@Code "@Box"}, {@Code "@Square"},
  270. {@Code "@Diamond"}, {@Code "@Polygon"}, {@Code "@Ellipse"}, and
  271. {@Code "@Circle"}) have a special @Code CIRCUM label, not displayed by
  272. {@Code "@ShowLabels"}.  The expression
  273. @ID {
  274. @Eq { "angle" } @Code CIRCUM
  275. }
  276. yields the point on the boundary of the shape at the given angle from
  277. the centre, in a coord&-inate system with the centre for origin.  Thus,
  278. given a labelled standard shape such as
  279. @ID @Code "A :: @Ellipse ..."
  280. the point on its boundary at an angle of 45 degrees from the centre is
  281. @ID @Code "A@CTR ++ {45 A@CIRCUM}"
  282. The braces must be present.  Regrettably, there is no way to produce a
  283. @Code CIRCUM label for shapes defined by the user in any reasonable time.
  284. @PP
  285. If the same label is used twice, as is inevitable with unlabelled standard
  286. shapes, only the most recent value is remembered.  There is a limit on the
  287. maximum number of distinct labels in any one figure, which
  288. can be changed by means of an option to the @Code "@Fig" symbol:
  289. @ID @Code {
  290. "@Fig"
  291. "   maxlabels { 500 }"
  292. "{ ... }"
  293. }
  294. The default value is 200.  Large values could cause the printing device
  295. to run out of memory.  Memory is reclaimed at the end of each figure.
  296. @End @Section
  297.