public static Vector2 GetPositionWithinCircle(float circleRadius) { float distThing = 1000000000.0f; float sqrThing = circleRadius * circleRadius; float xPos; float yPos; do { xPos = Ross_Utils.GetRandBetween(-circleRadius, circleRadius); yPos = Ross_Utils.GetRandBetween(-circleRadius, circleRadius); distThing = Ross_Utils.GetSqrDistance(new Vector2(0, 0), new Vector2(xPos, yPos)); }while(distThing > sqrThing); return(new Vector2(xPos, yPos)); }
public static int GetNearestThing(Vector2 headPos, Vector2[] positionArray, int numItems) { float nearestDistanceSqr = -1.0f; int nearestItem = -1; for (int i = 0; i < numItems; i++) { float sqrDist = Ross_Utils.GetSqrDistance(headPos, positionArray[i]); if ((nearestItem == -1) || (sqrDist < nearestDistanceSqr)) { nearestItem = i; nearestDistanceSqr = sqrDist; } } return(nearestItem); }