Math Utilities

Distance

Computes the straight-line Euclidean distance between two points in n-dimensional space. Access via MCP in Cursor or Windsurf, or REST at GET /v1/math/distance. Pass coordinates as arrays like [0,0] and [3,4] to get 5.0. Works in 2D, 3D, or higher dimensions with floating-point precision.

API Endpoint

GET /v1/math/distance

Code Examples

curl "https://tinyfn.io/v1/math/distance" \
  -H "X-API-Key: YOUR_API_KEY"
const response = await fetch('https://tinyfn.io/v1/math/distance', {
  headers: { 'X-API-Key': 'YOUR_API_KEY' }
});
const data = await response.json();
console.log(data);
import requests

response = requests.get('https://tinyfn.io/v1/math/distance',
    headers={'X-API-Key': 'YOUR_API_KEY'})
data = response.json()
print(data)

Use via MCP

Add to your AI agent

Connect your AI agent (Claude, Cursor, Windsurf, etc.) to TinyFn's math tools:

{
  "mcpServers": {
    "tinyfn-math": {
      "url": "https://tinyfn.io/mcp/math",
      "headers": {
        "X-API-Key": "YOUR_API_KEY"
      }
    }
  }
}

Learn more about MCP setup →

FAQ

How do I calculate distance between two 2D points?

Pass coordinate arrays like point1=[1,2] and point2=[4,6] to get the Euclidean distance. For (1,2) to (4,6), the result is 5.0.

Does the distance tool work with 3D coordinates?

Yes, it handles any dimensional space. Use [x,y,z] arrays for 3D points like [0,0,0] and [1,1,1] which gives distance √3 ≈ 1.732.

Can MCP agents use this for pathfinding calculations?

Absolutely. AI agents in Cursor or Cline can calculate distances between waypoints, find nearest neighbors, or compute movement costs in games and simulations.

What happens if the coordinate arrays have different lengths?

The calculation uses the minimum dimension count. Missing coordinates are treated as zero, so [1,2] and [3,4,5] computes distance in 2D space.

Is this faster than calculating distance manually in code?

For one-off calculations, yes. The optimized implementation handles edge cases and provides consistent floating-point precision without writing your own math.

Try Distance Now

Get your free API key and start using Distance in seconds.

Get Free API Key