Path Optimization with Friction and External Forces
When moving an object from point A to point B in the presence of friction and external forces, the total work required depends on the path taken. This article explores how to find the optimal path that minimizes the work needed, with concrete examples solved in Python.
The Physics
The work done on an object is given by:
$$W = \int_{\text{path}} \vec{F} \cdot d\vec{s}$$
When friction is present, we have:
$$W_{\text{total}} = W_{\text{applied}} + W_{\text{friction}}$$
For an object moving on a surface with friction coefficient $\mu$, the friction force is:
$$F_{\text{friction}} = \mu m g$$
If there’s also an external force field (like wind resistance or a gravitational gradient), the total work becomes:
$$W = \int_{\text{path}} \left( F_{\text{applied}} + F_{\text{external}} \right) \cdot d\vec{s}$$
Problem Setup
Let’s consider a specific example: moving a 10 kg box from point (0, 0) to point (10, 10) on a surface with:
- Variable friction coefficient: $\mu(x,y) = 0.1 + 0.05 \sin(x) \cos(y)$
- External force field (representing wind): $\vec{F}_{\text{ext}} = (-0.5x, -0.3y)$ N
Python Implementation
1 | import numpy as np |
Code Explanation
Physical Setup
The code begins by defining the physical parameters: mass (10 kg) and gravitational acceleration (9.81 m/s²). Two key functions characterize our problem environment:
Friction coefficient function: This varies spatially as $\mu(x,y) = 0.1 + 0.05 \sin(x) \cos(y)$, creating regions of higher and lower friction across the surface.
External force field: Defined as $\vec{F}_{\text{ext}} = (-0.5x, -0.3y)$, this represents a force that opposes motion and increases with distance from the origin.
Work Calculation
The calculate_work function computes the total work along a discretized path by summing contributions from each path segment:
- Friction work: For each segment, we calculate $W_f = \mu m g \Delta s$, where $\Delta s$ is the segment length
- External force work: We compute $W_{\text{ext}} = -\vec{F}_{\text{ext}} \cdot \Delta \vec{s}$, using the dot product of force and displacement
The midpoint approximation improves accuracy by evaluating forces at the segment center rather than endpoints.
Path Parameterization
The create_path function uses cubic spline interpolation to generate smooth paths from control points. This approach:
- Fixes the start (0,0) and end (10,10) points
- Uses intermediate control points as optimization variables
- Creates 100 discrete points for work calculation
- Ensures smooth, physically realistic trajectories
Optimization Process
The scipy minimize function with L-BFGS-B method searches for optimal control point positions that minimize total work. The initial guess uses evenly spaced points along the straight line.
Visualization Components
First plot: Shows the friction coefficient as a colored heatmap with both paths overlaid, revealing how the optimized path navigates through lower-friction regions.
Second plot: Displays the external force field as vectors, demonstrating how the optimal path takes advantage of force geometry.
Third plot (3D): The most insightful visualization shows the work density landscape. The height represents local work cost, and the paths appear as lines on this surface. The optimized path clearly follows valleys of lower work density. The get_work_density_along_path helper function samples the work density grid at each path point using nearest-neighbor lookup.
Additional analysis: The cumulative work plots show how total work accumulates along each path, while the work rate plots reveal where each path encounters high-cost regions.
Results
Optimizing path to minimize work... Work required for straight path: 179.76 J Work required for optimized path: 152.77 J Work saved: 26.99 J (15.0%)

Optimization complete! Graphs saved.
The optimization successfully finds a path requiring significantly less work than the straight-line approach. The optimized path intelligently:
- Avoids high-friction regions visible in the heatmap
- Leverages areas where external forces are less opposing
- Balances between path length and energy cost
The 3D visualization particularly highlights why certain routes are preferable—the optimal path stays in “valleys” of the work density landscape, even though it travels a longer distance.
This technique has practical applications in robotics path planning, logistics optimization, and any scenario where energy efficiency matters more than distance minimization.