Translates a by a given .
/// <summary> /// This is essentially the same as Lerp but instead the function will ensure that the speed never exceeds maxDistanceDelta. /// Negative values of maxDistanceDelta pushes the vector away from target. /// </summary> public static PointF MoveTowards(this PointF current, PointF target, float maxDistanceDelta) { var dir = target.Sub(current); var magnitude = dir.Length(); if (magnitude <= maxDistanceDelta || magnitude <= float.Epsilon) { return(target); } return(current.Add(dir.Mul(maxDistanceDelta / magnitude))); }
private PointF[] GetFlamePoints(int offsetX, int offsetY) { var center = new PointF(_position.X - offsetX, _position.Y - offsetY); var front = new PointF((float)Math.Cos(_rotation + Math.PI) * ShipSize * 1.5f, (float)Math.Sin(_rotation + Math.PI) * ShipSize * 1.5f); var left = new PointF((float)Math.Cos(_rotation + Theta + 0.3f) * ShipSize, (float)Math.Sin(_rotation + Theta + 0.3f) * ShipSize); var right = new PointF((float)Math.Cos(_rotation - Theta - 0.3f) * ShipSize, (float)Math.Sin(_rotation - Theta - 0.3f) * ShipSize); return new[] { center.Add(front), center.Add(left), center.Add(right) }; }
public Point Move(IField field) { var velocity = 0f; lock(velocityLock) velocity = Velocity; var location = new PointF(Location.X, Location.Y); velocity *= field.Time.TimeStep / field.Time.Interval; var vecV = Direction.Multiply(velocity); var step = field.Time.TimeStep; var endTime = field.Time.Interval + field.Time.TimeStep; var rectangles = field.StaticObjBoundaries; for (var time = 0f; time < endTime; time += step) { location = location.Add(vecV); var curLocRect = new RectangleF(location, Size); foreach (var rect in rectangles) if (curLocRect.IntersectsWith(rect)) { var intersectRect = RectangleF.Intersect(curLocRect, rect);//.Location; var normal = GetNormal(intersectRect, rect); var negDir = Direction.Negate(); Direction = negDir.Reflect(location, normal).Normalize(); vecV = Direction.Multiply(velocity); location = location.Add(vecV); curLocRect = new RectangleF(location, Size); while (curLocRect.IntersectsWith(rect)) { location = location.Add(vecV); curLocRect = new RectangleF(location, Size); } break; } } return location.ToPoint(); }
/// <summary> /// Set Center of a Rectangle /// </summary> /// <param name="r"></param> /// <param name="p"></param> /// <returns></returns> public static RectangleF SetCenter(this RectangleF r, PointF p) { p = p.Add(r.Size.Multiply(-0.5f)); r.Location = p; return r; }
/// <summary> /// Set Anchor position of a Rectangle (No Resize) /// </summary> /// <param name="r">Rectangle</param> /// <param name="a">Anchor Index</param> /// <param name="p">New Position of Anchor</param> /// <returns></returns> public static RectangleF SetAnchor(this RectangleF r, int a, PointF p) { var sz = r.Size; var l = r.Location; switch (a) { case 0: l = p; break; case 1: l = new PointF(p.X - sz.Width, p.Y); break; case 2: l = new PointF(p.X, p.Y - sz.Height); break; case 3: l = new PointF(p.X - sz.Width, p.Y - sz.Height); break; case 4: l = p.Add(sz.Multiply(-0.5f)); break; } return new RectangleF(l, sz); }
/// <summary> /// Center between two points /// </summary> /// <param name="p1"></param> /// <param name="p2"></param> /// <returns></returns> public static PointF Center(PointF p1, PointF p2) => p2.Add(p1).Scale(0.5f);
/// <summary>Translates the <see cref="T:System.Drawing.PointF" /> by the specified <see cref="T:System.Drawing.SizeF" />.</summary> /// <returns>The translated <see cref="T:System.Drawing.PointF" />.</returns> /// <param name="pt">The <see cref="T:System.Drawing.PointF" /> to translate.</param> /// <param name="sz">The <see cref="T:System.Drawing.SizeF" /> that specifies the numbers to add to the x- and y-coordinates of the <see cref="T:System.Drawing.PointF" />.</param> public static PointF operator +(PointF pt, SizeF sz) { return(PointF.Add(pt, sz)); }
public static Rectangle FromCornerSize(PointF TopLeftCorner, PointF Size) { return new Rectangle(new Line(TopLeftCorner, TopLeftCorner.Add(Size))); }
public static Rectangle FromCenterSize(PointF Center, PointF Size) { Size = Size.Divide(2); return new Rectangle(new Line(Center.Subtract(Size), Center.Add(Size))); }