Object resize by scaling(programming related) I made illustration so the explanation would be easier. 

Problem:
Basically, I want to do the green object resize(from each corner) by dragging it further from P(makes green object larger), getting closer to point P(makes green object smaller). This all needs to be done with scale(sX, sY) SVG transform.
Current solution:
Here's how I do it now, calculate the vector OP distance, so the F point is loose user could drag it anywhere. Next, would be the distance between the OF. To get the scale step, divide the OF/OP. 
I am not sure if this is a correct way to do it, or is there any easier ways? My solution is only working if the OF degree remains same as the OP.
Update
I made a mistake by describing the problem, all previously written problem statement remains. Here is updated visual: 
. 
What changed from the visual perspective is that the user could drag the box from each red corners. The movement is shown with vector PF, if the vector comes closer to point O which means scaling the box smaller. By moving the F distance further from O and P should grow the box. Basically, the OP+PF =OF from old picture.
 A: Judging from the fact that you want to "scale the rectangle based on F's distance from P" this would be my recommendation (Although it's a little unclear to me how you want to scaling mechanics to work):
Get the distance of $F=(x_1,y_1)$ to $P=(x_2,y_2)$, $d$, using the distance formula.
$$d=\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$
Now what you are going to want to do create a scaling constant, $k$, which this can be any value so you're just going to have to play around with it and see what works well. From here you are going to  want to ask yourself
$$\text{is }OF\ge OP\text{ ?}$$
this is basically asking whether $F$ or $P$ is further from the origin by comparing the length of the vectors $\vec{OF}$ and $\vec{OP}$. If the answer to that question is yes, then $F$ is farther from the origin and the square must be enlarged, otherwise $P$ is farther from the origin and the square should be shrunk. Now I having done all this I would make the scale factor as follows
$$S=\begin{cases}
1+\frac{k\cdot d}{OP} &\text{ if }OF\ge OP \\
\frac{k\cdot d}{OP} &\text{ if }OF<OP
\end{cases}$$
Then just call scale(S).
