\manpage {segment} {} {Segments}
 
\definition
    An instance $s$ of the data type $segment$ is a directed straight line
    segment in the two-dimensional plane, i.e., a straight line segment $[p,q]$
    connecting two points $p,q \in \real^2$. $p$ is called the start point
    and $q$ is called the end point of $s$. The length of $s$ is the Euclidean
    distance between $p$ and $q$. The angle between a right oriented horizontal
    ray and $s$ is called the direction of $s$. The segment $[(0,0),(0,0)]$
    is said to be empty.
 
\creation s 
 
\create {(point\ p,\ point\ q)}
   { introduces a variable \var\ of type \name. \var\ is initialized
            to the segment $(p,q)$  }
 
 
\create {(double\ x1,\ double\ y1,\ double\ x2,\ double\ y2)}
   { introduces a variable \var\ of type \name. \var\ is initialized
            to the segment from $((x_1,y_1),(x_2,y_2))$. } 
 
 
\create {(point\ p,\ double\ dir,\ double\ length)}
   { introduces a variable \var\ of type \name. \var\ is initialized
            to the segment with start point $p$, direction $dir$, and
            length $length$. }
 
 
\create { }
   { introduces a variable \var\ of type \name. \var\ is initialized
            to the empty segment. }
 
 
\operations 2 3.5
 
\op  point start {()}
           {  returns the start point of segment \var. }
 
 
\op  point end {()}
           {  returns the end point of segment \var. }
 
 
\op  double xcoord1 {()}
           {  returns the x-coordinate of \var.start(). }
 
 
\op  double xcoord2 {()}
           {  returns the x-coordinate of \var.end(). }
 
 
\op  double ycoord1 {()}
           {  returns the y-coordinate of \var.start(). }
 
 
\op  double ycoord2 {()}
           {  returns the y-coordinate of \var.end(). }
 
 
\op  double length {()}
           {  returns the length of \var. }
 
 
\op  double direction {()}
           {  returns the direction of \var\ as an angle in
	      the intervall $(-\pi,\pi]$. }
 
 
\op  double angle {()}
           {  returns \var.direction(). }
 
 
\op  double angle {( segment)}
           {  returns the angle between \var\ and $t$, i.e.,
              $t$.direction() - \var.direction(). }
 
 
\op  bool vertical {()}
           {  returns true iff \var\ is vertical. }
 
 
\op  bool horizontal {()}
           {  returns true iff \var\ is horizontal. }
 
 
\op  double slope {()}
           {  returns the slope of $s$.\\
	      \precond  \var\  is not vertical. }
 
 
\opl bool intersection {( segment\ t, \ point\&\ p)}
           {  if \var\ and $t$ are not collinear and intersect the
	    intersection point is assigned to $p$ and true is 
	    returned, otherwise false is returned. }
 
 
\opl segment translate {(double\ a, double\ d)}
           {  returns the segment created by a translation of
	    $s$ in direction $a$ by distance $d$. }
 
 
\op  segment translate {( vector\ v)}
           {  returns $s+v$, i.e., the segment created by
	    translating $s$ by vector $v$.\\
	    \precond $v$.dim() = 2. } 
 
 
\opl segment rotate {( point\ q, double\ a)}
           {  returns the segment created by a rotation of $s$
	    about point $q$ by angle $a$. }
 
 
\op  segment rotate {(double\ a)}
           {  returns $s$.rotate($s$.start(),$a$). }
 
 
\binop int == {s}
         {  Test for equality. }
 
 
\binop int != {s}
         {  Test for inequality. }
 
 
\binop segment + { vector\ v}
         {  Translation by vector $v$. }
 
 
\binopfunc  ostream\&   {ostream\&\ O\ <<s}
           {  writes \var\ to output stream $O$. }
 
 
\binopfunc  istream\&   {istream\&\ I\ >>\&\ s}
           {  reads the coordinates of \var\ (four $double$ numbers)
	           from input stream $I$. }
 
 
