Skip to main content

Integer Scaling and Intersection Denominators

To choose one coefficient that works throughout, we first bound the denominators of intersection coordinates. This article starts with integer endpoints and derives the intersection formula by eliminating variables through addition and subtraction.

First turn rational coordinates into integers​

Input endpoint coordinates are rational numbers: they can be written as ratios of integers. Choose a positive integer common denominator DD so that multiplying every endpoint coordinate by DD gives an integer. The common denominator need not be the least one; multiplying all the positive denominators is also a valid choice.

Use uppercase letters for the scaled coordinates:

X=Dx,Y=Dy.X=Dx,\qquad Y=Dy.

For example, if the only denominators in the coordinates are 22 and 33, we can choose D=6D=6. The point (1/2,−2/3)(1/2,-2/3) becomes (3,−4)(3,-4) after scaling, because 6×(1/2)=36\times(1/2)=3 and 6×(−2/3)=−46\times(-2/3)=-4. All other endpoints must use the same DD; we cannot choose a separate multiplier for each point. Both coordinate directions are scaled by the same factor.

Define MM as the maximum of 11 and the absolute values of all scaled endpoint coordinates. Thus MM is an integer, and

M≥1,∣X∣≤M,∣Y∣≤M.M\ge1,\qquad |X|\le M,\quad |Y|\le M.

We first prove the result in scaled integer coordinates, then return to the original coordinates at the end. If the input coordinates are already integers, we can take D=1D=1.

For example, if the complete set of endpoints is (3,−4)(3,-4) and (−2,1)(-2,1), we compare 1,3,4,2,11,3,4,2,1. Their maximum is 44, so M=4M=4. Including 11 ensures that MM is at least 11, so later division by MM is not division by zero.

Notice that it is the input endpoints that become integers. Even with integer endpoints, the intersection of two segments may have fractional coordinates; the next section bounds the denominators of those fractions.

Why intersection denominators are at most 8M²​

Step 1: Write the line equation through two endpoints​

To find the intersection of two segments, first write the equations of their supporting lines. Here we require that the two endpoints of each segment be distinct.

Consider one of the segments, with endpoints (X1,Y1)(X_1,Y_1) and (X2,Y2)(X_2,Y_2). Following the choice in Writing a line equation from two endpoints, let

a=Y2−Y1,b=X1−X2,c=aX1+bY1,a=Y_2-Y_1,\qquad b=X_1-X_2,\qquad c=aX_1+bY_1,

Then the supporting line of this segment can be written as

aX+bY=c.aX+bY=c.

The preceding article explained why these coefficients are chosen and why they also work for horizontal and vertical lines. Here we investigate two further questions: Are these coefficients integers? How large can a,ba,b be? Both answers will be used to bound intersection denominators.

First consider whether they are integers. The previous section scaled every endpoint coordinate by the same factor to make them all integers. Both aa and bb are differences of two integers, so they are integers too. To calculate c=aX1+bY1c=aX_1+bY_1, we perform two integer multiplications and add the results, so cc is also an integer.

Next consider the sizes of a,ba,b. The chosen MM ensures that every endpoint coordinate lies between −M-M and MM. Within this range, two numbers are farthest apart when one is −M-M and the other is MM, a difference of

M−(−M)=M+M=2M.M-(-M)=M+M=2M.

For example, if M=4M=4, the coordinates lie between −4-4 and 44, and two coordinates differ by at most 4−(−4)=84-(-4)=8. Reversing the subtraction changes the result from 88 to −8-8, but its absolute value is still 88.

a=Y2−Y1a=Y_2-Y_1 is the difference of two vertical coordinates. Its absolute value measures how far apart those coordinates are, so

∣a∣=∣Y2−Y1∣≤2M.|a|=|Y_2-Y_1|\le2M.

b=X1−X2b=X_1-X_2 is the difference of two horizontal coordinates. Similarly, they differ by at most 2M2M, so

∣b∣=∣X1−X2∣≤2M.|b|=|X_1-X_2|\le2M.

We have now obtained the result needed later: the coefficients a,b,ca,b,c chosen by these formulas are all integers, and the absolute values of a,ba,b are each at most 2M2M. We have not bounded the absolute value of cc by 2M2M. This bound also applies only to this choice of coefficients; it cannot be reused after multiplying them by an arbitrary factor.

Apply the same choice to the other segment to obtain the second line equation. We now solve the two equations together to find the intersection.

Step 2: Find the intersection by elimination​

Add subscripts to distinguish the coefficients of the two lines. Subscript 11 denotes the first line and subscript 22 the second. The intersection lies on both lines, so its coordinates satisfy both equations:

{a1X+b1Y=c1,a2X+b2Y=c2.\begin{cases} \teachBlue{a_1}X+\teachBlue{b_1}Y=\teachBlue{c_1},\\ \teachOrange{a_2}X+\teachOrange{b_2}Y=\teachOrange{c_2}. \end{cases}

First eliminate YY. Multiply both sides of the first equation by b2b_2, and both sides of the second by b1b_1:

a1b2X+b1b2Y=c1b2,a2b1X+b2b1Y=c2b1.\begin{aligned} a_1b_2X+b_1b_2Y&=c_1b_2,\\ a_2b_1X+b_2b_1Y&=c_2b_1. \end{aligned}

Subtract the lower equation from the upper one. Since b1b2=b2b1b_1b_2=b_2b_1, the two terms containing YY cancel, leaving

(a1b2−a2b1)X=c1b2−c2b1.(a_1b_2-a_2b_1)X=c_1b_2-c_2b_1.

For brevity, denote the number in parentheses by Δ\Delta (read "delta"):

Δ=a1b2−a2b1.\Delta=a_1b_2-a_2b_1.

Why is division by Δ\Delta allowed? We chose two lines that are neither parallel nor coincident. The following cases show that Δ\Delta cannot be 00.

  • If both b1,b2b_1,b_2 differ from 00, the lines can be written as Y=−(a1/b1)X+c1/b1Y=-(a_1/b_1)X+c_1/b_1 and Y=−(a2/b2)X+c2/b2Y=-(a_2/b_2)X+c_2/b_2. If Δ=0\Delta=0, then a1b2=a2b1a_1b_2=a_2b_1. Dividing both sides by the nonzero number b1b2b_1b_2 gives a1/b1=a2/b2a_1/b_1=a_2/b_2. The coefficients of XX are the same: equal constant terms would make the lines coincide, and different constant terms would make them parallel. Neither possibility fits our choice.
  • If b1=0b_1=0, the first line is vertical and a1≠0a_1\ne0. The second line cannot also be vertical, so b2≠0b_2\ne0. Hence Δ=a1b2≠0\Delta=a_1b_2\ne0.
  • If b2=0b_2=0, similarly a2≠0a_2\ne0 and b1≠0b_1\ne0, so Δ=−a2b1≠0\Delta=-a_2b_1\ne0.

We may therefore divide both sides of the equation obtained by elimination by Δ\Delta, giving

X=c1b2−c2b1Δ.X=\frac{c_1b_2-c_2b_1}{\Delta}.

Next eliminate XX. Multiply the first original equation by a2a_2 and the second by a1a_1:

a1a2X+a2b1Y=a2c1,a2a1X+a1b2Y=a1c2.\begin{aligned} a_1a_2X+a_2b_1Y&=a_2c_1,\\ a_2a_1X+a_1b_2Y&=a_1c_2. \end{aligned}

This time subtract the upper equation from the lower one. The terms containing XX cancel, giving

(a1b2−a2b1)Y=a1c2−a2c1.(a_1b_2-a_2b_1)Y=a_1c_2-a_2c_1.

Dividing by Δ\Delta again gives

Y=a1c2−a2c1Δ.Y=\frac{a_1c_2-a_2c_1}{\Delta}.

For example, the lines X+Y=1X+Y=1 and X−Y=0X-Y=0 have coefficients (1,1,1)(1,1,1) and (1,−1,0)(1,-1,0) respectively. Here Δ=1×(−1)−1×1=−2\Delta=1\times(-1)-1\times1=-2, so

X=1×(−1)−0×1−2=12,Y=1×0−1×1−2=12.X=\frac{1\times(-1)-0\times1}{-2}=\frac12,\qquad Y=\frac{1\times0-1\times1}{-2}=\frac12.

Substituting (1/2,1/2)(1/2,1/2) into the original equations gives 1=11=1 and 0=00=0, confirming that it is their intersection.

Step 3: Bound the denominator in the formula​

Δ\Delta is an integer because it is formed by multiplying and subtracting integers. It is nonzero, so its possible values are 1,−1,2,−2,…1,-1,2,-2,\ldots, and its absolute value is at least 11.

On the other hand, the absolute values of a1,a2,b1,b2a_1,a_2,b_1,b_2 are all at most 2M2M. Thus the absolute values of a1b2a_1b_2 and a2b1a_2b_1 are both at most (2M)(2M)=4M2(2M)(2M)=4M^2. When two numbers are subtracted, the absolute value of their difference is at most the sum of their absolute values. For example, 4−(−4)=84-(-4)=8: subtracting a negative number can increase the absolute value, so the bound for just one product is not enough. Therefore

1≤∣Δ∣≤∣a1b2∣+∣a2b1∣≤4M2+4M2=8M2.1\le|\Delta| \le |a_1b_2|+|a_2b_1| \le4M^2+4M^2=8M^2.

The numerators of the intersection coordinates are integers too. If the denominator Δ\Delta is negative, multiply both numerator and denominator by −1-1. This leaves the value unchanged and makes the denominator ∣Δ∣|\Delta|. Reducing a fraction divides its numerator and denominator by a positive common factor, so it can only decrease the positive denominator or leave it unchanged. For example, −2/−6=2/6=1/3-2/-6=2/6=1/3, and the final denominator 33 does not exceed the original denominator's absolute value 66.

Thus the positive denominator of each coordinate in lowest terms is at most 8M28M^2. Endpoints are already integers and can be written as that integer divided by 11, so they satisfy the same bound. 8M28M^2 is an upper bound, not a claim that every intersection denominator equals it.