example
This commit is contained in:
1 parent
e8ccd877a0
commit
a6b2f6677f
3 files changed
+46
-1
No files matched your search
@@ -11,6 +11,10 @@ class Point
|
|||||||
this.y = y;
|
this.y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Point(){
|
||||||
|
Point(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
public double X()
|
public double X()
|
||||||
{
|
{
|
||||||
return x;
|
return x;
|
||||||
@@ -26,4 +30,11 @@ class Point
|
|||||||
return Math.Sqrt(X() * X() + Y() * Y());
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,8 @@ class EntryPoint{
|
|||||||
public static void Main(String[] args){
|
public static void Main(String[] args){
|
||||||
Point point1 = new Point(3, 4);
|
Point point1 = new Point(3, 4);
|
||||||
Point point2 = 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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in new issue
Block a user