The chi are intertwined in a straight line: the chimney is in a vіdrіzkіv on the flat. Designation of the point of the crossbar of two widows

Let me give you two shots. First jobs speckled P 1 (x 1; y 1)і P 2 (x 2; y 2). Other jobs speckled P 3 (x 3; y 3)і P 4 (x 4; y 4).

Mutual roztashuvannya vіdrіzkіv can be reversed for additional vector creations:

Let's look at the vіdrіzok P 3 P 4 i specks P1і P2.

Dot, mottled P1 lie left-handed in a straight line P 3 P 4, for her vector TV v1 > 0, Oscilki vector and positively oriented.
Dot, mottled P2 roztashovana right-handed in a straight line, for her vector tvir v2< 0 , Oskilki vector and negatively oriented.

In order to point P1і P2 lay on different sides in a straight line P 3 P 4, enough, so that the mind was beaten v 1 v 2< 0 (Vector create small signs).

Analogous mirkuvannya can be carried out for vіdrіzka P 1 P 2 i point P3і P4.

Otzhe, yakscho v 1 v 2< 0 і v 3 v 4< 0 then the winds change.

Vector production of two vectors is calculated according to the formula:

de:
ax, ay- coordinates of the first vector
bx, by- Coordinates of another vector.

Alignment of a straight line, as to pass through two different points, given by their coordinates.

Let two points on a straight line that do not escape: P1 with coordinates ( x1; y1)і P2 with coordinates (x 2; y 2). Vіdpovіdno vector with the cob at the point P1 and end at the point P2 may coordinate (x 2 -x 1, y 2 -y 1). Yakscho P(x, y)- enough point on the straight line, then the coordinates of the vector P 1 P equal (x - x 1, y - y 1).

For the help of the vector creation of Umov, the collinarity of vectors P 1 Pі P 1 P 2 can be written like this:
|P 1 P ,P 1 P 2 |=0, then. (x-x 1)(y 2 -y 1)-(y-y 1)(x 2 -x 1)=0
or
(y 2 -y 1)x + (x 1 -x 2)y + x 1 (y 1 -y 2) + y 1 (x 2 -x 1) = 0

Remain equal to rewrite like this:
ax + by + c = 0, (1)
de
a \u003d (y 2 -y 1),
b \u003d (x 1 -x 2),
c \u003d x 1 (y 1 -y 2) + y 1 (x 2 -x 1)

Again, a direct line can be set equal to the form (1).

How to know the point of intersection of straight lines?
It is obvious that the solution is to open up the system of equalization of straight lines:

ax 1 +by 1 =-c 1
ax 2 +by 2 =-c 2
(2)

Enter sign:

Here D is the primate of the system, and D x ,D y- vyznachniki, yakі at the result of the replacement of stovptsya koefіtsієntіv іn case of an unknown stovptsy of the free members. Yakscho D ≠ 0 then the system (2) is clear, then there is only one solution. You can know the solution behind the following formulas: x 1 = D x / D, y 1 = D y / D, Yaki are called Cramer's formulas | A small conspiracy, like a vyznachnik of a different order. The clerk has two diagonals: head and side. The head diagonal is made up of elements taken from the straight line of the upper left corner of the signpost into the lower right corner. Side diagonal - from the upper right to the lower left. The signifier of a different order is the addition of elements in the head diagonal minus the addition of elements in the side diagonal.

Krapka peretina straight

Give us two direct data given by your own coefficients and . It is necessary to know their point of intersection, otherwise you can figure out which are directly parallel.

Solution

As if the two are not straight parallel, all the stinks mingle. To know the crossing point, it is enough to put together a system of ties from two equal straight lines:

Koristuyuchisya Cramer's formula, once you know the solution of the system, like and be shukane cross point:



Like a banner of zero, tobto.

then the system cannot solve (straight parallel and do not escape) or may be infinitely rich (straight run away). It is necessary to separate two points, it is necessary to reconsider, which coefficients of direct proportions are with the very coefficient of proportionality, which is the coefficient of proportions, for which it is necessary to take two vindications, for which they stink offending equal to zero, then straight away:

Implementation

struct pt (double x, y;); struct line (double a, b, c;); constdouble EPS=1e-9; double det (double a, double b, double c, double d) (return a * d - b * c;) bool intersect (line m, line n, pt & res) (double zn = det (ma, mb, na , nb); if (abs(zn)< EPS)returnfalse; res.x=- det (m.c, m.b, n.c, n.b)/ zn; res.y=- det (m.a, m.c, n.a, n.c)/ zn;returntrue;} bool parallel (line m, line n){returnabs(det (m.a, m.b, n.a, n.b))< EPS;} bool equivalent (line m, line n){returnabs(det (m.a, m.b, n.a, n.b))< EPS &&abs(det (m.a, m.c, n.a, n.c))< EPS &&abs(det (m.b, m.c, n.b, n.c))< EPS;}

Lesson from the series " Geometric Algorithms»

Hello dear reader.

Porada 1: How to know the coordinates and points of the crossroads of two straight lines

Let's write three new functions.

The LinesCross() function is meaningful, tinker chi two vіdrіzka. For a new one, the roztashuvannya vіdrіzkіv vyznaєetsya with help of vector creations. To enumerate vector creations, let's write the VektorMulti () function.

The RealLess() function is available to implement the matching operation<” (строго меньше) для вещественных чисел.

Task1. Two rails are given by their coordinates. Put the program together, how do you sign it, chi are tinted chi winds, not knowing the breaking point.

Solution
. Another job is speckled.



Let's look at vіdrіzok ta dot ta.

Krapka lie left-handed in a straight line, for her vector tvir > 0, scaling vectors and positively oriented.

Krapka raztashovana right-handed in a straight line, for her vector twir < 0, так как векторы отрицательно ориентированы.

In order for the points i to lie on different sides in a straight line, it’s enough, so that the mind< 0 (векторные произведения имели противоположные знаки).

Analogous mirroring can be carried out for a vіdrіzka that point that.

Otzhe, yakscho then the winds change.

For cross-checking, use the LinesCross() function, and for calculating vector creations, use the VektorMulti() function.

ax, ay - coordinates of the first vector,

bx, by - coordinates of another vector.

Program geometry4; (Which are 2 wires intermingled?) Const _Eps: Real=1e-4; (precision varies) var x1, y1, x2, y2, x3, y3, x4, y4: real; var v1,v2,v3,v4: real; function RealLess(Const a, b: Real): Boolean; (Strictly less) begin RealLess: = b-a> _Eps end; (RealLess)function VektorMulti(ax,ay,bx,by:real): real; (ax, ay - coordinates a bx, by - coordinates b) begin vektormulti: = ax * by-bx * ay; end;Function LinesCross(x1,y1,x2,y2,x3,y3,x4,y4:real): boolean; (Which do the wedges intertwine?) begin v1:=vektormulti(x4-x3,y4-y3,x1-x3,y1-y3); v2:=vectormulti(x4-x3,y4-y3,x2-x3,y2-y3); v3:=vectormulti(x2-x1,y2-y1,x3-x1,y3-y1); v4:=vectormulti(x2-x1,y2-y1,x4-x1,y4-y1); if RealLess(v1*v2,0) and RealLess(v3*v4,0) (v1v2<0 и v3v4<0, отрезки пересекаются} then LinesCross:= true else LinesCross:= false end; {LinesCross}begin {main} writeln(‘Введите координаты отрезков: x1,y1,x2,y2,x3,y3,x4,y4’); readln(x1,y1,x2,y2,x3,y3,x4,y4); if LinesCross(x1,y1,x2,y2,x3,y3,x4,y4) then writeln (‘Да’) else writeln (‘Нет’) end.

The results of the programming program:

Enter the coordinates of the vіdrіzkіv: -1 1 2 2.52 2 1 -1 3
So.

We wrote a program, how to design, chi tint the wires, set by their coordinates.

On the approaching level, we are compiling an algorithm, for the help of which it will be possible to determine which point is in the middle of the tricutnik.

Chance reader.

You have already learned a lot of lessons from the series "Geometric Algorithms". Chi everything is written? I'll be more vdyachna, so you can deprive me of advice about these lessons. Possibly, it is necessary to do more.

With respect, Vira Gospodar.

Let me give you two shots. First jobs speckled P 1 (x 1; y 1)і P 2 (x 2; y 2). Other jobs speckled P 3 (x 3; y 3)і P 4 (x 4; y 4).

Mutual roztashuvannya vіdrіzkіv can be reversed for additional vector creations:

Let's look at the vіdrіzok P 3 P 4 i specks P1і P2.

Dot, mottled P1 lie left-handed in a straight line P 3 P 4, for her vector TV v1 > 0, Oscilki vector and positively oriented.
Dot, mottled P2 roztashovana right-handed in a straight line, for her vector tvir v2< 0 , Oskilki vector and negatively oriented.

In order to point P1і P2 lay on different sides in a straight line P 3 P 4, enough, so that the mind was beaten v 1 v 2< 0 (Vector create small signs).

Analogous mirkuvannya can be carried out for vіdrіzka P 1 P 2 i point P3і P4.

Otzhe, yakscho v 1 v 2< 0 і v 3 v 4< 0 then the winds change.

Vector production of two vectors is calculated according to the formula:

de:
ax, ay- Coordinates of the first vector,
bx, by- Coordinates of another vector.

Alignment of a straight line, as to pass through two different points, given by their coordinates.

Let two points on a straight line that do not escape: P1 with coordinates ( x1; y1)і P2 with coordinates (x 2; y 2).

Retin straight

Vіdpovіdno vector with the cob at the point P1 and end at the point P2 may coordinate (x 2 -x 1, y 2 -y 1). Yakscho P(x, y)- enough point on the straight line, then the coordinates of the vector P 1 P equal (x - x 1, y - y 1).

For the help of the vector creation of Umov, the collinarity of vectors P 1 Pі P 1 P 2 can be written like this:
|P 1 P,P 1 P 2 |=0, then. (x-x 1)(y 2 -y 1)-(y-y 1)(x 2 -x 1)=0
or
(y 2 -y 1)x + (x 1 -x 2)y + x 1 (y 1 -y 2) + y 1 (x 2 -x 1) = 0

Remain equal to rewrite like this:
ax + by + c = 0, (1)
de
a \u003d (y 2 -y 1),
b \u003d (x 1 -x 2),
c \u003d x 1 (y 1 -y 2) + y 1 (x 2 -x 1)

Again, a direct line can be set equal to the form (1).

How to know the point of intersection of straight lines?
It is obvious that the solution is to open up the system of equalization of straight lines:

ax 1 +by 1 =-c 1
ax 2 +by 2 =-c 2
(2)

Enter sign:

Here D is the primate of the system, and D x ,D y- vyznachniki, scho to come after the replacement of the coefficients for the most important incompetent member of the free members. Yakscho D ≠ 0 then the system (2) is clear, then there is only one solution. You can know the solution behind the following formulas: x 1 = D x / D, y 1 = D y / D, Yaki are called Cramer's formulas | A small conspiracy, like a vyznachnik of a different order. The clerk has two diagonals: head and side. The head diagonal is made up of elements taken from the straight line of the upper left corner of the signpost into the lower right corner. Side diagonal - from the upper right to the lower left. The signifier of a different order is the addition of elements in the head diagonal minus the addition of elements in the side diagonal.