Algorithmic Solutions > LEDA > LEDA Guide > Geometry > Orientation and Sidedness > Example

Example Orientation and Sidedness

The following simple example shows how the functions and predicates for orientation and sidedness can be used.

#include <LEDA/geo/rat_point.h>
#include <LEDA/geo/rat_circle.h>
#include <LEDA/geo/rat_line.h>

using namespace leda;

int main()
{ 
  rat_point p(1,1), q(2,3), r(3,3);

  if (orientation(p,q,r)>0) 
    std::cout << "positive orientation" << std::endl;
  else if (orientation(p,q,r)<0) 
    std::cout << "negative orientation" << std::endl; 
  else  std::cout << "zero orientation" << std::endl;

  p=point(7,3);
  q=point(11,13);
  r=point(17,19);

  if (left_turn(p,q,r)) std::cout << "left turn" << std::endl;
  if (right_turn(p,q,r)) std::cout << "right turn" << std::endl;
  if (collinear(p,q,r)) std::cout << "collinear" << std::endl;


  rat_line l(p,q);
  if (l.side_of(r)>0) 
    std::cout << "r lies in positive part of l" << std::endl;
  else if (l.side_of(r)<0)
    std::cout << "r lies in positive part of l" << std::endl;

  if (l.side_of(p)==0) std::cout << "p lies on l" << std::endl;


  return 0;
}	

See also:

Data Types for 2D Geometry

Data Types for 3-D Geometry


Geometry

Advanced Data types for 2-D geometry

Geometry Algorithms

GeoWin

 



Please send any suggestions, comments or questions to leda@algorithmic-solutions.com
© Copyright 2001-2003, Algorithmic Solutions Software GmbH