Files
FirstProject/Algorithms/Point.cs
T

47 lines
871 B
C#

namespace Algorithms;
using System;
public class Point
{
private double x;
private double y;
public Point(double x, double y)
{
this.x = x;
this.y = y;
}
public double X()
{
return x;
}
public double Y()
{
return y;
}
public double Distance()
{
return Math.Sqrt(X() * X() + Y() * Y());
}
public double Distance(Point other)
{
double xDiff = X() - other.X();
double yDiff = Y() - other.Y();
return Math.Sqrt(xDiff * xDiff + yDiff*yDiff);
}
public Point MidPointOf(Point other)
{
double midX = (X() + other.X()) / 2;
double midY = (Y() + other.Y()) / 2;
return new Point(midX, midY);
}
public override string ToString(){
return "{\"x\": " + this.x + ", \"y\": " + this.y + "}";
}
}