Вычислите площадь тупоугольного равнобедренного треугольника - C#
Формулировка задачи:
Даны координаты трех точек на плоскости. Если они могут быть вершинами равнобедренного тупоугольного треугольника, вычислите его площадь. Выведите длины сторон и площадь в порядке возрастания значений.
Решение задачи: «Вычислите площадь тупоугольного равнобедренного треугольника»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CAppl1
{
class Program
{
private struct Points
{
public int x;
public int y;
}
static void Main(string[] args)
{
Points[] point = new Points[3];
Program pr = new Program();
for (int i = 0; i < point.Length; i++)
{
Console.WriteLine("Координаты точки {0}", (i + 1));
point[i].x = pr.getX();
point[i].y = pr.getY();
}
Console.WriteLine("Ввод данных завершен\n");
//calculate long side
double side_a = pr.calculateLongSide(point[0].x, point[0].y, point[1].x, point[1].y);
double side_b = pr.calculateLongSide(point[0].x, point[0].y, point[2].x, point[2].y);
double side_c = pr.calculateLongSide(point[2].x, point[2].y, point[1].x, point[1].y);
//test triangle and calculate square
double square;
if (pr.testObtuseAngle_Isosceles(side_a, side_b, side_c))
{
square = pr.calculateSquare(side_a, side_b, side_c);
if (square != 0)
{
Console.WriteLine("сторона а = {0:0.###}", side_a);
Console.WriteLine("сторона b = {0:0.###}", side_b);
Console.WriteLine("сторона c = {0:0.###}", side_c);
Console.WriteLine("Треугольник является тупоугольным и равнобедренным. Его площадь {0:0.###}", square);
}
else Console.WriteLine("С помощью введенных точек построить треугольник нельзя");
}
else Console.WriteLine("Треугольник не удовлетворяет заданным условиям");
Console.ReadLine();
}
private int getX()
{
Console.Write("х = ");
return Convert.ToInt32(Console.ReadLine());
}
private int getY()
{
Console.Write("y = ");
return Convert.ToInt32(Console.ReadLine());
}
private double calculateLongSide(int x1, int y1, int x2, int y2)
{
double res;
return res = Math.Sqrt(Math.Pow((x1 - x2), 2) + Math.Pow((y1 - y2), 2));
}
//the Heron's formula
private double calculateSquare(double a, double b, double c)
{
double res;
double p = (a + b + c)/2;
return res = Math.Sqrt(p * (p - a) * (p - b) * (p - c));
}
//search obtuse angle and isosceles
private bool testObtuseAngle_Isosceles(double a, double b, double c)
{
bool res = false;
if ((((a * a + b * b) < c * c) || ((a * a + c * c) < b * b)
|| ((c * c + b * b) < a * a)) && (a == b) || (a == c) || (b == c))
{
res = true;
}
return res;
}
}
}