I have a list of coordinates that represent an objects location in a world. I'd like to display these objects as sprites on a top-down 2d map of that world. The image is 600x600.
I need a way to convert from world coordinates to a pixel on the image that would represent their location.
I have a few point and their correlating image locations that I found manually.
World Coordiantes:
- (72, -64)
- (-40, 63)
- (72, -51)
And their respective image pixels:
- (528, 27)
- (37, 468)
- (480, 32)
You can do this using a projective transformation. In homogeneous coordinates, let a world point be denoted by $\mathbf{q} = [x,y,1]^T$ and let an image point be denoted by $\mathbf{p} = [u,v,1]^T$.
The transformation from a world point to an image point can be computed as
$$\mathbf{p} = P \mathbf{q} = K[R|t]\mathbf{q}$$
where $K$ transforms the world point to the image point and $R$ and $T$ rotates and translates the world point before projecting on the images (e.g., if the world is not aligned with the image).
The matrix $K$ is given by $$ K = \begin{bmatrix} sx& 0& cx\\ 0& sy& cy\\ 0& 0& 1 \end{bmatrix},$$ where the parameters $s_x$ nad $s_y$ define the scaling between image points and world points (e.g., pixels per unit) and the parameters $c_x$ and $c_y$ define the offset from the center of the image.
The matrix $[R|t]$ is given by $$ [R|t] = \begin{bmatrix} \cos \theta& -\sin \theta & t_x\\ \sin \theta& \cos \theta & t_y\\ 0& 0& 1 \end{bmatrix}. $$ where $\theta$ is the rotation between the image and world frame and $t$ is the translation between the image and world.
You need to define $s_x, s_y, c_x, c_y, \theta, t_x,$ and $t_y$ based on your problem. Note that if the world frame and image frame are already aligned (or if you don't want to rotate or translate the world before projecting on the image), then $[R|t] = [I|0]$ and $\mathbf{p} = K \mathbf{q}$.
Hope this helps you get started.