将lat / lng坐标转换为给定旋转地图上的像素 [英] Conversion of lat/lng coordinates to pixels on a given rotated map

查看:179
本文介绍了将lat / lng坐标转换为给定旋转地图上的像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将lat / lng坐标转换为旋转的地图(div)上的像素?



扭曲是地图不指向北方,但是倾斜10度...我的高中数学失败了我!



我发现了一些其他问题,向北的地图转换
指向此处



地图是伦敦地点的3 * 3公里地图。 p>

我正在使用javascript,但任何语言都可以: - )

解决方案

p>你有两张地图。在纬度和经度上测量的现实,以及您绘制的地图(我假设)像素。你需要从一个变换到另一个。
使用向量数学来做到这一点,分三个步骤。



1。)找到原始矢量,从您的原点到您要映射的点。



 让O =< Ox,Oy>; 
(原产地在纬度和长的地图)。

let M =< Mx,My> ;;
(您要转换为绘制地图上的像素的纬度/长度)

let V:= M - O =< Mx - Ox,My - Oy> ;
(这是从原点到要转换的点的向量)

As一个矢量,它包含两个数学量,方向和幅度。
我们需要将这两个数量从我们的纬度经度坐标系变换到我们的新像素坐标系。



2。)第一个比例。



比例是一个倍数,找出它是什么,并乘以你的矢量通过它。基本上是每纬度/长度多少个像素的倍数。

 让c =我们的缩放倍数。 

缩放与我们的矢量乘以我们的标量一样简单。

cV =< cVx,cVy> ;;



3)然后旋转



旋转是一个三角函数。旋转矢量的
X等于sin(t)| V |并且旋转矢量的
Y等于cos(t)| V |其中t是我们的旋转量(度或弧度,取决于您定义cos /正弦函数的方式。



注意:Scale和Rotate是线性函数,这意味着它不你所做的这个顺序你可以按比例旋转或旋转,然后缩放,它的答案也是一样的。



立即执行所有操作将如下所示:



矢量符号:



  let O:= origin 
let M:=要映射的点
let R(V,t):=将矢量V旋转t的函数
let c:=或缩放或缩放倍数
(或R,C是线性R(c(MO),t));
(b)b
$ b P = c * R(MO,t)



有序对符号:



  let O:=< Ox,Oy> 

let M:=< Mx,My>

let R(V,t)=& (t)*((Mx-Ox)^ 2 +(My-Oy)^ 2)^ $ 5
sin(t)*((Mx-Ox)^ 2 + ^ .5>

注意:| M - O | =((Mx-Ox)^ 2 +(My - Oy)^ 2)^。5

求解P.

< Px,Py> =< c * cos(t)*((Mx-Ox)^ 2 +(My-Oy)^ 2)^ $ 5
c * sin(t)*((Mx-Ox) )^ 2)^。5>


How do I convert lat/lng coordinates to pixels on a rotated map (a div)?

The twist is that the map does not point towards north, but is tilted 10 degrees... and my high school math is failing me!

I've found a couple of other questions that does the conversion on a north-facing map which points to here.

I am however not complete sure how to do it when the map is rotated.

The map is a 3*3km map of a location in London.

I'm using javascript, but any language will do :-)

解决方案

You have two maps. Reality measured in lat and longitude, and the map you are drawing measured in (I presume) pixels. You need to transform from one to the other. Do this with vector math and do it in three steps.

1.) Find your original vector going from your origin to the point you want to map.

let O = <Ox, Oy>; 
(the origin in lat and long of your map).

let M = <Mx, My>; 
(the point in lat/long that you want to convert to a pixel on your drawn map)

let V := M - O = <Mx - Ox, My - Oy>; 
(This is a vector from origin to the point you want to convert.)

As a vector it contains two mathematical quantities, direction and magnitude. We need to transform both of these quantities from our lat longitude coord system to our new pixel coordinate system.

2.) First Scale.

Scale is a multiple, figure out what it is and multiply your vector by it. Basic its a multiple of how many pixels per degree of lat/long.

let c = our 'zoom' multiple. 

Scaling is as easy as multiplying our vector by our scalar.

cV = <cVx, cVy>;

3.) then Rotate

Rotation is a trigonometric function. X of the rotated vector is equal to sin(t)|V| and Y of the rotated vector is equal to cos(t)|V| where t is our rotation amount in (degrees or radians depending on how you cos/sine functions are defined.

Note : Scale and Rotate are linear functions. That means it doesn't matter the order you do this in scale the rotate or rotate then scale, its the same answer.

Doing it all at once would look like this :

Vector notation :

let O := the origin 
let M := the point you want to map. 
let R(V,t) := a function to rotate vector V by t. 
let c := or zoom or scale multiple. 

solve for P.

P = c * R(M-O, t). (Or since R and c are linear R(c(M-O), t);  )

Ordered Pair notation :

let O := <Ox, Oy>

let M := <Mx, My>

let R(V,t) = < cos(t) * ((Mx - Ox)^2 + (My - Oy)^2)^.5
               sin(t) * ((Mx - Ox)^2 + (My - Oy)^2)^.5 >

Note : |M - O| = ((Mx - Ox)^2 + (My - Oy)^2)^.5

solve for P.

<Px, Py> = < c * cos(t) * ((Mx - Ox)^2 + (My - Oy)^2)^.5
             c*  sin(t) * ((Mx - Ox)^2 + (My - Oy)^2)^.5 >

这篇关于将lat / lng坐标转换为给定旋转地图上的像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆