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 so that multiplying every endpoint coordinate by 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:
For example, if the only denominators in the coordinates are and , we can choose . The point becomes after scaling, because and . All other endpoints must use the same ; we cannot choose a separate multiplier for each point. Both coordinate directions are scaled by the same factor.
Define as the maximum of and the absolute values of all scaled endpoint coordinates. Thus is an integer, and
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 .
For example, if the complete set of endpoints is and , we compare . Their maximum is , so . Including ensures that is at least , so later division by 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 and . Following the choice in Writing a line equation from two endpoints, let
Then the supporting line of this segment can be written as
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 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 and are differences of two integers, so they are integers too. To calculate , we perform two integer multiplications and add the results, so is also an integer.
Next consider the sizes of . The chosen ensures that every endpoint coordinate lies between and . Within this range, two numbers are farthest apart when one is and the other is , a difference of
For example, if , the coordinates lie between and , and two coordinates differ by at most . Reversing the subtraction changes the result from to , but its absolute value is still .
is the difference of two vertical coordinates. Its absolute value measures how far apart those coordinates are, so
is the difference of two horizontal coordinates. Similarly, they differ by at most , so
We have now obtained the result needed later: the coefficients chosen by these formulas are all integers, and the absolute values of are each at most . We have not bounded the absolute value of by . 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 denotes the first line and subscript the second. The intersection lies on both lines, so its coordinates satisfy both equations:
First eliminate . Multiply both sides of the first equation by , and both sides of the second by :
Subtract the lower equation from the upper one. Since , the two terms containing cancel, leaving
For brevity, denote the number in parentheses by (read "delta"):
Why is division by allowed? We chose two lines that are neither parallel nor coincident. The following cases show that cannot be .
- If both differ from , the lines can be written as and . If , then . Dividing both sides by the nonzero number gives . The coefficients of 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 , the first line is vertical and . The second line cannot also be vertical, so . Hence .
- If , similarly and , so .
We may therefore divide both sides of the equation obtained by elimination by , giving
Next eliminate . Multiply the first original equation by and the second by :
This time subtract the upper equation from the lower one. The terms containing cancel, giving
Dividing by again gives
For example, the lines and have coefficients and respectively. Here , so
Substituting into the original equations gives and , confirming that it is their intersection.
Step 3: Bound the denominator in the formula
is an integer because it is formed by multiplying and subtracting integers. It is nonzero, so its possible values are , and its absolute value is at least .
On the other hand, the absolute values of are all at most . Thus the absolute values of and are both at most . When two numbers are subtracted, the absolute value of their difference is at most the sum of their absolute values. For example, : subtracting a negative number can increase the absolute value, so the bound for just one product is not enough. Therefore
The numerators of the intersection coordinates are integers too. If the denominator is negative, multiply both numerator and denominator by . This leaves the value unchanged and makes the denominator . 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, , and the final denominator does not exceed the original denominator's absolute value .
Thus the positive denominator of each coordinate in lowest terms is at most . Endpoints are already integers and can be written as that integer divided by , so they satisfy the same bound. is an upper bound, not a claim that every intersection denominator equals it.