# Curvature of a parametric curve

## (Draft / notes)

Let $$s: \mathbb R \rightarrow \mathbb R^3$$ be the function representing a parametric curve and $$t \in \mathbb R$$ the curve parameter:

$c(s(t)) = \frac{ \| s'(t) \| }{ \| s'(t) × s''(t) \| }$

Where '×' is the cross product, $$s'(t)$$ speed at $$t$$ and $$s''$$ the acceleration.

// The MIT License
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

// Computes the curvature of a parametric curve f(x) as
// c(f) = |f'|^3 / | f' x f''|
vec3 a, b, c, m, n;
// curve
vec3 mapD0(float t){
return 0.25 + a*cos(t+m)*(b+c*cos(t*7.0+n));
}
// curve derivative (velocity)
vec3 mapD1(float t){
return -7.0*a*c*cos(t+m)*sin(7.0*t+n) - a*sin(t+m)*(b+c*cos(7.0*t+n));
}
// curve second derivative (acceleration)
vec3 mapD2(float t){
return 14.0*a*c*sin(t+m)*sin(7.0*t+n) - a*cos(t+m)*(b+c*cos(7.0*t+n)) - 49.0*a*c*cos(t+m)*cos(7.0*t+n);
}

//----------------------------------------

float curvature( float t ){
vec3 r1 = mapD1(t); // first derivative
vec3 r2 = mapD2(t); // second derivative
return pow(length(r1),3.0) / length(cross(r1,r2));
}