1
0

finished sweepline

This commit is contained in:
2019-05-15 16:28:26 +02:00
parent 57314a0a94
commit 6e1f8bbf63
7 changed files with 91 additions and 71 deletions

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
namespace TMI_practicum
{
@@ -17,7 +18,33 @@ namespace TMI_practicum
public double Distance(Circle otherCircle)
{
return Math.Sqrt(Math.Pow(X - otherCircle.X, 2) + Math.Pow(Y - otherCircle.Y, 2));
return Math.Round(Math.Sqrt(Math.Pow(X - otherCircle.X, 2) + Math.Pow(Y - otherCircle.Y, 2)), 15);
}
public IList<Intersection> FindIntersections(Circle c1)
{
var intersections = new List<Intersection>();
double d = Distance(c1);
if (d > R + c1.R || d < Math.Abs(R - c1.R) || d == 0.0 && R - c1.R == 0.0) return null;
double a = Math.Round((R * R - c1.R * c1.R + d * d) / (2.0*d), 15);
double px = Math.Round(X + a * (c1.X - X) / d, 15);
double py = Math.Round(Y + a * (c1.Y - Y) / d, 15);
double htemp = Math.Round(R * R - a * a, 15);
if (htemp == 0)
{
intersections.Add(new Intersection(px, py));
}
else
{
double h = Math.Round(Math.Sqrt(htemp), 15);
intersections.Add(new Intersection(px + h * (c1.Y - Y) / d, py - h * (c1.X - X) / d));
intersections.Add(new Intersection(px - h * (c1.Y - Y) / d, py + h * (c1.X - X) / d));
}
return intersections;
}
}
}