Добрый день. Необходимо на форме отрисовать равнобедренный треугольник. На входе дано только координаты вершин, что определяют основу треугольника и суму длин двух других сторон. В тех случаях, когда основа параллельна одной из осей проблем нету. Уже час не могу придумать как определить координаты третьей вершины когда она не параллельна. 

    2 answers 2

    Let A , B be the vertices of the base, C be the unknown vertex. If the sum s given, the lengths of the sides, then each side is equal to half of this sum. So, AC = BC = s/2 .

    Let M be the middle of AB (its coordinates are equal to the half-sum of coordinates A and B ). Then CM is the height, from the right triangle AMC we have:

     CM = sqrt(AC^2 - AM^2) = sqrt(s^2/4 - AB^2/4) 

    (If there is a negative number under the root, the task obviously has no solutions.)

    So, we have the length of the vector MC , its direction is easy to find, given that it is perpendicular to the vector AB : if (p, q) is the vector AB , then the vector (-q, p) perpendicular to it, the vector (-q/l, p/l) (where l = sqrt(p^2 + q^2) ) is perpendicular to AB and has a length of 1 and vector (-q/l*L, p/l*L) (where L is the previously calculated length CM ) is perpendicular to AB and has a length equal to the length of MC .

    So we have the vector MC . Adding its coordinates to the coordinates of point M , we get point C

    same graphically

    Note that we have 2 possible solutions, different in the sign of the MC vector: to get the second solution, change the sign of the MC from the first solution.

    This and other similar tasks will be coded very easily if there are classes in your arsenal representing a point, a vector, and operations on them are defined. For example, in my code, the solution usually looks like this (C #):

     var AB = B - A; var M = A + AB * 0.5; var L = Math.Sqrt(s * s - AB.Length * AB.Length) / 2; var MC = AB.Rotate(Angle.FromDegrees(90)).GetUnitVector() * L; var C1 = M + MC; var C2 = M + (-MC); 
    • What draw the picture, if not a secret? - nitrocaster
    • @Flammable: (sprinkling ashes on his head) ordinary Paint.NET :( - VladD
    • I was thinking ... - nitrocaster
    • Well, Paint.NET is not ms paint, but with xfig on such jobs it still doesn’t suffer. - alexlz 2:57 pm
    • @alexlz: and he happens under the vents? - VladD pm

    write a system of equations of a circle

      (x-x0)^2+(y-y0)^2=R (x-x01)^2+(y-y01)^2=R 

    (where x and y are the coordinates of the third point) (where x0 y0 x01 y01 are the coordinates of two known vertices), but how did you decide when the base is parallel to one of the axes if in any case two possible solutions to the problem are obtained. The third point can be from above or below grounds.

    • Thank! It does not matter which of the two points to take. - Freest
    • not at all) - Dikaz
    • one
      @Freest, mark the answer as accepted if it came up. - nitrocaster
    • Right in the formulas R ^ 2. - Yuri Negometyanov