Search code examples
javascriptmathmatrixcoordinatespoints

Calculate coordinates of point in another plan


I need to get x and y of a point in another plan. I'll explain:

- I have a plan where xmin = 0 & xmax = 720 & ymin = 0 & ymax = 894. 
- I have another plan with xmin = -3900 & xmax = 6000 & ymin = -4000 and ymax = 8000.
  • For the first plan the origin (0;0) is on top left.
  • On the second plan the origin is on the middle of the plan (in approximately 433;734 coordinates on the first plan). The top left point is -3900;8000.

What i need to do is to get coordinates of points, set in the second plan, in the first plan. For example if i search coordinates 0;0 of the second plan in the first plan i need to get 433;734 and if i search -3900;8000 i need to get 0;0 in the first plan.

I need to do this in JavaScript I hope you'll understand me well.

Thank you.

EDIT : Thanks you @MBo who work with me and find this solution. The first map is : http://rolux.org/svg/radar.svg and the second is : https://drive.google.com/file/d/0B-zvE86DVcv2MXhVSHZnc01QWm8/view

x_1 = (x_2 + 4000) * 1080 / 10000
y_1 = (8000 - y_2) * 1080 / 12000

Solution

  • In general the simplest mapping is linear.

    To transform coordinates from the first plan to the second one, you need to subtract first origin, multiply by scale coefficient and add the second origin.

    x2 = (x1 - origin1.x) * xsize2 / xsize1 + origin2.x
    

    For reverse transform use inverse coefficient:

    x1 = (x2 - origin2.x) * xsize1 / xsize2 + origin1.x
    

    The same for y-coordinates.

    It is hard to say - whether this approach is applicable to your task because description is still rather tangled...