From a6b2f6677f81fcd057e058ca17345c1572d3c742 Mon Sep 17 00:00:00 2001 From: didier amyot Date: Tue, 15 Aug 2023 10:19:37 -0400 Subject: [PATCH] example --- Algorithms/Point.cs | 11 +++++++++++ Algorithms/Program.cs | 3 ++- Algorithms/Triangle.cs | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 Algorithms/Triangle.cs diff --git a/Algorithms/Point.cs b/Algorithms/Point.cs index 7b4108e..fe6f8c1 100644 --- a/Algorithms/Point.cs +++ b/Algorithms/Point.cs @@ -11,6 +11,10 @@ class Point this.y = y; } + public Point(){ + Point(0, 0); + } + public double X() { return x; @@ -26,4 +30,11 @@ class Point return Math.Sqrt(X() * X() + Y() * Y()); } + public Point MidPointOf(Point other) + { + double midX = (X() + other.X()) / 2; + double midY = (Y() + other.Y()) / 2; + return new Point(midX, midY); + } + } \ No newline at end of file diff --git a/Algorithms/Program.cs b/Algorithms/Program.cs index 7e9fc6b..c5e8b59 100644 --- a/Algorithms/Program.cs +++ b/Algorithms/Program.cs @@ -10,7 +10,8 @@ class EntryPoint{ public static void Main(String[] args){ Point point1 = new Point(3, 4); Point point2 = new Point(-3, -4); + Point midPoint = point1.MidPointOf(point2); - Console.WriteLine("Hello World From A Class: " + p.Distance()); + Console.WriteLine("Hello World From A Class: " + midPoint.X() + ", " + midPoint.Y()); } } diff --git a/Algorithms/Triangle.cs b/Algorithms/Triangle.cs new file mode 100644 index 0000000..c6a5c32 --- /dev/null +++ b/Algorithms/Triangle.cs @@ -0,0 +1,33 @@ +namespace Algorithms; +internal class Triangle + +{ + + private Point sommet1; + private Point sommet2; + private Point sommet3; + + + + public Triangle(Point sommet1,Point sommet2,Point sommet3) + { + this.sommet1 = sommet1; + this.sommet2 = sommet2; + this.sommet3 = sommet3; + } + + public static Triangle Equilateral(double longueur) + { + + Point sommet1 = new Point(0,0); + Point sommet2 = new Point(0, longueur); + + // H2 = A2 + B2 + // B = sqrt (H2 - A2) + + double x = Math.Sqrt(longueur*longueur - longueur*longueur/4); + Point sommet3 = new Point(x, longueur/2); + return new Triangle(sommet1, sommet2, sommet3); + } + +} \ No newline at end of file