撰写的D3地理投影两个旋转?地理、两个

2023-09-08 01:03:41 作者:亞麻色的讪笑

获得乐趣与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

You can see my simple mockup at http://bl.ocks.org/patricksurry/5721459

我希望用户操纵像轨迹球地球( http://www.opengl.org/维基/轨迹球)。我开始与麦克的例子之一( http://mbostock.github.io/d3 /talk/20111018/azimuthal.html 的),并略有改善使用画布坐标和前preSS在'轨迹球坐标鼠标位置(即围绕帆布水平和垂直轴),以便旋转固定鼠标运动让更多的旋转靠近地球的边缘(如果你使用的双曲扩展上面解释地球以外的工作),而不是迈克的之一:一一对应

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.

有很好地工作,当在地球开始于一个未旋转位置(北极垂直),但是当在地球已经转动(操纵所以北极面向外的页面的例子)然后轨迹球控制成为非直观因为你不能简单地EX preSS轨迹球改变坐标作为d3.geo.rotate纬度/经度坐标的增量。 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 /主/ src目录/地理/ rotation.js ),并试图做数学来定义旋转矩阵。在code相优雅,但自由评论,我不知道我能正确解密封闭的正投影实例。

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.

在最后一点,如果有人知道d3.geo.projection的旋转矩阵形式,可能会解决我的问题了。

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

任何想法?

推荐答案

还有一个另外的解决方案,以patricksurry的回答,用四元数再presentations,作为灵感的杰森·戴维斯。我也认为D3就已经支持了这一成分本身!并希望杰森·戴维斯发布了code ...

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/ivy$c$cs/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/ivycodes/7c94cb5a3accd9913263

使用我有限的数学知识,我认为,优点四元数在欧拉之一就是一遍又一遍地复合多次旋转,而不用担心坐标参考的能力。因此,这将总是工作,无论在哪里你的北极脸,不管有多少转,你就会有。 (有人请纠正我,如果我得到这个错误的)。

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).