home *** CD-ROM | disk | FTP | other *** search
- \bigskip
- \bigskip
- {\magonebf 6.1.1 Points (point)}
-
- An instance of the data type $point$ is a point in the two-dimensional
- plane $\real^2$. We use $(a,b)$ to denote a point with first (or x-)
- coordinate $a$ and second (or y-) coordinate $b$.
-
- \def\name{$point$}
- \def\type{$point$}
-
- {\bf 1. Creation of a point }
-
- a) \create p (real\ x,\ real\ y)
-
- b) \create p {}
-
-
- introduces a variable \var\ of type \name\ initialized to the point
- $(x,y)$. Variant b) initializes \var\ to the point $(0,0)$.
-
-
- \bigskip
- {\bf 2. Operations on a point p}
-
- \medskip
- \+\cleartabs & \hskip 2.5truecm & \hskip 5truecm &\cr
- \+\op real xcoord {}
- {returns the first coordinate of point $p$}
- \smallskip
- \+\op real ycoord {}
- {returns the second coordinate of point $p$}
- \smallskip
- \+\op real distance {point\ q}
- {returns the euclidean distance between $p$}
- \+\nop { and $q$.}
- \smallskip
- \+\op real distance {}
- {returns the euclidean distance between $p$}
- \+\nop { and $(0,0)$.}
- \smallskip
- \+\op point translate {vector\ v}
- {returns $p+v$, i.e., $p$ translated by vector}
- \+\nop {$v$. \precond $v$.dim() = 2.}
-
- \vfill\eject
-
- \+\op point translate {real\ \alpha,\ real\ d} {}
- \+\nop {returns the point created by translating}
- \+\nop {$p$ in direction $\alpha$ by distance $d$. The}
- \+\nop {direction is given by its angle with a}
- \+\nop {right oriented horizontal ray.}
- \smallskip
- \+\op point rotate {point\ q,\ real\ \alpha}
- {returns the point created by a rotation of $p$}
- \+\nop {about point $q$ by angle $\alpha$.}
-
- \bigskip
- {\bf 3. Operators }
- \medskip
- \+&$point\&$ &$point$ =\ $point$ &assignment\cr
- \smallskip
- \+&$bool$ &$point$ == $point$ &test for equality\cr
- \smallskip
- \+&$bool$ &$point$ != $point$ &test for inequality\cr
- \smallskip
- \+&$point$ &$point$ +\ $vector$ &translation by vector\cr
-
- \medskip
- Input and output operators:
- \medskip
- \+&$ostream\&$ &$ostream << point$ &writes a point to an output stream\cr
- \smallskip
- \+&$istream\&$ &$istream >> point$ &reads the coordinates of a point (two reals)\cr
- \+& & &from an input stream\cr
-
-