Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 226be2e

Browse files
cbdavidejakobkogler
authored andcommitted
Translated Finding the equation of a line for a segment (#325)
1 parent d691c81 commit 226be2e

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

src/geometry/segment-to-line.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<!--?title Finding the equation of a line for a segment -->
2+
# Finding the equation of a line for a segment
3+
4+
The task is: given the coordinates of the ends of a segment, construct a line passing through it.
5+
6+
We assume that the segment is non-degenerate, i.e. has a length greater than zero (otherwise, of course, infinitely many different lines pass through it).
7+
8+
### Two-dimensional case
9+
10+
Let the given segment be $PQ$ i.e. the known coordinates of its ends $P_x , P_y , Q_x , Q_y$ .
11+
12+
It is necessary to construct **the equation of a line in the plane** passing through this segment, i.e. find the coefficients $A , B , C$ in the equation of a line:
13+
14+
$$A x + B y + C = 0.$$
15+
16+
Note that for the required triples $(A, B, C)$ there are **infinitely many** solutions which describe the given segment:
17+
you can multiply all three coefficients by an arbitrary non-zero number and get the same straight line.
18+
Therefore, our task is to find one of these triples.
19+
20+
It is easy to verify (by substitution of these expressions and the coordinates of the points $P$ and $Q$ into the equation of a straight line) that the following set of coefficients fits:
21+
22+
$$A = P_y - Q_y,$$
23+
$$B = Q_x - P_x,$$
24+
$$C = - A P_x - B P_y.$$
25+
26+
### Integer case
27+
28+
An important advantage of this method of constructing a straight line is that if the coordinates of the ends were integer, then the coefficients obtained will also be **integer** . In some cases, this allows one to perform geometric operations without resorting to real numbers at all.
29+
30+
However, there is a small drawback: for the same straight line different triples of coefficients can be obtained.
31+
To avoid this, but do not go away from the integer coefficients, you can apply the following technique, often called **rationing**. Find the [greatest common divisor](./algebra/euclid-algorithm.html) of numbers $| A | , | B | , | C |$ , we divide all three coefficients by it, and then we make the normalization of the sign: if $A <0$ or $A = 0, B <0$ then multiply all three coefficients by $-1$ .
32+
As a result, we will come to the conclusion that for identical straight lines, identical triples of coefficients will be obtained, which makes it easy to check straight lines for equality.
33+
34+
### Real case
35+
36+
When working with real numbers, you should always be aware of errors.
37+
38+
The coefficients $A$ and $B$ will have the order of the original coordinates, the coefficient $C$ is of the order of the square of them. This may already be quite large numbers, and, for example, when we [intersect straight lines](./geometry/lines-intersection.html), they will become even larger, which can lead to large rounding errors already when the coordinates of the end points are of order $10^3$.
39+
40+
Therefore, when working with real numbers, it is desirable to produce the so-called **normalization**, this is straightforward: namely, to make the coefficients such that $A ^ 2 + B ^ 2 = 1$ . To do this, calculate the number $Z$ :
41+
42+
$$Z = \sqrt{A ^ 2 + B ^ 2},$$
43+
44+
and divide all three coefficients $A , B , C$ by it.
45+
46+
Thus, the order of the coefficients $A$ and $B$ will not depend on the order of the input coordinates, and the coefficient $C$ will be of the same order as the input coordinates. In practice, this leads to a significant improvement in the accuracy of calculations.
47+
48+
Finally, we mention the **comparison** of straight lines - in fact, after such a normalization, for the same straight line, only two triples of coefficients can be obtained: up to multiplication by $-1$.
49+
Accordingly, if we make an additional normalization taking into account the sign (if $A < -\varepsilon$ or $| A | < \varepsilon$, $B <- \varepsilon$ then multiply by $-1$ ), the resulting coefficients will be unique.
50+
51+
### Three-dimensional and multidimensional case
52+
53+
Already in the three-dimensional case there is **no simple equation** describing a straight line (it can be defined as the intersection of two planes, that is, a system of two equations, but this is an inconvenient method).
54+
55+
Consequently, in the three-dimensional and multidimensional cases we must use the **parametric method of defining a straight line** , i.e. as a point $p$ and a vector $v$ :
56+
57+
$$p + v t, ~~~ t \in \mathbb{R}.$$
58+
59+
Those. a straight line is all points that can be obtained from a point $p$ adding a vector $v$ with an arbitrary coefficient.
60+
61+
The **construction** of a straight line in a parametric form along the coordinates of the ends of a segment is trivial, we just take one end of the segment for the point $p$, and the vector from the first to the second end — for the vector $v$.

src/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ especially popular in field of competitive programming.*
9494
- [Length of the union of segments](./geometry/length-of-segments-union.html)
9595
- [Oriented area of a triangle](./geometry/oriented-triangle-area.html)
9696
- [Intersection Point of Lines](./geometry/lines-intersection.html)
97+
- [Finding the equation of a line for a segment](./geometry/segment-to-line.html)
9798
- [Check if two segments intersect](./geometry/check-segments-intersection.html)
9899
- [Intersection of Segments](./geometry/segments-intersection.html)
99100
- [Circle-Line Intersection](./geometry/circle-line-intersection.html)

0 commit comments

Comments
 (0)