src/lemon/bezier.h
changeset 1110 ba28dfbea5f2
parent 1073 bedab8bd915f
child 1164 80bb73097736
equal deleted inserted replaced
0:bca77cb4a557 1:cb9ccc3ec39c
    19 
    19 
    20 ///\ingroup misc
    20 ///\ingroup misc
    21 ///\file
    21 ///\file
    22 ///\brief Classes to compute with Bezier curves.
    22 ///\brief Classes to compute with Bezier curves.
    23 ///
    23 ///
    24 ///Up to now this file is internally used by \ref graph_to_eps.h
    24 ///Up to now this file is used internally by \ref graph_to_eps.h
    25 ///
    25 ///
    26 ///\author Alpar Juttner
    26 ///\author Alpar Juttner
    27 
    27 
    28 #include<lemon/xy.h>
    28 #include<lemon/xy.h>
    29 
    29 
    56   
    56   
    57   Bezier1 after(double t) const
    57   Bezier1 after(double t) const
    58   {
    58   {
    59     return Bezier1(conv(p1,p2,t),p2);
    59     return Bezier1(conv(p1,p2,t),p2);
    60   }
    60   }
    61   Bezier1 operator()(double a,double b) { return before(b).after(a/b); }  
    61   Bezier1 revert() { return Bezier1(p2,p1);}
       
    62   Bezier1 operator()(double a,double b) { return before(b).after(a/b); }
       
    63   xy grad() { return p2-p1; }
       
    64   xy grad(double t) { return grad(); }
       
    65 
    62 };
    66 };
    63 
    67 
    64 class Bezier2 : public BezierBase
    68 class Bezier2 : public BezierBase
    65 {
    69 {
    66 public:
    70 public:
    85   {
    89   {
    86     xy q(conv(p1,p2,t));
    90     xy q(conv(p1,p2,t));
    87     xy r(conv(p2,p3,t));
    91     xy r(conv(p2,p3,t));
    88     return Bezier2(conv(q,r,t),r,p3);
    92     return Bezier2(conv(q,r,t),r,p3);
    89   }
    93   }
       
    94   Bezier2 revert() { return Bezier2(p3,p2,p1);}
    90   Bezier2 operator()(double a,double b) { return before(b).after(a/b); }
    95   Bezier2 operator()(double a,double b) { return before(b).after(a/b); }
    91   
    96   Bezier1 grad() { return Bezier1(2.0*(p2-p1),2.0*(p3-p2)); }
       
    97   xy grad(double t) { return grad()(t); }  
    92 };
    98 };
    93 
    99 
    94 class Bezier3 : public BezierBase
   100 class Bezier3 : public BezierBase
    95 {
   101 {
    96 public:
   102 public:
   128       xy a(conv(p,q,t));
   134       xy a(conv(p,q,t));
   129       xy b(conv(q,r,t));
   135       xy b(conv(q,r,t));
   130       xy c(conv(a,b,t));
   136       xy c(conv(a,b,t));
   131       return Bezier3(c,b,r,p4);
   137       return Bezier3(c,b,r,p4);
   132     }
   138     }
       
   139   Bezier3 revert() { return Bezier3(p4,p3,p2,p1);}
   133   Bezier3 operator()(double a,double b) { return before(b).after(a/b); }
   140   Bezier3 operator()(double a,double b) { return before(b).after(a/b); }
   134   
   141   Bezier2 grad() { return Bezier2(3.0*(p2-p1),3.0*(p3-p2),3.0*(p4-p3)); }
       
   142   xy grad(double t) { return grad()(t); }
   135 };
   143 };
   136 
   144 
   137 } //END OF NAMESPACE LEMON
   145 } //END OF NAMESPACE LEMON
   138 
   146 
   139 #endif // LEMON_BEZIER_H
   147 #endif // LEMON_BEZIER_H