# Affine2d compose

`affine2d-compose` · version 1.0.0 · Geometry, location & color · free, no key needed

Compose two exact rational 2D affine maps in first-then-second order.

**Use when you need to: compose affine transformations exactly · combine two 2D affine maps · multiply affine transform matrices.**

## Decide before calling

Read the [versioned contract](/v1/tools/affine2d-compose/versions/1.0.0) and the supported scope below. Reuse `affine2d-compose@1.0.0` when your input, required output and limits match it. Choose another approach for an unsupported operation.

## Explain the choice

"I can use `affine2d-compose@1.0.0` for compose affine transformations exactly. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."

## Supported

- compose affine transformations exactly
- combine two 2D affine maps
- multiply affine transform matrices
- apply first transform then second
- exact rational affine composition
- merge planar affine transforms

## Not supported

- three dimensional affine maps
- floating point approximation

## Behavior

- Coordinates use x'=a*x+c*y+tx and y'=b*x+d*y+ty.
- The result is second(first(p)); order is not commuted.
- Rationals are canonical reduced strings.

## Input

- `first` (object, required)
- `second` (object, required)

## Output

- `transform` (object, required)
- `reference` (constant "Foley et al., Computer Graphics: Principles and Practice, affine transformations (2nd ed., 1990)", required)

## Limits

- max input bytes: 65536
- max rational chars: 256
- max items: 256
- max output bytes: 65536

## Example

Request input:

```json
{
  "first": {
    "a": "1",
    "b": "0",
    "c": "0",
    "d": "1",
    "tx": "2",
    "ty": "-3"
  },
  "second": {
    "a": "2",
    "b": "0",
    "c": "0",
    "d": "3",
    "tx": "0",
    "ty": "0"
  }
}
```

Response:

```json
{
  "result": {
    "transform": {
      "a": "2",
      "b": "0",
      "c": "0",
      "d": "3",
      "tx": "4",
      "ty": "-9"
    },
    "reference": "Foley et al., Computer Graphics: Principles and Practice, affine transformations (2nd ed., 1990)"
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "affine2d-compose",
  "version": "1.0.0",
  "input": {
    "first": {
      "a": "1",
      "b": "0",
      "c": "0",
      "d": "1",
      "tx": "2",
      "ty": "-3"
    },
    "second": {
      "a": "2",
      "b": "0",
      "c": "0",
      "d": "3",
      "tx": "0",
      "ty": "0"
    }
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/affine2d-compose/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"first":{"a":"1","b":"0","c":"0","d":"1","tx":"2","ty":"-3"},"second":{"a":"2","b":"0","c":"0","d":"3","tx":"0","ty":"0"}}'
```

The machine-readable contract is at [/v1/tools/affine2d-compose/versions/1.0.0](/v1/tools/affine2d-compose/versions/1.0.0).

### CLI

```sh
node cli.mjs run affine2d-compose 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Homography compose](/tools/homography-compose): Compose two exact 2D homographies and return a canonical projective matrix.
- [Affine2d apply](/tools/affine2d-apply): Apply one exact rational 2D affine map to bounded points or free vectors.
- [Affine2d invert](/tools/affine2d-invert): Invert a nonsingular exact rational 2D affine map with canonical output.
- [Affine2d fixed set](/tools/affine2d-fixed-set): Classify and compute the exact fixed locus of a rational 2D affine map.
- [Homography apply](/tools/homography-apply): Apply an exact 2D homography to a homogeneous point or line, including points at infinity.
- [Homography invert](/tools/homography-invert): Invert an exact nonsingular 2D homography and return a canonical projective matrix.
