# Figure out simple joint formula for sets of vectors?

I have on the left side four pairs of sample values that result in the respective pair of values on the right side.

[640,  480]  => [245, 225]
[800,  600]  => [305, 280]
[1024, 768]  => [380, 360]
[1280, 1024] => [480, 460]


(Each pair on the left side is the width and height, and each pair on the right site represents x and y coordinates)

Is there a joint formula that could take the value on the left side and transform it to the value on the right side? (It doesn't have to be exact, but it should be within -5 to 5 of the sample values on the right side. For example the first sample set could be [240 to 250, 220 to 230])

For an input (left side) I need to find the result (right side). For example 1280 would end up being about 480, and 1024 would end up as about 460.

For the 4th sample I created this formula:

[w, h] => [x, y]

x = (w/2) - (w/2) * 0.75
y = (h/2) - (h/2) * 0.1


That correctly results in

x = (1280/2) - (1280/2) * 0.75 = 640 - 640 * 0.75 = 640 - 160   = 480
y = (1024/2) - (1024/2) * 0.1  = 512 - 512 * 0.1  = 512 - 52.2  = ~460


But that formula doesn't work for the other ones. For example the second sample would result in

x = (800/2) - (800/2) * 0.75 = 400 - 400 * 0.75 = 400 - 300 = 100, should be 305
y = (600/2) - (600/2) * 0.1  = 300 - 300 * 0.1  = 300 - 30  = 270, should be 280


Can anyone help me please? (And sorry for my bad English. I hope I explained it well enough)

PS: The four samples I provided at the top of my post are just samples. I have 45 in total... should I post them all? THanks

Oh and sorry if I asked wrong it's my first question

• So, do I understand correctly that $x$ can only depend on $w$ and $y$ can only depend on $h$? If so, is the question just about individual functions? – T.J. Gaffney Apr 16 '14 at 8:44
• I'm not sure to be honest. I made that dependency because I thought it would be easier, but it doesn't have to be dependant. I just need to figure out a function that "converts" the left side to the values on the right side. – A. D. Apr 16 '14 at 8:49
• Are there any restrictions on the type of function? Should it be continuous? Smooth? Linear? Etc?? – T.J. Gaffney Apr 16 '14 at 9:05
• I have no idea, I guess there are no restrictions. It's just for a little project of mine where I have different computer screen resolutions (left side) and a point for each (right side) and I need to figure out what that point's x, y coords are, based on the given resolution. So for example a 1280 x 1024 screen resolution, or [1280, 1024], would give me the coordinates [480, 460]. – A. D. Apr 16 '14 at 9:11
• You can just do a piecewise function then. Or "if" statements in computer language. e.g. Your function for $x$ would be 245 if 640, 305 if 800, 380 if 1024, 480 if 1280, and 0 for all other numbers. – T.J. Gaffney Apr 16 '14 at 9:30

If you want a linear solution, you need a matrix $X$ such that $AX=B$, being $A=\begin{bmatrix} 640 & 480 \\ 800 & 600 \\ 1024 & 768 \\ 1280 & 1024 \end{bmatrix}$ and $B=\begin{bmatrix} 245 & 225 \\ 305 & 280 \\ 380 & 360 \\ 480 & 460 \end{bmatrix}$.
Then, you can search a least squares solution: solving $A^TAX=A^TB$ we obtain $X\approx \begin{bmatrix} 0.398670 & 0.226749 \\ - 0.029587 & 0.165782 \end{bmatrix}$.
Try this transformation: $$\begin{bmatrix} x \\ y \end{bmatrix}=\begin{bmatrix} 0.398670 & 0.226749 \\ - 0.029587 & 0.165782 \end{bmatrix}^T\begin{bmatrix} w \\ h \end{bmatrix}$$