Graphics / Reference / Lines in other octants

Lines in other octants

A first-octant line algorithm can be extended to all line directions by changing the driving coordinate or step direction and by using endpoint reversal to pair opposite octants.

The plane around a point is divided into eight octants, numbered anticlockwise from the positive x axis. The first-octant form handles a shallow line moving right and up, with 0 <= m <= 1 and x0 < x1.

Other octants require changes to the driving coordinate and step direction. A shallow line can use x as the coordinate advanced every iteration, while a steep line instead uses y. The secondary coordinate then either stays unchanged or changes by one in the required positive or negative direction. For example, a steep rising case drives with increasing y; a shallow falling case can drive with increasing x while y occasionally decreases; a steep falling case drives with decreasing y while the horizontal coordinate is updated when required.

Opposite octants can be paired by reversing the endpoints. In particular, a fifth-octant line can be converted to the corresponding first-octant direction by swapping its endpoints. This symmetry means four directional forms are sufficient for all eight octants rather than eight unrelated algorithms.

The associated octant figure numbers the eight sectors and pairs each direction with its opposite.

Eight octants surround the origin and are numbered anticlockwise, with arrows pairing each octant to its opposite to show how endpoint reversal reduces directional cases.
Opposite octants describe the same segment traversed in reverse, so endpoint swapping reduces eight directions to four algorithm families.

Builds on

Read