Example Orientation and SidednessThe 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:Advanced Data types for 2-D geometry |