home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / leda / man / segment.tex < prev    next >
Encoding:
Text File  |  1991-11-15  |  4.2 KB  |  122 lines

  1. \bigskip
  2. \bigskip
  3. {\magonebf 6.1.2 Segments (segment)}
  4.  
  5. An instance $s$ of the data type $segment$ is a directed straight line 
  6. segment in the two-dimensional plane, i.e., a straight line segment $[p,q]$ 
  7. connecting two points $p,q \in \real^2$. $p$ is called the start point
  8. and $q$ is called the end point of $s$. The length of $s$ is the euclidean 
  9. distance between $p$ and $q$. The angle between a right oriented horizontal 
  10. ray and $s$ is called the direction of $s$. The segment $[(0,0),(0,0)]$ 
  11. is said to be empty.
  12.  
  13. \def\name{$segment$}
  14. \def\type{$segment$}
  15.  
  16. {\bf 1. Creation of a segment }
  17.  
  18. a) \create s (point\ p,\ point\ q)
  19.  
  20. b) \create s (point\ p,\ real\ \alpha,\ real\ d)
  21.  
  22. c) \create s {}
  23.  
  24.  
  25. introduces a variable \var\ of type \name. \var\ is initialized to the segment 
  26. from $p$ to $q$ (variant a), to the segment with start point $p$, direction 
  27. $\alpha$, and length $d$ (variant b) or to the empty segment (variant c).
  28.  
  29. \vfill\eject
  30.  
  31. \bigskip
  32. {\bf 2. Operations on a segment \var}
  33.  
  34. \medskip
  35. \+\cleartabs & \hskip 2.5truecm & \hskip 5truecm &\cr
  36. \+\op point   start {}
  37.                            {returns the start point of segment \var.}
  38. \smallskip
  39. \+\op point   end {}
  40.                            {returns the end point of segment \var.}
  41. \smallskip
  42. \+\op real    xcoord1 {}
  43.                            {returns the x-coordinate of \var.start().}
  44. \smallskip
  45. \+\op real    ycoord1 {}
  46.                            {returns the y-coordinate of \var.start().}
  47. \smallskip
  48. \+\op real    xcoord2 {}
  49.                            {returns the x-coordinate of \var.end().}
  50. \smallskip
  51. \+\op real    ycoord2 {}
  52.                            {returns the y-coordinate of \var.end().}
  53. \smallskip
  54. \+\op real    length {}
  55.                            {returns the length of \var.}
  56. \smallskip
  57. \+\op real   direction {} 
  58.                         {returns the direction of \var\ as an angle in}
  59. \+\nop                  {the intervall $(-\pi,\pi]$.}
  60. \smallskip
  61. \+\op real   angle {segment\ t} 
  62.                         {returns the angle between \var\ and $t$, i.e.,}
  63. \+\nop                  {$t$.direction() - \var.direction().}
  64. \smallskip
  65. \+\op real   angle {} 
  66.                         {returns \var.direction().}
  67. \smallskip
  68. \+\op bool   horizontal {} 
  69.                         {returns true iff \var\ is horizontal.}
  70. \smallskip
  71. \+\op bool   vertical {} 
  72.                         {returns true iff \var\ is vertical.}
  73. \smallskip
  74. \+\op real   slope {}
  75.                         {returns the slope of $s$.}
  76. \+\nop                  { \precond  \var\  is not vertical.}
  77. \smallskip
  78. \+\op bool    intersection {segment\ t,\ point\&\ p} {}
  79. \+\nop                     {if $s$ and $t$ are not collinear and intersect the}
  80. \+\nop                     {intersection point is assigned to $p$ and true is}
  81. \+\nop                     {returned, otherwise false is returned.}
  82. \smallskip
  83. \+\op segment rotate {point\ q,\ real\ \alpha}
  84.                         {returns the segment created by a rotation of $s$}
  85. \+\nop                  {about point $q$ by angle $\alpha$.}
  86. \smallskip
  87. \+\op segment rotate {real\ \alpha}
  88.                         {returns $s$.rotate($s$.start(),$\alpha$).}
  89. \smallskip
  90. \+\op segment translate {vector\ v} {}
  91. \+\nop                     {returns $s+v$, i.e., the segment created by}
  92. \+\nop                     {translating $s$ by vector $v$. \precond $v$}
  93. \+\nop                     {has dimension 2.}
  94. \smallskip
  95. \+\op segment translate {real\ alpha,\ real\ d} {}
  96. \+\nop                  {returns the segment created by a translation of }
  97. \+\nop                  {$s$ in direction $\alpha$ by distance $d$.}
  98. \smallskip
  99.  
  100. \bigskip
  101. {\bf 3. Operators }
  102. \medskip
  103. \+&$segment\&$  &$segment$ =\ \  $segment$  &assignment\cr
  104. \smallskip
  105. \+&$bool$       &$segment$ ==    $segment$  &test for equality\cr
  106. \smallskip
  107. \+&$bool$       &$segment$\ !=   $segment$  &test for inequality\cr
  108. \smallskip
  109. \+&$segment$    &$segment$ +\ \  $vector$  &translation by vector\cr
  110.  
  111. \medskip
  112. \smallskip
  113.  
  114. \medskip
  115. Input and output operators:
  116. \medskip
  117. \+&$ostream\&$ &$ostream << segment$ &writes a segment to an output stream.\cr
  118. \smallskip
  119. \+&$istream\&$ &$istream >> segment$ &reads the coordinates of a segment (four reals)\cr
  120. \+&            &                     &from an input stream.\cr
  121.  
  122.