internal GamePoint[] SetMove(float distance, float angleRotate) { var angleRad = (angleRotate * Math.PI) / 180; CenterPolygonAbsolute = new GamePoint(-Math.Sin(angleRad) * distance + CenterPolygonAbsolute.X , Math.Cos(angleRad) * distance + CenterPolygonAbsolute.Y); return(GetDrawPoints()); }
private GamePoint[] RotatePolygon() { GamePoint[] rotateGamePoints = new GamePoint[Points.Length]; for (int i = 0; i < Points.Length; i++) { rotateGamePoints[i] = RotatePoint(Points[i]); } return(rotateGamePoints); }
internal GamePoint RotatePoint(GamePoint point) { var angleRad = (AngleRotate * Math.PI) / 180; var x = (point.X) * Math.Cos(angleRad) - (point.Y) * Math.Sin(angleRad); var y = (point.X) * Math.Sin(angleRad) + (point.Y) * Math.Cos(angleRad); return(new GamePoint((float)x, (float)y)); }
public GamePoint[] GetDrawPoints() { GamePoint[] newGamePoints = new GamePoint[Points.Length]; var rotatePoints = RotatePolygon(); for (int i = 0; i < newGamePoints.Length; i++) { newGamePoints[i] = rotatePoints[i] * Scale + CenterPolygonAbsolute; } return(newGamePoints); }
private GamePolygon(GamePoint[] gamePoints, GamePoint centerPolygon, float angleGradus, GamePoint creationGamePoint, bool offcetCenter = false) { if (gamePoints.Length < 3) { throw new ArgumentException("Полигон объекта не может иметь менее трех вершин."); } GamePoint[] polygonGamePoint = new GamePoint[gamePoints.Length]; for (int i = 0; i < gamePoints.Length; i++) { polygonGamePoint[i] = gamePoints[i] - centerPolygon; } Points = polygonGamePoint; CenterPolygonAbsolute = creationGamePoint; OffcetCenter = offcetCenter; CenterPolygonRelative = centerPolygon; AngleRotate = angleGradus; SetMaxRadius(CenterPolygonRelative); }
public float DistanceTo(GamePoint gamePoint) { return((float)Math.Sqrt((this.X - gamePoint.X) * (this.X - gamePoint.X) + (this.Y - gamePoint.Y) * (this.Y - gamePoint.Y))); }
//Методы возвращают расстояние между двумя точками. public static float Distance(GamePoint gamePointA, GamePoint gamePointB) { return((float)Math.Sqrt((gamePointA.X - gamePointB.X) * (gamePointA.X - gamePointB.X) + (gamePointA.Y - gamePointB.Y) * (gamePointA.Y - gamePointB.Y))); }
public static GamePolygon GetPollygonOffcetCenter(GamePoint[] gamePoints, float angleGradus, GamePoint creationGamePoint) { GamePoint centerPolygon = GetOffcetCenterPolygon(gamePoints); return(new GamePolygon(gamePoints, centerPolygon, angleGradus, creationGamePoint, true)); }
public static GamePolygon GetPolygon(GamePoint[] points, float angleRotationGradus, GamePoint creationGamePoint) { GamePoint centerPolygon = GetCenterPolygon(points); return(new GamePolygon(points, centerPolygon, angleRotationGradus, creationGamePoint)); }
private void SetMaxRadius(GamePoint centerPolygon) { MaxRadiusObject = (float)Points.Select(n => n * Scale).Max(n => n.DistanceTo(centerPolygon)); }