A simple algorithm for determining the intersection of two segments.

Comments 11

Task

Find the point of intersection of two straight lines plotted from two points with known coordinates and azimuths from these points.

Application

To study the behavior of animals, the radiotelemetry method is often used: the object under study is marked with a radio transmitter, which emits a radio signal of a certain frequency, and then the researcher, using a receiver and receiving antenna, monitors the movements of this object. One of possible ways definitions exact location object is the biangulation method. To do this, the researcher needs to take 2 azimuths to the object under study from points with known coordinates. The location of the object will correspond to the intersection point of these two azimuths. The coordinates of the points from which azimuths are measured can be taken using a satellite navigator (GPS), or azimuths are taken from reference points whose coordinates are known in advance. Azimuth in this case is the direction to the source of the strongest signal emanating from an object marked by the transmitter, usually measured in degrees.


Before calculations, it is necessary to convert the points obtained using GPS into a projected coordinate system, for example the corresponding UTM zone; this can be done using DNRGarmin.

In order for the calculated location of the object under study to most accurately correspond to the real position, the following must be taken into account:

1) you must try to wait until the error in determining the coordinates in the navigator is as small as possible.

2) so that the angle between azimuths tends to 90 degrees (at least it is more than 30 and less than 150 degrees).

The distance from which the azimuth should be taken depends on the range of the transmitter, and the rule of thumb is that the error in determining the azimuth increases by 1 meter with the distance from the object under study for every 10 m. Thus. when taking an azimuth with a distance to an object of 100 m, the error will be 10 m. However, this rule is applicable in flat, open areas. It should be taken into account that uneven terrain and tree and shrub vegetation screen and reflect the signal. You should avoid being in close proximity to the object being studied, because firstly, too strong a signal will make it difficult to determine the exact azimuth, and, secondly, in some cases it will be impossible to calculate the intersection point due to the fact that the second azimuth will pass behind the point where the first azimuth was taken. The time interval between taking a pair of azimuths should be minimized, but, of course, depends on the mobility of the animal being studied.

Solution

The problem is solved using simple geometry and solving a system of equations.
To begin with, from a point and azimuth we obtain the equation of a straight line, for this:

From Eq. general view:

ax + by + c = 0

provided that b<>0 we get

y = kx + d , Where k=-(a/b) , d=-(c/b)

thus we get

k=tan(a)
d=y-tan(a)*x
b=1

k1x + d1 = y
k2x + d2 = y

We obtain the X and Y coordinates of the common point of two lines (the point of intersection).

The equation must include two special occasions, when the lines are parallel (k1=k2).

Since we are not dealing with vectors or rays, that is, lines have no beginning and end, it is also necessary to provide for the case of intersection of lines outside the area of ​​interest, the so-called. false intersection. The solution to this problem is achieved by measuring the azimuth from the false point a3 to point 2, if the azimuth a3 = a2, then the intersection is false, the return azimuth from the resulting point back to the original 2 should not be equal to one of the original azimuths.

Necessary procedure in Avenue language it looks like this:

a1rad = (90-a1)*pi/180
a2rad = (90-a2)*pi/180
"if the line is parallel to the x-axis
if ((a1 = 0) or (a1 = 180)) then
l1a = 1
l1b = 0
l1c = x1
else
l1a = -(a1rad.tan)
l1b = 1
l1c = y1 - (a1rad.tan*x1)
end
if ((a2 = 0) or (a2 = 180)) then
l2a = 1
l2b = 0
l2c = x2
else
l2a = -(a2rad.tan)
l2b = 1
l2c = y2 - (a2rad.tan*x2)
end
D1 = l1a*l2b
D2 = l2a*l1b
D3 = D1 - D2
"If the lines are parallel, non-existent values ​​are written to the result field
if (D3 = 0) then
resX = 9999
resY = 9999
else resX = ((l1c*l2b) - (l2c*l1b))/D3
resY = ((l1a*l2c) - (l2a*l1c))/D3 end
  1. To find the coordinates of the intersection point of the graphs of functions, you need to equate both functions to each other, transfer them to left side all terms containing $ x $, and to the right the rest and find the roots of the resulting equation.
  2. The second method is to create a system of equations and solve it by substituting one function into another
  3. The third method involves graphically constructing functions and visual definition intersection points.

The case of two linear functions

Consider two linear functions $ f(x) = k_1 x+m_1 $ and $ g(x) = k_2 x + m_2 $. These functions are called direct. It is quite easy to construct them; you need to take any two values ​​$ x_1 $ and $ x_2 $ and find $ f(x_1) $ and $ (x_2) $. Then repeat the same with the function $ g(x) $. Next, visually find the coordinate of the intersection point of the function graphs.

You should know that linear functions have only one intersection point and only when $ k_1 \neq k_2 $. Otherwise, in the case of $ k_1=k_2 $ the functions are parallel to each other, since $ k $ is the slope coefficient. If $ k_1 \neq k_2 $ but $ m_1=m_2 $, then the intersection point will be $ M(0;m) $. It is advisable to remember this rule to quickly solve problems.

Example 1
Let $ f(x) = 2x-5 $ and $ g(x)=x+3 $ be given. Find the coordinates of the intersection point of the function graphs.
Solution

How to do this? Since two linear functions are presented, the first thing we look at is the slope coefficient of both functions $ k_1 = 2 $ and $ k_2 = 1 $. We note that $ k_1 \neq k_2 $, so there is one intersection point. Let's find it using the equation $ f(x)=g(x) $:

$$ 2x-5 = x+3 $$

We move the terms with $ x $ to the left side, and the rest to the right:

$$ 2x - x = 3+5 $$

We have obtained $ x=8 $ the abscissa of the intersection point of the graphs, and now let’s find the ordinate. To do this, let’s substitute $ x = 8 $ into any of the equations, either in $ f(x) $ or in $ g(x) $:

$$ f(8) = 2\cdot 8 - 5 = 16 - 5 = 11 $$

So, $ M (8;11) $ is the point of intersection of the graphs of two linear functions.

If you cannot solve your problem, then send it to us. We will provide detailed solution. You will be able to view the progress of the calculation and gain information. This will help you get your grade from your teacher in a timely manner!

Answer
$$ M (8;11) $$

The case of two nonlinear functions

Example 3
Find the coordinates of the intersection point of the function graphs: $ f(x)=x^2-2x+1 $ and $ g(x)=x^2+1 $
Solution

What about two nonlinear functions? The algorithm is simple: we equate the equations to each other and find the roots:

$$ x^2-2x+1=x^2+1 $$

We spread it around to different parties equation terms with and without $x$:

$$ x^2-2x-x^2=1-1 $$

The abscissa of the desired point has been found, but it is not enough. The ordinate $y$ is still missing. We substitute $ x = 0 $ into any of the two equations of the problem condition. For example:

$$ f(0)=0^2-2\cdot 0 + 1 = 1 $$

$ M (0;1) $ - intersection point of function graphs

Answer
$$ M (0;1) $$

Lesson from the series “Geometric algorithms”

Hello dear reader!

Let's continue to get acquainted with geometric algorithms. In the last lesson, we found the equation of a straight line using the coordinates of two points. We got an equation of the form:

Today we will write a function that, using the equations of two straight lines, will find the coordinates of their intersection point (if there is one). To check the equality of real numbers, we will use the special function RealEq().

Points on the plane are described by a pair of real numbers. When using a real type, it is better to implement comparison operations using special functions.

The reason is known: on the Real type in the Pascal programming system there is no order relation, so it is better not to use records of the form a = b, where a and b are real numbers.
Today we will introduce the RealEq() function to implement the “=” (strictly equal) operation:

Function RealEq(Const a, b:Real):Boolean; (strictly equal) begin RealEq:=Abs(a-b)<=_Eps End; {RealEq}

Task. The equations of two straight lines are given: and . Find the point of their intersection.

Solution. The obvious solution is to solve the system of line equations: Let's rewrite this system a little differently:
(1)

Let us introduce the following notation: , , . Here D is the determinant of the system, and are the determinants resulting from replacing the column of coefficients for the corresponding unknown with a column of free terms. If , then system (1) is definite, that is, it has a unique solution. This solution can be found using the following formulas: , which are called Cramer formulas. Let me remind you how the second-order determinant is calculated. The determinant distinguishes two diagonals: the main and the secondary. The main diagonal consists of elements taken in the direction from the upper left corner of the determinant to the lower right corner. Side diagonal - from the upper right to the lower left. The second-order determinant is equal to the product of the elements of the main diagonal minus the product of the elements of the secondary diagonal.

The code uses the RealEq() function to check equality. Calculations on real numbers are performed with an accuracy of _Eps=1e-7.

Program geom2; Const _Eps: Real=1e-7;(calculation accuracy) var a1,b1,c1,a2,b2,c2,x,y,d,dx,dy:Real; Function RealEq(Const a, b:Real):Boolean; (strictly equal) begin RealEq:=Abs(a-b)<=_Eps End; {RealEq} Function LineToPoint(a1,b1,c1,a2,b2,c2: real; var x,y:real):Boolean; {Определение координат точки пересечения двух линий. Значение функции равно true, если точка пересечения есть, и false, если прямые параллельны. } var d:real; begin d:=a1*b2-b1*a2; if Not(RealEq(d,0)) then begin LineToPoint:=True; dx:=-c1*b2+b1*c2; dy:=-a1*c2+c1*a2; x:=dx/d; y:=dy/d; end else LineToPoint:=False End;{LineToPoint} begin {main} writeln("Введите коэффициенты уравнений: a1,b1,c1,a2,b2,c2 "); readln(a1,b1,c1,a2,b2,c2); if LineToPoint(a1,b1,c1,a2,b2,c2,x,y) then writeln(x:5:1,y:5:1) else writeln("Прямые параллельны."); end.

We have compiled a program with which you can, knowing the equations of lines, find the coordinates of their intersection points.

Let two lines be given and you need to find their point of intersection. Since this point belongs to each of the two given lines, its coordinates must satisfy both the equation of the first line and the equation of the second line.

Thus, in order to find the coordinates of the point of intersection of two lines, one must solve the system of equations

Example 1. Find the point of intersection of lines and

Solution. We will find the coordinates of the desired intersection point by solving the system of equations

The intersection point M has coordinates

Let's show how to construct a straight line using its equation. To construct a straight line, it is enough to know its two points. To construct each of these points, we specify an arbitrary value for one of its coordinates, and then from the equation we find the corresponding value for the other coordinate.

If in the general equation of a straight line both coefficients at the current coordinates are not equal to zero, then to construct this straight line it is best to find the points of its intersection with the coordinate axes.

Example 2. Construct a straight line.

Solution. We find the point of intersection of this line with the abscissa axis. To do this, we solve their equations together:

and we get . Thus, the point M (3; 0) of intersection of this line with the abscissa axis has been found (Fig. 40).

Then solving together the equation of this line and the equation of the ordinate axis

we find the point of intersection of the line with the ordinate axis. Finally, we construct a straight line from its two points M and

Perpendicular line

This task is probably one of the most popular and in demand in school textbooks. The tasks based on this topic are varied. This is the definition of the point of intersection of two lines, this is also the definition of the equation of a line passing through a point on the original line at any angle.

We will cover this topic using in our calculations the data obtained using

It was there that the transformation of the general equation of a straight line into an equation with an angular coefficient and vice versa was considered, and the determination of the remaining parameters of the straight line according to given conditions.

What do we lack in order to solve the problems that this page is dedicated to?

1. Formulas for calculating one of the angles between two intersecting lines.

If we have two lines that are given by the equations:

then one of the angles is calculated like this:

2. Equation of a straight line with a slope passing through a given point

From formula 1, we can see two borderline states

a) when then and therefore these two given lines are parallel (or coincide)

b) when , then , and therefore these lines are perpendicular, that is, intersect at right angles.

What could be the initial data for solving such problems, other than the given straight line?

A point on a straight line and the angle at which the second straight line intersects it

Second equation of the line

What problems can a bot solve?

1. Two lines are given (explicitly or indirectly, for example, by two points). Calculate the point of intersection and the angles at which they intersect.

2. Given one straight line, a point on a straight line and one angle. Determine the equation of a straight line that intersects a given line at a specified angle

Examples

Two lines are given by equations. Find the point of intersection of these lines and the angles at which they intersect

line_p A=11;B=-5;C=6,k=3/7;b=-5

We get the following result

Equation of the first line

y = 2.2 x + (1.2)

Equation of the second line

y = 0.4285714285714 x + (-5)

Angle of intersection of two straight lines (in degrees)

-42.357454705937

Point of intersection of two lines

x = -3.5

y = -6.5


Don't forget that the parameters of two lines are separated by a comma, and the parameters of each line are separated by a semicolon.

A straight line passes through two points (1:-4) and (5:2). Find the equation of the line that passes through the point (-2:-8) and intersects the original line at an angle of 30 degrees.

We know one straight line because we know the two points through which it passes.

It remains to determine the equation of the second line. We know one point, but instead of the second, the angle at which the first line intersects the second is indicated.

It seems that everything is known, but the main thing here is not to make mistakes. We are talking about the angle (30 degrees) not between the x-axis and the line, but between the first and second line.

This is why we post like this. Let's determine the parameters of the first line and find out at what angle it intersects the x-axis.

line xa=1;xb=5;ya=-4;yb=2

General equation Ax+By+C = 0

Coefficient A = -6

Factor B = 4

Factor C = 22

Coefficient a= 3.6666666666667

Coefficient b = -5.5

Coefficient k = 1.5

Angle of inclination to the axis (in degrees) f = 56.309932474019

Coefficient p = 3.0508510792386

Coefficient q = 2.5535900500422

Distance between points=7.211102550928

We see that the first line intersects the axis at an angle 56.309932474019 degrees.

The source data does not say exactly how the second line intersects the first. You can, after all, construct two lines that satisfy the conditions, the first one rotated 30 degrees CLOCKWISE, and the second 30 degrees COUNTERclockwise.

Let's count them

If the second line is rotated 30 degrees COUNTERclockwise, then the second line will have the degree of intersection with the x-axis 30+56.309932474019 = 86 .309932474019 degrees

line_p xa=-2;ya=-8;f=86.309932474019

Parameters of a straight line according to specified parameters

General equation Ax+By+C = 0

Coefficient A = 23.011106998916

Coefficient B = -1.4840558255286

Coefficient C = 34.149767393603

Equation of a straight line in segments x/a+y/b = 1

Coefficient a= -1.4840558255286

Coefficient b = 23.011106998916

Equation of a straight line with angular coefficient y = kx + b

Coefficient k = 15.505553499458

Angle of inclination to the axis (in degrees) f = 86.309932474019

Normal equation of the line x*cos(q)+y*sin(q)-p = 0

Coefficient p = -1.4809790664999

Coefficient q = 3.0771888256405

Distance between points=23.058912962428

Distance from a point to a straight line li =

that is, our second line equation is y= 15.505553499458x+ 23.011106998916