1
0

improvement

This commit is contained in:
2019-05-21 14:49:12 +02:00
parent c022a2915b
commit a7b988a977
4 changed files with 149 additions and 43 deletions

View File

@@ -23,26 +23,27 @@ namespace TMI_practicum
public IEnumerable<Intersection> FindIntersections(Circle c1)
{
IList<Intersection> intersections;
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 a = (R * R - c1.R * c1.R + d * d) / (2.0*d);
double px = X + a * (c1.X - X) / d;
double py = Y + a * (c1.Y - Y) / d;
double htemp = Math.Round(R * R - a * a, 15);
if (htemp == 0)
{
intersections = new Intersection[1];
intersections[0] = new Intersection(px, py);
intersections[0] = new Intersection(Math.Round(px, 15), Math.Round(py, 15));
}
else
{
intersections = new Intersection[2];
double h = Math.Round(Math.Sqrt(htemp), 15);
intersections[0] = new Intersection(px + h * (c1.Y - Y) / d, py - h * (c1.X - X) / d);
intersections[1] = new Intersection(px - h * (c1.Y - Y) / d, py + h * (c1.X - X) / d);
intersections[0] = new Intersection(Math.Round(px + h * (c1.Y - Y) / d, 15), Math.Round(py - h * (c1.X - X) / d, 15));
intersections[1] = new Intersection(Math.Round(px - h * (c1.Y - Y) / d, 15), Math.Round(py + h * (c1.X - X) / d, 15));
}
return intersections;