I am tyring to map the location of a POINT from its postion in a source RECTto a new realitve postion in a destination RECT of another size and /or position.
Nothing I have tried even comes close. Does anynone know a simple mapping alogrithim?
Liz
Printable View
I am tyring to map the location of a POINT from its postion in a source RECTto a new realitve postion in a destination RECT of another size and /or position.
Nothing I have tried even comes close. Does anynone know a simple mapping alogrithim?
Liz
I am appending my post with my most recent try. Seems to work if the source rect is greater than the destination rect, but not in any other case:
void MapPt(POINT *pt,RECT src,RECT dst)
{
float w1 = src.right - src.left,
h1 = src.bottom - src.top,
w2 = dst.right - dst.left,
h2 = dst.bottom - dst.top,
x = pt->x,
y = pt->y,
xr,yr,xx,yy;
//the ratios
xr = w2/w1;
yr = h2/h1;
//scale the point
x = x*xr;
y = y*yr;
//Zeroed pos
xx = ((dst.left - src.left)*xr) + x;
yy = ((dst.top - src.top)*yr) + y;
pt->x = xx + dst.left;
pt->y = yy + dst.top;
}
Are there any suggestions?
Liz