public static Point CalculateCurrentCirclePosition(int secondsBefore, int milisecondsBefore, Circle c) { DateTime now = DateTime.Now; double timeElapsed; if (now.Second != secondsBefore) { timeElapsed = (now.Millisecond + 1000 - milisecondsBefore); } else { timeElapsed = (now.Millisecond - milisecondsBefore); } return c.Position + c.StrengthVector * timeElapsed * speedOfMoving; }
public static Vector CalculateForceVector(Circle c, ICollection<Circle> circles) { Vector resultantForce = new Vector(); foreach(Circle i in circles) { double distance = Circle.CountDistance(i, c); if (repelRange >= distance && distance != 0) { Vector v = new Vector(c.Position.X - i.Position.X, c.Position.Y - i.Position.Y); resultantForce += (v * 1 / distance); // inverserly to distance. } } // System.Diagnostics.Debug.WriteLine("accidental strength "+accidentalStrength); return resultantForce; }
public static Circle CreateVertex(Point position, DrawingState state) { Circle circle = new Circle(position); state.controller.AddVertex(circle); Ellipse ellipse = circle.ellipse; ellipse.MouseDown += (object a, MouseButtonEventArgs b) => { if (state.currentTool == DrawingState.Tool.DRAW_EDGE) { if (state.firstCircle == null) state.firstCircle = circle; else if (state.secondCircle != null) state.firstCircle = circle; else state.secondCircle = circle; } else { state.firstCircle = state.secondCircle = null; } }; //TODO - choose hover effect, do when styling ellipse.MouseEnter += (object o, MouseEventArgs e) => { if (state.currentTool == DrawingState.Tool.DRAW_EDGE) { ellipse.Fill = new SolidColorBrush(Color.FromRgb(0, 0, 0)); } }; ellipse.MouseLeave += (object o, MouseEventArgs e) => { ellipse.Fill = new SolidColorBrush(Color.FromArgb(255, 0, 150, 0)); }; state.canvas.Children.Add(ellipse); return circle; }
public static bool DetectColision(Circle a, Circle b) { var r1 = a.ellipse.Width/2; var r2 = b.ellipse.Width/2; return CountDistance(a, b) < r1 + r2; }
public static double CountDistance(Circle a, Circle b) { return Math.Sqrt((a.Position.X - b.Position.X) * (a.Position.X - b.Position.X) + (a.Position.Y - b.Position.Y) * (a.Position.Y - b.Position.Y)); }
public void RestoreEdge(Circle one, Circle two) { state.firstCircle = one; state.secondCircle = two; LineDrawer.CreateEdge(state); }
public static void UpdateForceVector(Circle c, ICollection<Circle> circles) { c.StrengthVector = CalculateForceVector(c, circles); }
public static void UpdateCurrentCirclePosition(int secondsBefore, int milisecondsBefore, Circle c) { c.Position = CalculateCurrentCirclePosition(secondsBefore, milisecondsBefore, c); }