在D3地理投影中构造两个旋转? [英] Compose two rotations in D3 geo projection?

查看:303
本文介绍了在D3地理投影中构造两个旋转?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用D3地理正交投影来创建一个互动地球仪,基于我发现的所有伟大的例子。

Having fun with D3 geo orthographic projection to build an interactive globe, based on all the great examples I found.

您可以在 http:/ /bl.ocks.org/patricksurry/5721459

我想让用户像轨迹球一样操作地球仪( http://www.opengl.org/wiki/Trackball )。我从Mike的一个例子开始( http://mbostock.github.io/d3 /talk/20111018/azimuthal.html ),并稍微改进以使用画布坐标并在轨迹球坐标中表示鼠标位置(即围绕画布水平和垂直轴旋转),以便固定的鼠标移动给出更多的旋转靠近地球的边缘(如果你使用上面解释过的hyberbolic扩展,则在地球外面工作),而不是Mike的一个对应。

I want the user to manipulate the globe like a trackball (http://www.opengl.org/wiki/Trackball). I started with one of Mike's examples (http://mbostock.github.io/d3/talk/20111018/azimuthal.html), and improved slightly to use canvas coordinates and express the mouse locations in 'trackball coordinates' (i.e. rotation around canvas horizontal and vertical axes) so that a fixed mouse movement gives more rotation near the edges of the globe (and works outside the globe if you use the hyberbolic extension explained above), rather than Mike's one:one correspondence.

地球从未旋转的位置(北极垂直)开始,但是当地球已经旋转(操纵示例,使北极朝向页面)时,轨迹球控制变得不直观,因为你不能简单地表达将轨迹球坐标的变化作为d3.geo.rotate lat / lon坐标中的增量。 D3的3轴旋转包括应用经度旋转(绕北极旋转),然后进行纬度旋转(绕画布平面中的水平轴旋转),然后进行偏转旋转(围绕垂直于平面的轴旋转) - 请参阅 http://bl.ocks.org/mbostock/4282586

It works nicely when the globe starts at an unrotated position (north pole vertical), but when the globe is already rotated (manipulate the example so the north pole is facing out of the page) then the trackball controls become non-intuitive because you can't simply express a change in trackball coordinates as a delta in the d3.geo.rotate lat/lon coordinates. D3's 3-axis rotation involves applying a longitude rotation (spin around north pole), then a latitude rotation (spin around a horizontal axis in the canvas plane), and then a 'yaw' rotation (spin around an axis perpendicular to the plane) - see http://bl.ocks.org/mbostock/4282586.

我想我需要一个方法来组成我的两个旋转矩阵(一个当前在投影,一个新的旋转轨迹球轻微),但我看不到在D3中做到这一点的方法,除了挖掘源代码( https ://github.com/mbostock/d3/blob/master/src/geo/rotation.js ),并尝试用数学来定义旋转矩阵。代码看起来很优雅,但没有注释,我不确定是否可以用正交投影实例正确地解释闭包。

I guess what I need is a method for composing my two rotation matrices (the one currently in the projection, with a new one to rotate the trackball slightly), but I can't see a way to do that in D3, other than digging into the source (https://github.com/mbostock/d3/blob/master/src/geo/rotation.js) and trying to do the math to define the rotation matrix. The code looks elegant but comment-free and I'm not sure I can correctly decipher the closures with the orthographic projection instance.

最后一点,如果有人知道

On the last point, if someone knows the rotation matrix form of d3.geo.projection that would probably solve my problem too.

有任何想法吗?

推荐答案

有一个替代的解决方案patricksurry的答案,通过使用四元数表示,灵感来自 Jason Davies 。我也,认为D3会已经支持这种组合本身!并希望Jason Davies发布他的代码...

There is an alternative solution to patricksurry's answer, by using quaternion representations, as inspired by Jason Davies. I, too, thought D3 would've already supported this composition natively! And hoped Jason Davies posted his code...

花点时间来计算数学。演示在这里上传,试图解释数学。 http://bl.ocks.org/ivyywang/7c94cb5a3accd9913263

Took sometime to figure out the math. A demo is uploaded here, with an attempt to explain the math too. http://bl.ocks.org/ivyywang/7c94cb5a3accd9913263

有了我有限的数学知识,我认为,Euler的四元数的优势之一是能够反复多次旋转,而不必担心坐标参考。所以它总是工作,无论你的北极面临什么,无论你有多少个旋转。 (有人请纠正我,如果我错了)。

With my limited math knowledge, I think, one of the advantages quaternion over Euler is the ability to compound multiple rotations over and over, without worrying about coordinate references. So it would always work, no matter where your north pole faces, and no matter how many rotations you'll have. (Someone please correct me, if I got this wrong).

这篇关于在D3地理投影中构造两个旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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