/** * Make sure we never move too much, and make sure that if we move too much to add a displacement * so that the movement will be still in our radius. * * @param radius - radius form the flip origin * @param bMaintainMoveDir - Cap movement but do not change the current movement direction * @return Corrected point */ private Vector2D CapMovement(Vector2D point, boolean bMaintainMoveDir) { // Make sure we never ever move too much if (point.distance(mOrigin) > mFlipRadius) { if (bMaintainMoveDir) { // Maintain the direction point = mOrigin.sum(point.sub(mOrigin).normalize().mult(mFlipRadius)); } else { // Change direction if (point.x > (mOrigin.x + mFlipRadius)) point.x = (mOrigin.x + mFlipRadius); else if (point.x < (mOrigin.x - mFlipRadius)) point.x = (mOrigin.x - mFlipRadius); point.y = (float) (Math.sin(Math.acos(Math.abs(point.x - mOrigin.x) / mFlipRadius)) * mFlipRadius); } } return point; }
public boolean pointInSegment(Vector2D point) { return a.distance(point) + b.distance(point) <= a.distance(b) + 0.0001; }