# Center of Mass API
> Centre-of-mass and barycentre mechanics as an API, computed locally and deterministically. The point-masses endpoint computes the centre of mass of a system of point masses in one, two or three dimensions, applying x_com = Σ(m_i·x_i)/Σm_i to each axis from a list of masses and their x (and optional y and z) coordinates — masses of 1, 2 and 3 at positions 0, 1 and 2 give a centre of mass at 1.333, and four equal masses at the corners of a square sit at its centre. The two-body endpoint computes the barycentre of two masses separated by a distance, r1 = d·m2/(m1+m2) from the first body, which always lies closer to the heavier one — for the Earth-Moon system the barycentre is about 4 670 km from Earth’s centre, still inside the planet. Lists may be passed as comma-separated values (masses=1,2,3&x=0,1,2) or as JSON arrays in a POST body, and units are consistent and unit-agnostic. Everything is computed locally and deterministically, so it is instant and private. Ideal for physics, engineering-statics, astronomy, robotics, game-physics and mechanics-education app developers, balance-point and barycentre tools, and simulation software. Pure local computation — no key, no third-party service, instant. Live, nothing stored. 2 endpoints. This is the centre of mass; for the rotational moment of inertia use a moment-of-inertia API.

## Authentication
All requests require your oanor API key in the `x-oanor-key` header. Get one at https://www.oanor.com/developer/keys.

```bash
curl -H "x-oanor-key: oanor_live_…" "https://api.oanor.com/centerofmass-api/..."
```

## Pricing
- **Free** (Free) — 5,100 calls/Mo, 2 req/s
- **Starter** ($4/Mo) — 51,000 calls/Mo, 6 req/s
- **Pro** ($12/Mo) — 230,000 calls/Mo, 15 req/s
- **Mega** ($38/Mo) — 1,340,000 calls/Mo, 40 req/s

## Endpoints

### CenterOfMass

#### `GET /v1/point-masses` — Center of mass of point masses

**Parameters:**
- `masses` (query, required, string) — Masses (comma-separated or array) Example: `1,2,3`
- `x` (query, required, string) — x coordinates Example: `0,1,2`
- `y` (query, optional, string) — y coordinates (2D/3D)
- `z` (query, optional, string) — z coordinates (3D)

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/centerofmass-api/v1/point-masses?masses=1%2C2%2C3&x=0%2C1%2C2"
```

**Response:**
```json
{
    "data": {
        "note": "Centre of mass x_com = Σ(m_i·x_i)/Σm_i, applied per axis. Masses [1,2,3] at x [0,1,2] give x_com = 8/6 ≈ 1.3333.",
        "x_com": 1.33333333,
        "inputs": {
            "count": 3,
            "total_mass": 6
        },
        "dimensions": 1
    },
    "meta": {
        "timestamp": "2026-06-05T19:50:22.935Z",
        "request_id": "fee3e554-2556-4361-9647-ad0cab42e1f8"
    },
    "status": "ok",
    "message": "Center of mass of point masses",
    "success": true
}
```

#### `GET /v1/two-body` — Two-body barycentre

**Parameters:**
- `m1` (query, required, string) — First mass Example: `10`
- `m2` (query, required, string) — Second mass Example: `2`
- `separation` (query, required, string) — Distance between them Example: `12`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/centerofmass-api/v1/two-body?m1=10&m2=2&separation=12"
```

**Response:**
```json
{
    "data": {
        "note": "Two-body barycentre: r1 = d·m2/(m1+m2) from the first mass; the barycentre lies closer to the heavier body. For the Earth-Moon system it sits inside the Earth.",
        "inputs": {
            "m1": 10,
            "m2": 2,
            "separation": 12
        },
        "mass_ratio": 5,
        "distance_from_m1": 2,
        "distance_from_m2": 10
    },
    "meta": {
        "timestamp": "2026-06-05T19:50:23.035Z",
        "request_id": "ff6e002e-b843-4134-8482-f021f3c28a57"
    },
    "status": "ok",
    "message": "Two-body barycentre",
    "success": true
}
```

### Meta

#### `GET /v1/meta` — Spec

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/centerofmass-api/v1/meta"
```

**Response:**
```json
{
    "data": {
        "notes": "Lists may be given as comma-separated values (e.g. masses=1,2,3&x=0,1,2) or as JSON arrays in a POST body. Units are consistent and unit-agnostic.",
        "service": "centerofmass-api",
        "endpoints": {
            "GET /v1/meta": "This document.",
            "GET /v1/two-body": "Barycentre distances of two masses separated by a distance.",
            "GET /v1/point-masses": "Centre of mass from lists of masses and x (and optional y, z) coordinates."
        },
        "description": "Centre of mass of a point-mass system (1D/2D/3D) and the barycentre of a two-body system."
    },
    "meta": {
        "timestamp": "2026-06-05T19:50:23.141Z",
        "request_id": "dc2d1f9b-24bf-470e-bdc7-ca09b99c735b"
    },
    "status": "ok",
    "message": "Meta",
    "success": true
}
```


---
Marketplace page: https://www.oanor.com/api/centerofmass-api
OpenAPI spec: https://www.oanor.com/api/centerofmass-api/openapi.json
