> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ploterr.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Add a ramp

> Put a curved ramp with a landing in a storey, read its exact length, and run a curved grid line beside it.

A ramp is a sloped plate along a path in the plan. It climbs from one height to another at one even slope, and a landing is a flat stretch on the way. This page draws a ramp that turns through a quarter of a circle, reads its exact length, and sets a curved grid line and a column beside it.

[Live example](https://floorkit-examples.ploterr.com/floorkit/guides/add-a-ramp?embed=1)

## Before you start

You have a session from [Start a building](https://docs.ploterr.com/floorkit/guides/start-a-building.md). The fields of a ramp are in the [`Ramp` API](https://docs.ploterr.com/floorkit/api/architecture/ramp).

## Write the ramp

A ramp has a `path` of plan points in metres, a `width`, the heights of its first and last point, and a `thickness`. This ramp has two points, `[6, 0]` and `[0, 6]`, and rises 1.2 m.

```typescript theme={null}
import type { BmRamp, BuildingSession } from '@opengeometry/floorkit';

export const radius = 6;

export const entryRamp: BmRamp = {
  id: 'entry-ramp',
  path: [
    [radius, 0],
    [0, radius],
  ],
  arcs: [{ through: [radius * Math.SQRT1_2, radius * Math.SQRT1_2] }],
  width: 1.5,
  fromElevation: 0,
  toElevation: 1.2,
  thickness: 0.2,
};

export function addRamp(session: BuildingSession): void {
  session.apply(
    {
      kind: 'add-element',
      buildingId: 'building',
      storeyId: 'ground',
      list: 'ramps',
      element: entryRamp,
    },
    session.revision,
  );
}
```

## A curved ramp

`arcs` has one entry for each segment of the path: `null` for a straight segment, or `{ through }`, a point on the arc between the two points of the segment. The point `[radius * √½, radius * √½]` lies halfway round, so the ramp above is a quarter circle of radius 6 m. The ramp keeps its slope along the arc: the plan outline, the walkline and the 3D body follow the curve, and the `1:n` label is the slope along it.

An arc is checked as a wall arc is. A `through` point on the line between the two points is refused with `arc-collinear`. An arc whose radius is less than half the width of the ramp is refused with `ramp-arc-tight`, because the inner edge of the ramp would turn back on itself.

## Add a landing

A landing sits at a station along the path: `at` is the distance in metres along the arc from the first point. The landing is flat, and the rest of the ramp takes the rise at an even slope. A landing 1 m long at 4.7 m puts a flat stretch on the arc.

```typescript theme={null}
export function addLanding(session: BuildingSession): void {
  session.apply(
    {
      kind: 'replace-element',
      buildingId: 'building',
      storeyId: 'ground',
      list: 'ramps',
      elementId: entryRamp.id,
      element: { ...entryRamp, landings: [{ at: 4.7, length: 1 }] },
    },
    session.revision,
  );
}

export function removeLanding(session: BuildingSession): void {
  session.apply(
    {
      kind: 'replace-element',
      buildingId: 'building',
      storeyId: 'ground',
      list: 'ramps',
      elementId: entryRamp.id,
      element: entryRamp,
    },
    session.revision,
  );
}
```

## Read the length

The length of a path with arcs is the sum of its chords and its arcs. An arc through three points has the radius of the circle through them, and the angle it spans: a point `through` that makes an obtuse angle at itself lies on the short way round.

```typescript theme={null}
type Point2 = BmRamp['path'][number];

const distance = (from: Point2, to: Point2) => Math.hypot(to[0] - from[0], to[1] - from[1]);

export function arcLength(from: Point2, through: Point2, to: Point2): number {
  const [near, far, chord] = [distance(from, through), distance(through, to), distance(from, to)];
  const doubleArea = Math.abs(
    (through[0] - from[0]) * (to[1] - from[1]) - (to[0] - from[0]) * (through[1] - from[1]),
  );
  const circle = (near * far * chord) / (2 * doubleArea);
  const angle = 2 * Math.asin(chord / (2 * circle));
  const shortWay =
    (from[0] - through[0]) * (to[0] - through[0]) + (from[1] - through[1]) * (to[1] - through[1]) <
    0;
  return circle * (shortWay ? angle : 2 * Math.PI - angle);
}

export function rampLength(ramp: BmRamp): number {
  return ramp.path.reduce((sum, from, index) => {
    const to = ramp.path[index + 1];
    if (!to) return sum;
    const arc = ramp.arcs?.[index];
    return sum + (arc ? arcLength(from, arc.through, to) : distance(from, to));
  }, 0);
}

export function rampGradient(ramp: BmRamp): number {
  const landings = (ramp.landings ?? []).reduce((sum, { length }) => sum + length, 0);
  return (rampLength(ramp) - landings) / (ramp.toElevation - ramp.fromElevation);
}
```

For this ramp the length is 3π, which is 9.4248 m. Without a landing the slope is 1 in 7.85. With the landing of 1 m the sloped length is 8.4248 m and the slope is 1 in 7.02.

## Run a curved grid line beside it

A grid line is saved in `BmBuilding.grids`. With `arc: { through }` it is the circular arc from `start` through that point to `end`, not the chord. Here grid `A` follows the same quarter circle as the ramp, and grid `1` is a radial line from the centre of the circle. `snapToGrids` snaps a point to the arc, and `columnGridLocation` names a column by the two grids that cross at it.

```typescript theme={null}
import {
  ColumnShape,
  columnGridLocation,
  snapToGrids,
  type BmGridLine,
} from '@opengeometry/floorkit';

export const station = 2.5;

const onCircle = (distanceFromCentre: number, angle: number): Point2 => [
  distanceFromCentre * Math.cos(angle),
  distanceFromCentre * Math.sin(angle),
];

export const curvedGrid: BmGridLine = {
  id: 'grid-a',
  label: 'A',
  start: [radius, 0],
  end: [0, radius],
  arc: { through: [radius * Math.SQRT1_2, radius * Math.SQRT1_2] },
};

export const radialGrid: BmGridLine = {
  id: 'grid-1',
  label: '1',
  start: [0, 0],
  end: onCircle(8, station / radius),
};

export function addGrids(session: BuildingSession): void {
  for (const element of [curvedGrid, radialGrid])
    session.apply(
      { kind: 'add-building-element', buildingId: 'building', list: 'grids', element },
      session.revision,
    );
}

export function addColumnOnGrid(session: BuildingSession): void {
  const building = session.snapshot().buildings[0];
  if (!building) return;
  session.apply(
    {
      kind: 'add-element',
      buildingId: 'building',
      storeyId: 'ground',
      list: 'columns',
      element: {
        id: 'ramp-column',
        shape: ColumnShape.RECTANGULAR,
        center: snapToGrids(building, onCircle(radius + 0.1, station / radius)),
        baseOffset: 0,
        width: 0.3,
        depth: 0.3,
      },
    },
    session.revision,
  );
}

export function columnStation(session: BuildingSession): number | undefined {
  const center = session
    .snapshot()
    .buildings[0]?.storeys.flatMap(({ columns }) => columns ?? [])
    .find(({ id }) => id === 'ramp-column')?.center;
  return center ? radius * Math.atan2(center[1], center[0]) : undefined;
}

export function columnLocation(session: BuildingSession): string | undefined {
  const building = session.snapshot().buildings[0];
  return building ? columnGridLocation(building, 'ramp-column') : undefined;
}
```

The point given to `snapToGrids` is 0.1 m outside the arc. The column lands on the arc, 2.5 m from the start of grid `A` along it (the station), and `columnGridLocation` gives `A-1`. The crossing is measured along the arc, not along the chord.

## Next

> [card] [Add a stair](https://docs.ploterr.com/floorkit/guides/add-a-stair.md)
>
> Climb a storey in equal steps.

> [card] [Ramp API](https://docs.ploterr.com/floorkit/api/architecture/ramp.md)
>
> See each field of a ramp.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.