public Coordonnees GetCenter() { Coordonnees topLeft = GetTopLeft(), bottomRight = GetBottomRight(); ZZCoordinate centerOfSegment = ZZMath.GetCenterOfSegment((ZZCoordinate)topLeft, (ZZCoordinate)bottomRight); return(new Coordonnees(centerOfSegment.Y, centerOfSegment.X)); }
public double GetPerimeter() { double perimeter = 0; for (int i = 0; i < NbPoints - 1; i++) { perimeter += ZZMath.GetDistance((ZZCoordinate)Coordonnees[i], (ZZCoordinate)Coordonnees[i + 1]); } return(perimeter); }
public bool IsPointInside(Coordonnees toCheck) { if (IsValid()) { double sumAngle = 0; for (int i = 1; i <= NbPoints; i++) { ZZCoordinate previousPoint = (ZZCoordinate)Coordonnees[i - 1], anglePoint = (ZZCoordinate)toCheck, nextPoint = (ZZCoordinate)Coordonnees[i % NbPoints]; double alpha = ZZMath.AngleFrom3Points(previousPoint, anglePoint, nextPoint); double dx = anglePoint.X - previousPoint.X, dy = anglePoint.Y - previousPoint.Y; int sign = 1; if (dx == 0) // Vertical line { if (dy > 0) // The line goes upward { if (nextPoint.X > previousPoint.X) { sign = -1; } } else // The line goes downward { if (nextPoint.X < previousPoint.X) { sign = -1; } } } else { double m = dy / dx, p = previousPoint.Y - m * previousPoint.X; double slopeAngle = ZZMath.SlopeAngle(previousPoint, anglePoint); if (slopeAngle < 90 || slopeAngle > 270) // The point needs to be below the line { if (nextPoint.Y < m * nextPoint.Y + p) { sign = -1; } } else // The point needs to be above the line { if (nextPoint.Y > m * nextPoint.Y + p) { sign = -1; } } } sumAngle += sign * alpha; } Console.WriteLine(sumAngle); return(sumAngle == 360); // To be inside, the total of the angles needs to equal 360 } return(false); }
public bool IsPointInside(Coordonnees toCheck) { if (IsValid()) { double sumAngle = 0; for (int i = 1; i <= NbPoints; i++) { ZZCoordinate previousPoint = (ZZCoordinate)Coordonnees[i - 1], anglePoint = (ZZCoordinate)toCheck, nextPoint = (ZZCoordinate)Coordonnees[i % NbPoints]; double alpha = ZZMath.AngleFrom3Points(previousPoint, anglePoint, nextPoint); double dx = anglePoint.X - previousPoint.X, dy = anglePoint.Y - previousPoint.Y; int sign = 1; if (dx == 0) // Vertical line { if (dy > 0) // The line goes upward { if (nextPoint.X > previousPoint.X) { sign = -1; } } else // The line goes downward { if (nextPoint.X < previousPoint.X) { sign = -1; } } } else { double m = dy / dx, p = previousPoint.Y - m * previousPoint.X; double slopeAngle = ZZMath.SlopeAngle(anglePoint, previousPoint); double fx = m * nextPoint.X + p; if (slopeAngle < 90 || slopeAngle > 270) // The point needs to be below the line { if (nextPoint.Y > fx) { sign = -1; } } else // The point needs to be above the line { if (nextPoint.Y < fx) { sign = -1; } } } sumAngle += sign * alpha; } return((sumAngle > 359.9 && sumAngle < 360.1) || (sumAngle < -359.9 && sumAngle > -360.1)); // To be inside, the total of the angles needs to be above 359.9 or below 359.9, depending on the rotation sense made when creating the polygon (basicly == 360 but double precision doesn't always makes it work) } return(false); }
public override bool IsPointClose(Coordonnees toCheck, double precision) { for (int i = 0; i < Coordonnees.Count() - 1; i++) { if (ZZMath.GetDistancePointToLine((ZZCoordinate)Coordonnees[i], (ZZCoordinate)Coordonnees[i + 1], (ZZCoordinate)toCheck) < precision) { return(true); } } return(false); }
private bool IsValid() { if (NbPoints >= 3) // Is at least a triangle, 3 coordinates { for (int i = 0; i < NbPoints; i++) { ZZCoordinate previousPoint = (ZZCoordinate)Coordonnees[ZZFunctions.nmod(i - 1, NbPoints)], anglePoint = (ZZCoordinate)Coordonnees[i], nextPoint = (ZZCoordinate)Coordonnees[(i + 1) % NbPoints]; double alpha = ZZMath.AngleFrom3Points(previousPoint, anglePoint, nextPoint); if (alpha == 0) { return(false); // The angle formed by the 3 points isn't 0 degrees } } return(true); } return(false); }
public Polygon Extend(double extentionSize) { if (IsValid()) { List <Coordonnees> newCoordCollection = new List <Coordonnees>(); for (int i = 0; i < NbPoints; i++) { ZZCoordinate previousPoint = (ZZCoordinate)Coordonnees[ZZFunctions.nmod(i - 1, NbPoints)], anglePoint = (ZZCoordinate)Coordonnees[i], nextPoint = (ZZCoordinate)Coordonnees[(i + 1) % NbPoints]; double alpha = ZZMath.AngleFrom3Points(previousPoint, anglePoint, nextPoint), beta = (180 - alpha) / 2.0; double slopeAngle = ZZMath.SlopeAngle(previousPoint, anglePoint) + beta; double distanceToAdd = extentionSize / Math.Cos(ZZMath.ToRadians(beta)); double newX = anglePoint.X + distanceToAdd * Math.Cos(ZZMath.ToRadians(slopeAngle)); double newY = anglePoint.Y + distanceToAdd * Math.Sin(ZZMath.ToRadians(slopeAngle)); newCoordCollection.Add(new Coordonnees(newX, newY)); } return(new Polygon(newCoordCollection, BackgroundColor, BorderColor, Oppacity)); } return(this); }
/* * public bool IsPointClose_BoundingBox(Coordonnees toCheck, double precision) * { * if (IsValid()) { * double max_X = Coordonnees[0].Latitude, max_Y = Coordonnees[0].Longitude, min_X = Coordonnees[0].Latitude, min_Y = Coordonnees[0].Longitude; * * for (int i = 1; i < NbPoints; i++) { * if (Coordonnees[i].Latitude > max_X) max_X = Coordonnees[i].Latitude; * else if (Coordonnees[i].Latitude < min_X) min_X = Coordonnees[i].Latitude; * if (Coordonnees[i].Longitude > max_Y) max_Y = Coordonnees[i].Longitude; * else if (Coordonnees[i].Longitude < min_Y) min_Y = Coordonnees[i].Longitude; * } * * if (toCheck.Latitude > min_X - precision && toCheck.Latitude < max_X + precision) { * if (toCheck.Longitude > min_Y - precision && toCheck.Longitude < max_Y + precision) { * return true; * } * } * } * return false; * } */ public override bool IsPointClose(Coordonnees toCheck, double precision) { if (IsValid()) { // return Extend(precision).IsPointInside(toCheck); // Or, more precise: if (!IsPointInside(toCheck)) { for (int i = 0; i < NbPoints; i++) { if (ZZMath.GetDistancePointToLine((ZZCoordinate)Coordonnees[i], (ZZCoordinate)Coordonnees[(i + 1) % NbPoints], (ZZCoordinate)toCheck) < precision) { return(true); } } } else { return(true); } } return(false); }
public override bool IsPointClose(Coordonnees toCheck, double precision) { return(ZZMath.GetDistance((ZZCoordinate)toCheck, (ZZCoordinate)this) < precision); }