Code-Eli  0.3.6
curvature.hpp
Go to the documentation of this file.
1 /*********************************************************************************
2 * Copyright (c) 2013 David D. Marshall <ddmarsha@calpoly.edu>
3 *
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * David D. Marshall - initial code and implementation
11 ********************************************************************************/
12 
13 #ifndef eli_geom_curve_curvature_hpp
14 #define eli_geom_curve_curvature_hpp
15 
16 #include "eli/code_eli.hpp"
17 
18 namespace eli
19 {
20  namespace geom
21  {
22  namespace curve
23  {
24  template<typename curve__>
25  void curvature(typename curve__::data_type &rho, const curve__ &c, const typename curve__::data_type &t)
26  {
27  // check to make sure have valid curve
28  assert(c.degree()>0);
29 
30  typename curve__::point_type xp(c.fp(t)), xpp(c.fpp(t));
31 
32  if (xp.innerSize()==2)
33  {
34  typename curve__::data_type tmp1(std::abs(xp(0)*xpp(1)-xp(1)*xpp(0))), tmp2(xp.norm());
35 
36  rho=tmp1/(tmp2*tmp2*tmp2);
37  }
38  else
39  {
40  typename curve__::point_type tmp1;
41  typename curve__::data_type tmp2(xp.norm());
42 
43  tmp1 << (xp(1)*xpp(2)-xp(2)*xpp(1)), (xp(2)*xpp(0)-xp(0)*xpp(2)), (xp(0)*xpp(1)-xp(1)*xpp(0));
44  rho=tmp1.norm()/(tmp2*tmp2*tmp2);
45  }
46  }
47  }
48  }
49 }
50 #endif
Definition: math.hpp:20
void curvature(typename curve__::data_type &rho, const curve__ &c, const typename curve__::data_type &t)
Definition: curvature.hpp:25