An ellipse defined on the 2D plane is given by the equation:
$$\sqrt{(x-a_1)^2 + (y-b_1)^2} + \sqrt{(x-a_2)^2 + (y-b_2)^2} = c,$$
where $(a_1, b_1), (a_2,b_2)$ are the foci and $c$ is some real number greater or equal than the distance between the foci. The ellipse is the set of points $(x,y)$ that satisfy the equation. Suppose that I have built the foci and $c$ so that the ellipse is bound by the square $-1\le x,y \le 1$. Now, suppose that I want the ellipse to fit into a rectangle enclosed by $y_{min}, y_{max}, x_{min}, x_{max}$. To do this I can map the points $(x,y)$ to new coordinates: $$y' = \frac{(1-y)y_{min} + (1+y)y_{max}}{2}.$$
Note that if $y$ takes the minimum initial value, i.e. -1, then $y'=y_{min}$, as desired. Similarly when $y$ takes the maximum value, i.e. 1. The same happens with $x$: $$x' = \frac{(1-x)x_{min} + (1+x)x_{max}}{2}.$$
My problem is that the components of foci $(a_1, b_1), (a_2,b_2)$ DO NOT transform under the same transformation (i.e. $a_1'\neq \frac{1}{2}[(1-a_1)x_{min} + (1+a_1)x_{max}]$). How do I get the new foci?
I tried pluging $y',x'$ into the ellipse equation, but failed.
It should come as no surprise that the foci don’t transform the same way because, unless the new rectangle is also a square, you’re changing the ellipse’s eccentricity. As Jack D’Aurizio has pointed out in his comment to your question, the focal distance $c$ is related to the half-axis lengths via $b^2=a^2-c^2$, so in general, if you scale the axes differently, the foci are going to shift in a nonlinear fashion. As a simple example, start with a circle, which you can view as an ellipse with coincident foci ($c=0$). If you scale the $x$- and $y$- axes differently, you end up with a proper ellipse ($c>0$). The two foci obviously didn’t transform the same way as the circle itself.
Update:
Unfortunately, the axes of the ellipse also get shifted in unexpected ways, so determining the new foci isn’t quite as simple as mapping the original center and major axis and computing the new focal distance from the above formula.
A straightforward, albeit tedious way to find the foci (and other parameters) of the transformed ellipse is to work with a matrix form equation: $(\mathbf x-\mathbf p)^TQ(\mathbf x-\mathbf p)=1$, where $\mathbf p$ is the center of the ellipse and $Q$ is a matrix of the form $\pmatrix{A&B/2\\B/2&C}$ with positive determinant. The eigenvectors of this matrix give the directions of the ellipse’s axes and the reciprocals of the square roots of its eigenvalues are the semi-axis lengths. Translating the ellipse amounts to replacing $\mathbf p$ by some other point $\mathbf p'$ and obviously doesn’t affect the shape of the ellipse. To obtain the equation of the ellipse scaled by $s_x$ and $s_y$ in the $x$ and $y$ directions, respectively, multiply $Q$ on both sides by the inverse of the scaling matrix $\operatorname{diag}(s_x,s_y)$, which gives $$Q'=\pmatrix{\frac A{s_x^2} & \frac B{2s_xs_y} \\ \frac B{2s_xs_y} & \frac C{s_y^2}}.$$ In your case, $s_x=(x_\text{max}-x_\text{min})/2$ and $s_y=(y_\text{max}-y_\text{min})/2$. Compute the eigenvalues and eigenvectors of this transformed matrix to get the semi-axes of the transformed ellipse, from which you can then find the new foci.