Chapter 16
22 min read
Section 143 of 353

Arc Length and Curvature

Vector-Valued Functions

Learning Objectives

By the end of this section, you will be able to:

  1. Compute the arc length of a space curve using the integral formula L=abr(t)dtL = \int_a^b |\mathbf{r}'(t)| \, dt
  2. Understand arc length parametrization and why it simplifies formulas in differential geometry
  3. Calculate curvature using multiple formulas and interpret it geometrically
  4. Visualize the osculating circle and understand its relationship to curvature
  5. Construct the TNB (Frenet-Serret) frame and explain its components
  6. Apply arc length and curvature concepts to problems in physics, robotics, and machine learning

The Big Picture: Measuring Curves in Space

"A curve is the trace of a moving point. Arc length tells us how far it traveled; curvature tells us how sharply it turned."

When you drive a car, two quantities fundamentally matter for your journey: the distance traveled (measured by the odometer) and how sharply you turn the steering wheel. These correspond precisely to arc length and curvature in mathematics.

In the previous sections, we learned to describe curves in space using vector-valued functions r(t)=x(t),y(t),z(t)\mathbf{r}(t) = \langle x(t), y(t), z(t) \rangle. We computed velocities and accelerations. Now we ask deeper questions:

  • How long is the curve? — This leads us to arc length
  • How much does the curve bend? — This leads us to curvature
  • What circle best approximates the curve at each point? — This leads us to the osculating circle

📏 Arc Length Applications

  • Distance traveled along a path
  • Cable lengths for suspension bridges
  • Robot arm trajectory planning
  • GPS navigation route distances

🔄 Curvature Applications

  • Highway and railway design
  • Roller coaster engineering
  • Lens and mirror optics
  • Computer graphics smooth curves

Why These Concepts Matter

Arc length and curvature are intrinsic properties of curves — they depend only on the shape of the curve, not on how it is parametrized. This makes them essential for comparing curves, detecting patterns, and building invariant features for machine learning.


Arc Length: The Intuition

Imagine you are hiking along a winding mountain trail. Your GPS tells you the straight-line distance to your destination is 3 km, but the actual walking distance along the trail is 5 km. That 5 km is the arc length of your path.

From Straight Lines to Curves

For a straight line, measuring length is trivial — just use the distance formula. But for a curve, we cannot simply connect the endpoints. The key insight is to approximate the curve by many tiny line segments, then take a limit as the segments become infinitesimally small.

The Arc Length Approximation

  1. Divide the curve into nn small pieces
  2. Approximate each piece by a straight line segment of length Δsi\Delta s_i
  3. Sum all segments: Li=1nΔsiL \approx \sum_{i=1}^{n} \Delta s_i
  4. Take the limit as nn \to \infty: L=limni=1nΔsiL = \lim_{n \to \infty} \sum_{i=1}^{n} \Delta s_i

This limiting process gives us the arc length integral. The more segments we use, the closer our approximation becomes to the true arc length.

Interactive: Arc Length Approximation

Explore how arc length is computed for different space curves. Adjust the number of segments to see how the approximation converges to the exact value.

Loading 3D visualization...

The Arc Length Formula

Let r(t)=x(t),y(t),z(t)\mathbf{r}(t) = \langle x(t), y(t), z(t) \rangle be a smooth curve for t[a,b]t \in [a, b]. The arc length from t=at = a to t=bt = b is:

Arc Length Formula

L=abr(t)dt=ab(dxdt)2+(dydt)2+(dzdt)2dtL = \int_a^b |\mathbf{r}'(t)| \, dt = \int_a^b \sqrt{\left(\frac{dx}{dt}\right)^2 + \left(\frac{dy}{dt}\right)^2 + \left(\frac{dz}{dt}\right)^2} \, dt

Understanding the Integrand

The term r(t)|\mathbf{r}'(t)| is the speed — the magnitude of the velocity vector. It tells us how fast a point is moving along the curve at time tt.

  • Speed: r(t)=(x)2+(y)2+(z)2|\mathbf{r}'(t)| = \sqrt{(x')^2 + (y')^2 + (z')^2}
  • Distance = (Speed) × (Time), integrated over the entire journey

Why Speed Matters

The arc length formula says: to find the total distance traveled, integrate the speed over time. This is exactly what your car's odometer does — it measures instantaneous speed and accumulates it to give total distance.

Example: Arc Length of a Helix

Find the arc length of one complete turn of the helix r(t)=cost,sint,t\mathbf{r}(t) = \langle \cos t, \sin t, t \rangle for t[0,2π]t \in [0, 2\pi].

Solution:

First, find the velocity: r(t)=sint,cost,1\mathbf{r}'(t) = \langle -\sin t, \cos t, 1 \rangle

Next, find the speed: r(t)=sin2t+cos2t+1=1+1=2|\mathbf{r}'(t)| = \sqrt{\sin^2 t + \cos^2 t + 1} = \sqrt{1 + 1} = \sqrt{2}

Finally, integrate: L=02π2dt=22π=2π2L = \int_0^{2\pi} \sqrt{2} \, dt = \sqrt{2} \cdot 2\pi = 2\pi\sqrt{2}

Constant Speed

The helix above has constant speed 2\sqrt{2}. This makes the integral easy. For most curves, speed varies with tt, and the integral may require numerical methods.

Arc Length in 2D

For a plane curve r(t)=x(t),y(t)\mathbf{r}(t) = \langle x(t), y(t) \rangle, the formula simplifies:

L=ab(dxdt)2+(dydt)2dtL = \int_a^b \sqrt{\left(\frac{dx}{dt}\right)^2 + \left(\frac{dy}{dt}\right)^2} \, dt

For a curve given as y=f(x)y = f(x) for x[a,b]x \in [a, b]:

L=ab1+(dydx)2dxL = \int_a^b \sqrt{1 + \left(\frac{dy}{dx}\right)^2} \, dx

Arc Length Parametrization

A curve can be parametrized in many ways. For example, the circle x2+y2=1x^2 + y^2 = 1 can be written as:

  • r(t)=cost,sint\mathbf{r}(t) = \langle \cos t, \sin t \rangle for t[0,2π]t \in [0, 2\pi]
  • r(t)=cos2t,sin2t\mathbf{r}(t) = \langle \cos 2t, \sin 2t \rangle for t[0,π]t \in [0, \pi] (twice as fast)
  • r(t)=cost2,sint2\mathbf{r}(t) = \langle \cos t^2, \sin t^2 \rangle (non-uniform speed)

All these parametrizations trace the same circle, but with different speeds. The arc length parametrization is special: the parameter ss equals the distance traveled along the curve.

Arc Length Parametrization

A curve r(s)\mathbf{r}(s) is parametrized by arc length if r(s)=1|\mathbf{r}'(s)| = 1 for all ss.

This means the speed is always 1 — moving one unit in parameter ss moves exactly one unit along the curve.

Why Arc Length Parametrization?

  • Simplifies formulas: Curvature becomes κ=r(s)\kappa = |\mathbf{r}''(s)|
  • Intrinsic: Depends only on the curve's shape, not the speed of traversal
  • Uniform sampling: Equal parameter intervals give equal distances along the curve

To convert from parameter tt to arc length ss, use:

s(t)=atr(τ)dτs(t) = \int_a^t |\mathbf{r}'(\tau)| \, d\tau

Then invert this function to get t=t(s)t = t(s) and substitute.

In Practice

Arc length parametrization is often impossible to compute in closed form. The integral for s(t)s(t) may not have an elementary antiderivative, and inverting it may be even harder. Numerical methods are typically used in practice.


The Concept of Curvature

Curvature measures how sharply a curve bends. A straight line has zero curvature (no bending), while a tight circle has high curvature.

Intuitive Understanding

Imagine driving along different roads:

Road ShapeCurvatureSteering Wheel
Straight highwayκ = 0Centered, no turning
Gentle highway curveκ smallSlight turn
Parking lot hairpinκ largeFull turn
360° roundaboutκ = 1/RConstant turn

Curvature tells us how fast the direction of travel is changing relative to the distance traveled.

Definition of Curvature

For a curve parametrized by arc length ss, the curvature is:

κ=dTds=r(s)\kappa = \left| \frac{d\mathbf{T}}{ds} \right| = |\mathbf{r}''(s)|

where T\mathbf{T} is the unit tangent vector.

Radius of Curvature

The radius of curvature ρ\rho is the reciprocal of curvature:

ρ=1κ\rho = \frac{1}{\kappa}

This is the radius of the circle that best approximates the curve at that point (the osculating circle).

  • High curvature → small radius → tight bend
  • Low curvature → large radius → gentle curve
  • Zero curvature → infinite radius → straight line

Computing Curvature

While the definition uses arc length parametrization, we often have curves in other forms. Here are the key formulas:

General Parametric Form (3D)

For r(t)=x(t),y(t),z(t)\mathbf{r}(t) = \langle x(t), y(t), z(t) \rangle:

Curvature Formula (3D)

κ=r(t)×r(t)r(t)3\kappa = \frac{|\mathbf{r}'(t) \times \mathbf{r}''(t)|}{|\mathbf{r}'(t)|^3}

The cross product r×r\mathbf{r}' \times \mathbf{r}'' captures the component of acceleration perpendicular to velocity — the part that causes the curve to bend rather than just speed up.

General Parametric Form (2D)

For r(t)=x(t),y(t)\mathbf{r}(t) = \langle x(t), y(t) \rangle:

κ=xyyx(x2+y2)3/2\kappa = \frac{|x'y'' - y'x''|}{(x'^2 + y'^2)^{3/2}}

Explicit Form y = f(x)

For a function y=f(x)y = f(x):

Curvature for y = f(x)

κ=f(x)[1+(f(x))2]3/2\kappa = \frac{|f''(x)|}{[1 + (f'(x))^2]^{3/2}}

Example: Curvature of a Circle

Find the curvature of a circle of radius RR.

Solution:

Parametrize: r(t)=Rcost,Rsint\mathbf{r}(t) = \langle R\cos t, R\sin t \rangle

Velocity: r(t)=Rsint,Rcost\mathbf{r}'(t) = \langle -R\sin t, R\cos t \rangle

Acceleration: r(t)=Rcost,Rsint\mathbf{r}''(t) = \langle -R\cos t, -R\sin t \rangle

Cross product (z-component): xyyx=R2sin2t+R2cos2t=R2x'y'' - y'x'' = R^2\sin^2 t + R^2\cos^2 t = R^2

Speed: r=R|\mathbf{r}'| = R, so r3=R3|\mathbf{r}'|^3 = R^3

Curvature: κ=R2R3=1R\kappa = \frac{R^2}{R^3} = \frac{1}{R}

Key Result

A circle of radius RR has constant curvature κ=1/R\kappa = 1/R. Smaller circles (smaller RR) have larger curvature — they bend more sharply.


The Osculating Circle

The osculating circle (from Latin "osculare" = to kiss) at a point on a curve is the circle that best approximates the curve at that point. It:

  1. Passes through the point
  2. Has the same tangent direction as the curve
  3. Has the same curvature as the curve

Properties of the Osculating Circle

  • Radius: ρ=1/κ\rho = 1/\kappa (radius of curvature)
  • Center: Located at distance ρ\rho from the curve along the principal normal direction
  • Plane: Lies in the osculating plane (spanned by T\mathbf{T} and N\mathbf{N})

Think of it this way: if you freeze the curve at one instant and ask "what circle would I be tracing right now?", the answer is the osculating circle.

Interactive: Curvature and Osculating Circle

Explore how curvature varies along different curves. Watch the osculating circle change size as curvature changes — it shrinks at sharp bends and grows on gentler sections.

Loading 3D visualization...

The TNB Frame (Frenet-Serret Frame)

At each point on a smooth curve, we can define three mutually perpendicular unit vectors that form a natural coordinate system attached to the curve. This is called the TNB frame or Frenet-Serret frame.

VectorNameDefinitionMeaning
TUnit Tangentr'/|r'|Direction of motion
NPrincipal NormaldT/ds / |dT/ds|Direction curve is turning
BBinormalT × NPerpendicular to osculating plane

The Unit Tangent Vector T

T(t)=r(t)r(t)\mathbf{T}(t) = \frac{\mathbf{r}'(t)}{|\mathbf{r}'(t)|}

T\mathbf{T} points in the direction of motion. It always has length 1.

The Principal Normal Vector N

N(t)=dT/dsdT/ds=T(t)T(t)\mathbf{N}(t) = \frac{d\mathbf{T}/ds}{|d\mathbf{T}/ds|} = \frac{\mathbf{T}'(t)}{|\mathbf{T}'(t)|}

N\mathbf{N} points toward the center of curvature — the direction in which the curve is bending. It is perpendicular to T\mathbf{T}.

The Binormal Vector B

B(t)=T(t)×N(t)\mathbf{B}(t) = \mathbf{T}(t) \times \mathbf{N}(t)

B\mathbf{B} is perpendicular to both T\mathbf{T} and N\mathbf{N}. It points out of the osculating plane.

Frenet-Serret Formulas

The TNB frame evolves along the curve according to:

dTds=κN\frac{d\mathbf{T}}{ds} = \kappa \mathbf{N}

dNds=κT+τB\frac{d\mathbf{N}}{ds} = -\kappa \mathbf{T} + \tau \mathbf{B}

dBds=τN\frac{d\mathbf{B}}{ds} = -\tau \mathbf{N}

where κ\kappa is curvature and τ\tau is torsion (how much the curve twists out of its osculating plane).

Torsion

While curvature measures bending in the osculating plane, torsion τ\tau measures how the curve twists out of that plane. A plane curve has τ=0\tau = 0 everywhere. A helix has constant nonzero torsion.


Real-World Applications

1. Highway and Railway Design

Engineers cannot instantly change curvature on roads or tracks — this would require infinite acceleration. Instead, they use transition curves (clothoids or Euler spirals) where curvature changes linearly with arc length, providing smooth entry into circular curves.

Road ElementCurvatureDriver Experience
Straight sectionκ = 0No steering
Transition spiralκ increases linearlyGradual turn
Circular arcκ = constantSteady turn
Exit spiralκ decreases linearlyStraightening out

2. Roller Coaster Design

The thrill of a roller coaster comes from rapid changes in acceleration. Curvature determines the normal force experienced by riders:

FN=m(g+κv2)F_N = m(g + \kappa v^2)

At high speeds and high curvature, riders experience strong g-forces. Designers must balance excitement with safety limits.

3. Optics: Lens Design

The curvature of a lens surface determines its focusing power. The lensmaker's equation relates the focal length to the curvatures of both surfaces:

1f=(n1)(1R11R2)\frac{1}{f} = (n-1)\left(\frac{1}{R_1} - \frac{1}{R_2}\right)

4. Robotics: Path Planning

Robots must plan smooth paths that respect physical constraints. Arc length ensures correct distance estimates, while curvature limits ensure the robot can actually execute the path given its maximum turning radius.


Machine Learning Applications

Arc length and curvature are powerful features for machine learning because they are intrinsic — they depend only on the shape, not on position, orientation, or parametrization.

Gesture Recognition

When recognizing handwritten characters or gestures, curvature features are rotation-invariant. The letter "S" has a characteristic curvature profile (changing sign twice) that distinguishes it from "C" or "O" regardless of how the user writes it.

Trajectory Classification

In autonomous driving and surveillance, curvature profiles help classify vehicle behaviors:

BehaviorCurvature Pattern
Straight drivingNear-zero curvature
Lane changeBrief high curvature, then opposite
U-turnSustained high curvature
ParkingVariable high curvature

Shape Matching and Retrieval

To compare two curves, reparametrize both by arc length. Then compare their curvature functions. Similar shapes have similar curvature profiles.

Invariance Properties

Arc length is invariant under rotation and translation. Curvature is invariant under rotation, translation, and reparametrization. These invariances make curvature ideal for shape analysis in ML.


Python Implementation

Computing Arc Length

Arc Length Calculation
🐍arc_length.py
8Arc Length Integral

The arc length formula L = ∫|r'(t)| dt integrates the speed along the curve. At each instant t, |r'(t)| tells us how fast we're moving, and integrating this gives total distance traveled.

EXAMPLE
For a circle of radius 2, r(t) = (2cos(t), 2sin(t)), the speed |r'(t)| = 2, so L = ∫₀²π 2 dt = 4π
20Speed Function

The speed |r'(t)| is the magnitude of the velocity vector. We compute it as √(x'² + y'² + z'²) using np.linalg.norm().

28Helix Parametrization

The helix r(t) = (cos(t), sin(t), t/(2π)) traces a spiral. The xy-projection is a circle of radius 1, while z increases linearly with t.

62 lines without explanation
1import numpy as np
2from scipy.integrate import quad
3import matplotlib.pyplot as plt
4from mpl_toolkits.mplot3d import Axes3D
5
6def arc_length(r_prime, t_start, t_end, num_points=1000):
7    """
8    Calculate arc length of a curve r(t) from t_start to t_end.
9
10    Arc length formula: L = ∫|r'(t)| dt
11
12    The integrand |r'(t)| is the speed - how fast we're moving
13    along the curve at each instant.
14
15    Parameters:
16        r_prime: Function returning velocity vector [x'(t), y'(t), z'(t)]
17        t_start, t_end: Parameter bounds
18    """
19    def speed(t):
20        v = np.array(r_prime(t))
21        return np.linalg.norm(v)
22
23    length, error = quad(speed, t_start, t_end)
24    return length
25
26# Example: Helix r(t) = (cos(t), sin(t), t/(2π))
27def helix_position(t):
28    return np.array([np.cos(t), np.sin(t), t / (2 * np.pi)])
29
30def helix_velocity(t):
31    return np.array([-np.sin(t), np.cos(t), 1 / (2 * np.pi)])
32
33# Calculate arc length for one complete turn
34t_start, t_end = 0, 2 * np.pi
35length = arc_length(helix_velocity, t_start, t_end)
36
37print("Helix Arc Length Calculation")
38print("=" * 50)
39print(f"Curve: r(t) = (cos(t), sin(t), t/(2π))")
40print(f"Parameter range: t ∈ [{t_start:.4f}, {t_end:.4f}]")
41print(f"Arc length: {length:.6f}")
42
43# Analytical verification: For this helix, |r'(t)| = √(1 + 1/(4π²))
44# So L = 2π × √(1 + 1/(4π²))
45analytical_length = 2 * np.pi * np.sqrt(1 + 1 / (4 * np.pi**2))
46print(f"Analytical value: {analytical_length:.6f}")
47print(f"Difference: {abs(length - analytical_length):.2e}")
48
49# Visualize the curve
50fig = plt.figure(figsize=(10, 8))
51ax = fig.add_subplot(111, projection='3d')
52
53t_vals = np.linspace(0, 2*np.pi, 100)
54positions = np.array([helix_position(t) for t in t_vals])
55
56ax.plot(positions[:, 0], positions[:, 1], positions[:, 2],
57        'b-', linewidth=2, label='Helix')
58ax.set_xlabel('X')
59ax.set_ylabel('Y')
60ax.set_zlabel('Z')
61ax.set_title(f'Helix: Arc Length = {length:.4f}')
62ax.legend()
63
64plt.tight_layout()
65plt.show()

Computing Curvature

Curvature Calculation
🐍curvature.py
6Curvature Formula

κ = |r' × r''| / |r'|³ computes curvature without requiring arc length parametrization. The cross product captures the acceleration perpendicular to velocity.

35Cross Product

The cross product r' × r'' gives a vector whose magnitude equals |r'||r''|sin(θ). This measures the component of acceleration causing the curve to bend, not just speed up.

51Radius of Curvature

ρ = 1/κ is the radius of the osculating circle. A large radius means gentle bending; a small radius means sharp turning. For a straight line, ρ = ∞.

79 lines without explanation
1import numpy as np
2from scipy.misc import derivative
3import matplotlib.pyplot as plt
4
5def curvature_3d(r, t, h=1e-5):
6    """
7    Calculate curvature κ at parameter t for a 3D curve.
8
9    Formula: κ = |r' × r''| / |r'|³
10
11    This formula measures how quickly the direction of motion
12    is changing relative to the speed of motion.
13
14    High curvature = sharp bend (small osculating circle)
15    Low curvature = gentle curve (large osculating circle)
16    κ = 0 means straight line (osculating circle has infinite radius)
17    """
18    # Compute velocity and acceleration numerically
19    def r_x(s): return r(s)[0]
20    def r_y(s): return r(s)[1]
21    def r_z(s): return r(s)[2]
22
23    # First derivatives (velocity)
24    v = np.array([
25        derivative(r_x, t, dx=h),
26        derivative(r_y, t, dx=h),
27        derivative(r_z, t, dx=h)
28    ])
29
30    # Second derivatives (acceleration)
31    a = np.array([
32        derivative(r_x, t, dx=h, n=2),
33        derivative(r_y, t, dx=h, n=2),
34        derivative(r_z, t, dx=h, n=2)
35    ])
36
37    # Cross product magnitude
38    cross = np.cross(v, a)
39    cross_mag = np.linalg.norm(cross)
40
41    # Speed cubed
42    speed_cubed = np.linalg.norm(v) ** 3
43
44    # Curvature
45    if speed_cubed < 1e-10:
46        return 0
47
48    kappa = cross_mag / speed_cubed
49    return kappa
50
51def radius_of_curvature(kappa):
52    """Radius of curvature ρ = 1/κ (radius of osculating circle)"""
53    if kappa < 1e-10:
54        return float('inf')
55    return 1 / kappa
56
57# Example curves
58curves = {
59    'circle_r2': lambda t: np.array([2*np.cos(t), 2*np.sin(t), 0]),
60    'helix': lambda t: np.array([np.cos(t), np.sin(t), t/(2*np.pi)]),
61    'parabola': lambda t: np.array([t, t**2/2, 0]),
62}
63
64print("Curvature Analysis")
65print("=" * 60)
66
67for name, curve in curves.items():
68    print(f"\nCurve: {name}")
69    print("-" * 40)
70
71    t_values = [0, np.pi/4, np.pi/2, np.pi]
72    for t in t_values:
73        kappa = curvature_3d(curve, t)
74        rho = radius_of_curvature(kappa)
75        print(f"  t = {t:.4f}: κ = {kappa:.6f}, ρ = {rho:.4f}")
76
77# Special case: Circle of radius R has constant κ = 1/R
78print("\n" + "=" * 60)
79print("Verification: Circle of radius 2 should have κ = 1/2 = 0.5")
80circle = lambda t: np.array([2*np.cos(t), 2*np.sin(t), 0])
81print(f"Computed κ at t=0: {curvature_3d(circle, 0):.6f}")
82print(f"Computed κ at t=π/2: {curvature_3d(circle, np.pi/2):.6f}")

Machine Learning: Curve Feature Extraction

Curvature-Based ML Features
🐍curve_features.py
10ML Applications

Arc length and curvature are fundamental in robotics (path planning), graphics (smooth rendering), signal processing (trajectory analysis), and autonomous systems (lane following).

52Curvature from Discrete Data

For real-world data, we approximate derivatives using finite differences (np.gradient). The curvature formula κ = |v × a| / |v|³ still applies.

86Arc Length Reparametrization

Reparametrizing by arc length ensures uniform sampling along the curve. This is essential for comparing shapes and extracting consistent features across different trajectories.

101Curvature Features

Curvature-based features (mean, max, total curvature) are rotation and translation invariant - they describe the shape regardless of position or orientation. This makes them ideal for ML classification.

155 lines without explanation
1import numpy as np
2from scipy.integrate import cumulative_trapezoid
3from scipy.interpolate import interp1d
4
5class CurveAnalyzer:
6    """
7    Analyze curves for machine learning applications.
8
9    Arc length and curvature are crucial in:
10    - Robotics: Path planning and motion control
11    - Computer Graphics: Smooth curve rendering
12    - Signal Processing: Feature extraction from trajectories
13    - Autonomous Vehicles: Lane following and obstacle avoidance
14    """
15
16    def __init__(self, positions, times=None):
17        """
18        positions: Array of shape (n, d) - n points in d dimensions
19        times: Optional parameter values (defaults to uniform spacing)
20        """
21        self.positions = np.array(positions)
22        self.n_points = len(positions)
23        self.dim = positions.shape[1]
24
25        if times is None:
26            self.times = np.linspace(0, 1, self.n_points)
27        else:
28            self.times = np.array(times)
29
30    def compute_arc_length(self):
31        """
32        Compute cumulative arc length along the curve.
33
34        Returns array of arc lengths from start to each point.
35        This is essential for:
36        - Re-parametrizing curves by arc length
37        - Sampling curves uniformly in space (not in parameter)
38        - Computing curve metrics and features
39        """
40        # Compute point-to-point distances
41        diffs = np.diff(self.positions, axis=0)
42        segment_lengths = np.linalg.norm(diffs, axis=1)
43
44        # Cumulative arc length
45        arc_lengths = np.concatenate([[0], np.cumsum(segment_lengths)])
46        self.total_length = arc_lengths[-1]
47
48        return arc_lengths
49
50    def compute_curvature(self):
51        """
52        Compute curvature at each point using finite differences.
53
54        For discrete data, we approximate:
55        - Velocity from first differences
56        - Acceleration from second differences
57        Then apply κ = |v × a| / |v|³
58        """
59        # First differences (velocity approximation)
60        v = np.gradient(self.positions, self.times, axis=0)
61
62        # Second differences (acceleration approximation)
63        a = np.gradient(v, self.times, axis=0)
64
65        curvatures = []
66        for i in range(self.n_points):
67            vi = v[i]
68            ai = a[i]
69
70            if self.dim == 2:
71                # 2D curvature: κ = |v × a| / |v|³
72                cross = vi[0] * ai[1] - vi[1] * ai[0]
73                cross_mag = abs(cross)
74            else:
75                # 3D curvature
76                cross_mag = np.linalg.norm(np.cross(vi, ai))
77
78            speed_cubed = np.linalg.norm(vi) ** 3
79            if speed_cubed > 1e-10:
80                kappa = cross_mag / speed_cubed
81            else:
82                kappa = 0
83
84            curvatures.append(kappa)
85
86        return np.array(curvatures)
87
88    def reparametrize_by_arc_length(self, num_points=100):
89        """
90        Reparametrize curve so parameter proportional to arc length.
91
92        This is crucial for:
93        - Uniform sampling of curves
94        - Fair comparison of curve shapes
95        - Consistent feature extraction
96        """
97        arc_lengths = self.compute_arc_length()
98
99        # Create interpolators for each coordinate
100        interpolators = [
101            interp1d(arc_lengths, self.positions[:, d], kind='cubic')
102            for d in range(self.dim)
103        ]
104
105        # Sample uniformly in arc length
106        uniform_s = np.linspace(0, self.total_length, num_points)
107
108        new_positions = np.column_stack([
109            interpolators[d](uniform_s) for d in range(self.dim)
110        ])
111
112        return new_positions, uniform_s
113
114    def extract_curvature_features(self):
115        """
116        Extract curvature-based features for ML classification.
117
118        These features are rotation and translation invariant!
119        """
120        curvatures = self.compute_curvature()
121
122        features = {
123            'mean_curvature': np.mean(curvatures),
124            'max_curvature': np.max(curvatures),
125            'min_curvature': np.min(curvatures),
126            'std_curvature': np.std(curvatures),
127            'total_curvature': np.trapz(curvatures, self.times),
128            'arc_length': self.compute_arc_length()[-1],
129        }
130
131        return features
132
133# Example: Analyze a trajectory
134print("Curve Analysis for Machine Learning")
135print("=" * 60)
136
137# Generate sample trajectory (figure-8 pattern)
138t = np.linspace(0, 2*np.pi, 100)
139positions = np.column_stack([
140    np.sin(t),
141    np.sin(2*t) / 2
142])
143
144analyzer = CurveAnalyzer(positions, t)
145
146# Compute arc length
147arc_lengths = analyzer.compute_arc_length()
148print(f"\nTotal arc length: {analyzer.total_length:.4f}")
149
150# Compute curvature
151curvatures = analyzer.compute_curvature()
152print(f"Mean curvature: {np.mean(curvatures):.4f}")
153print(f"Max curvature: {np.max(curvatures):.4f}")
154
155# Extract ML features
156features = analyzer.extract_curvature_features()
157print("\nCurvature-based ML features:")
158for name, value in features.items():
159    print(f"  {name}: {value:.4f}")

Test Your Understanding


Summary

Arc length and curvature are fundamental tools for analyzing curves in space. They describe the intrinsic geometry of curves — properties that depend only on shape, not on how the curve is parametrized or positioned.

Key Formulas

ConceptFormula
Arc LengthL = ∫|r'(t)| dt
Speed|r'(t)| = √(x'² + y'² + z'²)
Arc Length Parameters(t) = ∫₀ᵗ |r'(τ)| dτ
Curvature (arc length)κ = |dT/ds| = |r''(s)|
Curvature (general)κ = |r' × r''| / |r'|³
Curvature (y = f(x))κ = |f''| / (1 + f'²)^(3/2)
Radius of Curvatureρ = 1/κ
Unit TangentT = r'/|r'|
Principal NormalN = T'/|T'|
BinormalB = T × N

Key Concepts

  1. Arc length measures the total distance traveled along a curve, computed by integrating speed
  2. Arc length parametrization uses distance as the parameter, giving unit speed and simplifying formulas
  3. Curvature measures how sharply a curve bends, with κ=1/R\kappa = 1/R for a circle of radius RR
  4. The osculating circle is the best-fit circle at each point, with radius equal to the radius of curvature
  5. The TNB frame provides a natural coordinate system attached to the curve at each point
  6. These concepts have wide applications in engineering (roads, roller coasters), physics (optics, mechanics), and machine learning (shape recognition, trajectory classification)
The Geometry of Curves:
"Arc length tells us how far we've traveled. Curvature tells us how much we've turned. Together, they capture the essence of a curve's shape."
Coming Next: In the next section, we'll explore Motion in Space — how position, velocity, and acceleration vectors describe the movement of objects along curves. We'll see how curvature and speed combine to determine the forces experienced by moving objects.
Loading comments...