# Library/Graphics/Points

## Overview

A point is position in space. In a 3-dimensional world, a point is usually 3-tuple of x, y, and z coordinates.

##### Differentiating Points and Vectors

A graphics API may choose to distinguish between a point and vector class. Although the structures are both 3-tuples of the same layout and members, their usage can vary. For example, interpolating between two points and interpolating between two vectors often requires different algorithms to result in smooth, natural looking interpolation. Likewise, transforming a point versus a normal vector at that point (both 3-tuples) by a transformation matrix requires different algorithms. Differentiating the types in the compiler can help prevent inadvertent misuse of the algorithms.

On the other hand, additional classes and differentiation can add complexity and detail that is not strictly necessary to the system.

## Interface

### Functions

• subtract(pt, pt) -> vector
• distance(pt, pt) -> scalar
• distanceSquared(pt, pt) -> scalar - often useful when relative distances between points are being compared. This will save needing an additional square root operation on each distance calculation.

• interpolateLinear(pt, pt, t) -> pt
• interpolateSinusoidal(pt, pt, t) -> pt

### Extended Functions

• add(pt, pt) -> pt - if the system makes a distinction between points (positions) and vectors (directed lengths), then adding two points should not be part of the system - or should require additional syntactical work to ensure the programmer is not accidentally mixing unintended quantities.

## Variations

### 2D points

Even in a 3D world, there are many instances were a 2D position is meaningful: for example, the coordinate on a the surface of a 3-dimensional object can be represented by a 2D point.

### 4-tuples

A point may be represented by a 4-tuple with a w component as well. Useful for clip space / perpsective projection, etc. to be completed.