Mathematical Representation of Points and Lines in Computer Graphics: From Equations to Pixels

Follow one segment from Cartesian coordinates to line equations, a point projection, a homogeneous intersection and seven selected pixels.

KnowledgeGate Team

Exam prep & CS education

Updated 21 Aug 20266 min read

A point and a line look elementary until a problem switches between endpoint, parametric, implicit, slope and pixel forms. Then it is easy to apply a valid formula to the wrong object, perhaps treating a finite segment as an infinite line or trying to calculate the slope of a vertical line. One segment carries every calculation: P0=(2,1) to P1=(8,5). Written out, it is 2x-3y-1=0 implicitly and P(t)=(2+6t,1+4t) parametrically, it lies 3/sqrt(13) from the point R=(5,4), it meets the line x+y-8=0 at (5,3), and it reduces to exactly seven pixels.

Output primitives: points, lines and the coordinate frame

An output primitive is a basic geometric object supplied to a graphics system for display. A mathematical point P=(x,y) specifies location, not width or area. Its visible size, colour and marker shape are rendering attributes, not extra coordinates. In 3D the point becomes P=(x,y,z), which adds a component without changing what a point means.

An infinite line through two distinct points extends in both directions. A ray has one endpoint and continues in one direction. Our output primitive is the closed segment from P0 to P1, including both endpoints.

Fix a Cartesian plane with positive x to the right and positive y upward. That frame holds until rasterisation. Geometry remains real-valued until pixels are chosen. A display API may instead put its origin at the top left with positive y downward, but that convention must be declared, not silently mixed into the mathematics.

Line representations that match the task

For distinct endpoints P0=(x0,y0) and P1=(x1,y1), define the direction d=P1-P0=(dx,dy). The parametric form is P(t)=P0+t d. Use all real t for the infinite line, t>=0 for the ray from P0, and 0<=t<=1 for the segment.

When dx!=0, slope forms are y-y0=m(x-x0) and y=mx+c. The implicit form Ax+By+C=0 works for every non-degenerate line. From two endpoints:

A=y0-y1, B=x1-x0, and C=x0y1-x1y0.

Here (A,B) is a normal vector, while (-B,A) is a possible direction vector. Either can be multiplied by any non-zero scale. Endpoint form suits drawing calls, parametric form handles interpolation and segment bounds, implicit form handles membership and sidedness, and slope form is convenient only for non-vertical lines. Review the vector and coordinate foundations in Engineering Mathematics.

Points and lines worked example: convert a segment and test a point

For P0=(2,1) and P1=(8,5):

  • dx=8-2=6 and dy=5-1=4

  • m=4/6=2/3

  • point-slope: y-1=(2/3)(x-2)

  • slope-intercept: y=(2/3)x-1/3

  • implicit: 2x-3y-1=0

  • parametric: P(t)=(2+6t,1+4t), with 0<=t<=1 for the segment

At t=1/2, P(1/2)=(5,3), so the midpoint is M=(5,3). The length is sqrt(6^2+4^2)=sqrt(52)=2sqrt(13).

Test points with the implicit equation. For M, 2(5)-3(3)-1=0, and t=1/2 also puts it inside the segment. For R=(5,4), 2(5)-3(4)-1=-3, so R is off the line. That raw value -3 is not a Euclidean distance because (2,-3) is not a unit normal.

Project R onto the line using d=(6,4):

t*=((R-P0) dot d)/(d dot d)=((3,3) dot (6,4))/52=30/52=15/26.

Therefore F=P0+t*d=(71/13,43/13). Substitution gives 2(71/13)-3(43/13)-1=0. The perpendicular distance is

|2(5)-3(4)-1|/sqrt(2^2+(-3)^2)=3/sqrt(13), approximately 0.832.

Cartesian plane with the segment from (2,1) to (8,5) lying on the dashed line 2x-3y-1=0, its midpoint (5,3), and the point (5,4) joined to its foot on the line 3/sqrt(13) away.

Vertical, horizontal and degenerate line inputs

For the vertical segment from V0=(4,2) to V1=(4,7), dx=0, so its slope is undefined. Its parametric form V(t)=(4,2+5t) and implicit form x-4=0 remain valid, with 0<=t<=1. Never divide by zero or call the slope infinite.

For the horizontal segment from H0=(1,6) to H1=(7,6), the slope is zero, H(t)=(1+6t,6), and the implicit form is y-6=0. A horizontal line has zero slope; a vertical line has undefined slope.

Coincident endpoints are a different object. D0=D1=(3,3) gives d=(0,0), zero length and no unique supporting line. Depending on its contract, a renderer may display a point or reject the line request.

Homogeneous coordinates for line incidence and intersection

Represent an affine point as p=[x,y,1]^T and a line as l=[A,B,C]^T. The incidence test is l^T p=Ax+By+C=0. Multiplying every component of either vector by the same non-zero scalar does not change the represented object after normalisation.

The line joining two points must pass the incidence test for both of them, so it has to be perpendicular to both point vectors, and the cross product of those vectors returns exactly such a vector. The endpoint cross product is [2,1,1]^T x [8,5,1]^T=(-4,6,2)^T. Divide by -2 to obtain l1=(2,-3,-1)^T. A second line through Q0=(3,5) and Q1=(7,1) gives [3,5,1]^T x [7,1,1]^T=(4,4,-32)^T, then l2=(1,1,-8)^T, or x+y-8=0.

The intersection point lies on both lines, so by the same incidence test it must be perpendicular to both line vectors, and once again their cross product produces it. Now l1 x l2=(25,15,5)^T. Dividing by the last coordinate yields (5,3,1)^T, so the intersection is M=(5,3). Both equations confirm it: 2(5)-3(3)-1=0 and 5+3-8=0. A result with homogeneous coordinate w=0 has no finite affine intersection, as happens for parallel lines. Linear Algebra for GATE CS is a useful follow-on for the vector and matrix operations behind this method.

Raster samples: turning a line segment into pixels

The equation describes infinitely many real-valued locations. A raster display must choose finitely many pixels. For DDA-style sampling, steps=max(|dx|,|dy|)=max(6,4)=6, xIncrement=6/6=1, and yIncrement=4/6=2/3.

k

exact sample

nearest pixel

0

(2,1)

(2,1)

1

(3,5/3)

(3,2)

2

(4,7/3)

(4,2)

3

(5,3)

(5,3)

4

(6,11/3)

(6,4)

5

(7,13/3)

(7,4)

6

(8,5)

(8,5)

Both endpoints are present, and none of these values creates a half-integer rounding tie. The pixels preserve an ordered visual path, but most selected pixel centres are not exactly on the continuous line. Keep m, t, A, B, C and coordinates exact until pixel selection. DDA-style sampling relies on floating-point increments; Bresenham's algorithm selects the same seven pixels for this segment using only integer arithmetic, which is why hardware favours it.

Pixel grid showing the segment from (2,1) to (8,5) rasterised to seven shaded pixels along the line y=(2/3)x-1/3, beside a table of the exact y value at each step k=0 to 6.

Points and lines: common traps and how questions test them

trap

what goes wrong

correct check

Treating 0<=t<=1 as an infinite line

Valid points beyond the endpoints are excluded

Use real t for the line

Using slope when dx=0

Division by zero

Use parametric or implicit form

Confusing zero and undefined slope

Horizontal and vertical cases swap

Check dy=0 versus dx=0

Treating scaled (A,B,C) triples as different

One line appears to become many

Compare up to non-zero scale

Calling the raw implicit value a distance

The normal length is ignored

Divide by sqrt(A^2+B^2)

Rounding before intersection

Exact incidence can be lost

Normalise first, round last

Omitting the final raster endpoint

The visible segment ends early

Sample k=0 through k=steps

Mixing upward-y and downward-y frames

Signs and orientation change

Declare the coordinate convention

Joining coincident endpoints as a line

No unique direction exists

Detect d=(0,0) first

Typical tasks ask you to convert endpoints, check a point against the finite segment, find a midpoint or distance, intersect lines, handle a vertical or degenerate case, or list pixels from increments. With our values, useful checks are t within [0,1], M=(5,3), distance 3/sqrt(13), both line equations equal to zero at the intersection, and seven samples for k=0 to 6.

The most reliable preparation is repetition on the forms themselves: reproduce the parametric, implicit and homogeneous forms of a segment from its endpoints, then test yourself on the finite-segment, infinite-line and degenerate-input cases until each check is automatic.

Points and lines: the short version and next step

Declare the coordinate frame, distinguish line, ray and segment, form d=P1-P0, then choose the representation that matches the task. Parametric form controls bounds, implicit form tests incidence, slope form needs dx!=0, and homogeneous vectors simplify intersections. Detect vertical and coincident endpoints, and round only while selecting pixels.

Without notes, recover P(t)=(2+6t,1+4t), 2x-3y-1=0, M=(5,3), F=(71/13,43/13), distance 3/sqrt(13), x+y-8=0, intersection vector (25,15,5), and pixels (2,1), (3,2), (4,2), (5,3), (6,4), (7,4), (8,5). Say each result aloud and explain why its chosen representation makes that operation straightforward. Continue with ZERO TO HERO (Complete Course) for the structured Computer Graphics route, or browse the wider CS Fundamentals catalogue.