Reputation: 609
I don't know if i ask this question in right place but i was too desperate and couldn't find any solution for my problem , i have 2 classes Point And Line and i want to write e triangle class and i want to know if 3 lines makes equilateral triangle or not and approve it in my triangle class how can i do it?
here is my point class:
class Point
{
public int X { get; set; }
public int Y { get; set; }
public Point(int x, int y)
{
X = x;
Y = y;
}
public override string ToString()
{
return string.Format("X: {0} Y:{1}",X,Y);
}
}
here is my line class:
class Line
{
public Point Start { get; set; }
public Point End { get; set; }
public double Length
{
get
{
return Math.Sqrt(Math.Pow(End.X - Start.X, 2) + Math.Pow(End.Y - Start.Y, 2));
}
}
public Line(Point start,Point end)
{
Start=start;
End = end;
}
public override string ToString()
{
return string.Format("Start Point X: {0} Y: {1} End Point X: {2} Y: {3}"
,Start.X,Start.Y,End.X,End.Y);
}
}
Upvotes: 1
Views: 1221
Reputation: 184
you need to write a method in the Line class to calculate the length of the current line. Remember that a negative length is the same as a positive ;)
Once you have this method, to get you the length of a line, you need to check that the 3 lines of the triangle are all equal. If they are, it is an equilateral triangle.
Upvotes: 4