home *** CD-ROM | disk | FTP | other *** search
- \bigskip
- \bigskip
- {\magonebf 6.1.3 Straight Lines (line)}
-
- An instance $l$ of the data type $line$ is a directed straight line
- in the two-dimensional plane. The angle between a right oriented horizontal
- line and $l$ is called the direction of $l$.
-
- \def\name{$line$}
- \def\type{$line$}
-
- {\bf 1. Creation of a line }
-
- a) \create l (point\ p,\ point\ q)
-
- b) \create l (segment\ s)
-
- c) \create l (point\ p,\ real\ \alpha)
-
- d) \create l {}
-
-
-
- introduces a variable \var\ of type \name. \var\ is initialized to the line
- passing through points $p$ and $q$ directed form $p$ to $q$ (variant a), to
- the line supporting segment $s$ (variant b), to the line passing through point
- $p$ with direction $\alpha$ (variant c), or a line through $(0,0)$ with
- direction 0 (variant d).
-
- \bigskip
- {\bf 2. Operations on a line \var}
-
- \medskip
- \+\cleartabs & \hskip 2.5truecm & \hskip 5truecm &\cr
- \+\op real direction {}
- {returns the direction of \var.}
- \smallskip
- \+\op real angle {line\ g}
- {returns the angle between \var\ and $g$, i.e.,}
- \+\nop {$g$.direction() - \var.direction().}
- \smallskip
- \+\op real angle {}
- {returns \var.direction().}
- \smallskip
- \+\op bool horizontal {}
- {returns true iff \var\ is horizontal.}
- \smallskip
- \+\op bool vertical {}
- {returns true iff \var\ is vertical.}
- \smallskip
- \+\op real slope {}
- {returns the slope of \var.}
- \+\nop {\precond \var\ is not vertical.}
- \smallskip
- \+\op real y\_proj {real\ x}
- {returns $p$.ycoord(), where $p \in l$ with $p$.xcoord()}
- \+\nop {= $x$. \precond \var\ is not vertical.}
- \smallskip
- \+\op real x\_proj {real\ y}
- {returns $p$.xcoord(), where $p \in l$ with $p$.ycoord()}
- \+\nop {= $y$. \precond \var\ is not horizontal.}
- \smallskip
- \+\op real y\_abs {}
- {returns the y-abscissa of \var\ (\var.y\_proj(0)).}
- \+\nop {\precond \var\ is not vertical.}
- \smallskip
- \+\op bool intersection {line\ g,\ point\&\ p} {}
- \+\nop {if $l$ and $g$ are not collinear and intersect the}
- \+\nop {intersection point is assigned to $p$ and true is}
- \+\nop {returned, otherwise false is returned.}
- \smallskip
- \+\op bool intersection {segment\ s,\ point\&\ p} {}
- \+\nop {if $l$ and $s$ are not collinear and intersect the}
- \+\nop {intersection point is assigned to $p$ and true is}
- \+\nop {returned, otherwise false is returned.}
- \smallskip
- \+\op line translate {vector\ v} {}
- \+\nop {returns $l+v$, i.e., the line created by}
- \+\nop {translating $l$ by vector $v$. \precond $v$}
- \+\nop {has dimension 2.}
- \smallskip
- \+\op line translate {real\ alpha,\ real\ d} {}
- \+\nop {returns the line created by a translation of }
- \+\nop {\var\ in direction $\alpha$ by distance $d$.}
- \smallskip
- \+\op line rotate {point\ q,\ real\ \alpha}
- {returns the line created by a rotation of $l$}
- \+\nop {about point $q$ by angle $\alpha$.}
- \smallskip
- \+\op segment perpendicular {point\ p}
- {returns the nromal of $p$ with respect to \var.}
-
- {\bf 3. Operators }
- \medskip
- \+&$line\&$ &$line$ =\ \ $line$ &assignment\cr
- \smallskip
- \+&$bool$ &$line$ == $line$ &test for equality\cr
- \smallskip
- \+&$bool$ &$line$\ !=\ $line$ &test for inequality\cr
-
- \vfill\eject
-
-