Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- public class Triangle
- {
- private readonly Point a;
- private readonly Point b;
- private readonly Point c;
- private double AB => GetLengthOfSide(a, b);
- private double AC => GetLengthOfSide(a, c);
- private double BC => GetLengthOfSide(b, c);
- public Triangle(Point a, Point b, Point c)
- {
- this.a = a;
- this.b = b;
- this.c = c;
- }
- public double GetPerimeter()
- {
- return AB + AC + BC;
- }
- public double GetSquare()
- {
- double p = (AB + BC + AC) / 2;
- return Math.Sqrt(p * (p - AB) * (p - AC) * (p - BC));
- }
- public bool GetAngleBetweenEqualsSides(out double angle)
- {
- if (AB == BC) {
- angle = Math.Asin(AC / (2 * AB * AC * BC / 4 / GetSquare()));
- return true;
- }
- if (AB == AC) {
- angle = Math.Asin(BC / (2 * AB * AC * BC / 4 / GetSquare()));
- return true;
- }
- if (AC == BC) {
- angle = Math.Asin(AB / (2 * AB * AC * BC / 4 / GetSquare()));
- return true;
- }
- angle = -1;
- return false;
- }
- public bool GetHypotenuse(out double hypotenuse)
- {
- if (Math.Sqrt(AB * AB + AC * AC) == BC ) {
- hypotenuse = Math.Sqrt(AB * AB + AC * AC);
- return true;
- }
- if (Math.Sqrt(AB * AB + BC * BC) == AC) {
- hypotenuse = Math.Sqrt(AB * AB + BC * BC);
- return true;
- }
- if (Math.Sqrt(BC * BC + AC * AC) == AB) {
- hypotenuse = Math.Sqrt(BC * BC + AC * AC);
- return true;
- }
- hypotenuse = -1;
- return false;
- }
- private static double GetLengthOfSide(Point first, Point second)
- {
- return Math.Sqrt((first.GetX() - second.GetX()) * (first.GetX() - second.GetX()) +
- (first.GetY() - second.GetY()) * (first.GetY() - second.GetY()));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement