1
0
This commit is contained in:
2019-05-21 20:50:35 +02:00
parent 168262ea7b
commit eb2e9172a9
3 changed files with 34 additions and 15 deletions

View File

@@ -32,8 +32,8 @@ namespace TMI_practicum
double px = X + a * (c1.X - X) / d; double px = X + a * (c1.X - X) / d;
double py = Y + a * (c1.Y - Y) / d; double py = Y + a * (c1.Y - Y) / d;
double htemp = Math.Round(R * R - a * a, 15); double htemp = R * R - a * a;
if (htemp == 0) if (Math.Round(htemp, 15) == 0)
{ {
intersections = new Intersection[1]; intersections = new Intersection[1];
intersections[0] = new Intersection(Math.Round(px, 15), Math.Round(py, 15)); intersections[0] = new Intersection(Math.Round(px, 15), Math.Round(py, 15));
@@ -41,7 +41,7 @@ namespace TMI_practicum
else else
{ {
intersections = new Intersection[2]; intersections = new Intersection[2];
double h = Math.Round(Math.Sqrt(htemp), 15); double h = Math.Sqrt(htemp);
intersections[0] = new Intersection(Math.Round(px + h * (c1.Y - Y) / d, 15), Math.Round(py - h * (c1.X - X) / d, 15)); 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)); intersections[1] = new Intersection(Math.Round(px - h * (c1.Y - Y) / d, 15), Math.Round(py + h * (c1.X - X) / d, 15));
} }

View File

@@ -79,9 +79,11 @@ namespace TMI_practicum
solved.Contains(new Intersection(intersection.X, intersection.Y - 10e-15)) solved.Contains(new Intersection(intersection.X, intersection.Y - 10e-15))
) continue; ) continue;
Console.WriteLine(InCircles(circles));
failed = true; failed = true;
Console.WriteLine("Not found: {0}\t{1}", intersection.X, intersection.Y); Console.WriteLine("Not found: {0}\t{1}", intersection.X, intersection.Y);
Console.WriteLine("corrrect"); Console.WriteLine("correct");
foreach (var intersection1 in correctSol) foreach (var intersection1 in correctSol)
{ {
Console.WriteLine("{0}\t{1}", intersection1.X, intersection1.Y); Console.WriteLine("{0}\t{1}", intersection1.X, intersection1.Y);
@@ -203,5 +205,27 @@ namespace TMI_practicum
sw.WriteLine("\r\n{0}", time); sw.WriteLine("\r\n{0}", time);
} }
} }
private static int InCircles(IList<Circle> circles)
{
int count = 0;
foreach (var toCheck in circles)
{
foreach (var circle in circles)
{
if (circle == toCheck) continue;
if (circle.R > toCheck.R && circle.Distance(toCheck) < circle.R &&
circle.FindIntersections(toCheck) == null)
{
count++;
}
}
}
return count;
}
} }
} }

View File

@@ -117,12 +117,6 @@ namespace TMI_practicum
if (intersects == null) return; if (intersects == null) return;
foreach (var intersection in intersects) foreach (var intersection in intersects)
{ {
// if (upper)
// {
// if (intersection.Y < circle.Y) continue;
// }
// else if (intersection.Y > circle.Y) continue;
if (intersections.Contains(intersection)) continue; if (intersections.Contains(intersection)) continue;
events.Add(new Event(Event.EventType.Intersection, intersection.X, circle, intersection.Y, events.Add(new Event(Event.EventType.Intersection, intersection.X, circle, intersection.Y,
new[] {new C5.KeyValuePair<SegmentKey, Circle>(segment, circle), neighbour})); new[] {new C5.KeyValuePair<SegmentKey, Circle>(segment, circle), neighbour}));
@@ -197,7 +191,7 @@ namespace TMI_practicum
{ {
get get
{ {
if (_lastX.Equals(_sweepline)) return _lastY; if (_lastX == _sweepline) return _lastY;
_lastX = _sweepline; _lastX = _sweepline;
_lastY = CalculateY(_circle, Type); _lastY = CalculateY(_circle, Type);
return _lastY; return _lastY;
@@ -218,10 +212,10 @@ namespace TMI_practicum
public int CompareTo(SegmentKey other) public int CompareTo(SegmentKey other)
{ {
if (_identifier.Equals(other._identifier)) return Type.CompareTo(other.Type); if (_identifier == other._identifier) return Type.CompareTo(other.Type);
if (!Y.Equals(other.Y)) return Y.CompareTo(other.Y); if (Y != other.Y) return Y.CompareTo(other.Y);
return Type.Equals(other.Type) ? _identifier.CompareTo(other._identifier) : Type.CompareTo(other.Type); return Type == other.Type ? _identifier.CompareTo(other._identifier) : Type.CompareTo(other.Type);
} }
public override bool Equals(object obj) public override bool Equals(object obj)
@@ -229,7 +223,7 @@ namespace TMI_practicum
if (obj == null || GetType() != obj.GetType()) return false; if (obj == null || GetType() != obj.GetType()) return false;
SegmentKey r = (SegmentKey) obj; SegmentKey r = (SegmentKey) obj;
return _identifier.Equals(r._identifier) && Type.Equals(r.Type); return _identifier == r._identifier && Type == r.Type;
} }
public override int GetHashCode() public override int GetHashCode()
@@ -246,6 +240,7 @@ namespace TMI_practicum
private static double CalculateY(Circle circle, SegmentKey.SegmentType type) private static double CalculateY(Circle circle, SegmentKey.SegmentType type)
{ {
if (_sweepline > circle.X + circle.R || _sweepline < circle.X - circle.R) return circle.Y;
return type == SegmentKey.SegmentType.Upper return type == SegmentKey.SegmentType.Upper
? Math.Round(Math.Sqrt(circle.R * circle.R - Math.Pow(_sweepline - circle.X, 2)) + circle.Y, 14) ? Math.Round(Math.Sqrt(circle.R * circle.R - Math.Pow(_sweepline - circle.X, 2)) + circle.Y, 14)
: Math.Round(-Math.Sqrt(circle.R * circle.R - Math.Pow(_sweepline - circle.X, 2)) + circle.Y, 14); : Math.Round(-Math.Sqrt(circle.R * circle.R - Math.Pow(_sweepline - circle.X, 2)) + circle.Y, 14);