[英]How to convert x, y, z to longitude, latitude, altitude in Cesium?
Using three.js library I have assembled a design(plant).使用three.js库我已经组装了一个设计(植物)。 That design is contains of so many smaller models which have the reference of position in (x, y, z) from origin (0,0,0).该设计包含许多较小的模型,这些模型具有从原点 (0,0,0) 在 (x, y, z) 中的位置参考。 Attached the sample screenshot in the following link在以下链接中附上了示例屏幕截图
Now I want to load the individual model with its own position into Cesium.现在我想将具有自己位置的单个模型加载到 Cesium 中。 When I try to load the directly converting the position (x, y, z) to (north, east, up) the result is not as expected.当我尝试加载直接将位置 (x, y, z) 转换为 (north, Eastern, up) 时,结果并不如预期。 All the models are scattered.所有的模型都是分散的。
The functionality which I am trying to achieve is, based on some origin (lon, lat, alt) point, I should position the model into cesium with reference of (x, y, z) relative to cesium coordinates (lon, lat, alt)我试图实现的功能是,基于一些原点(lon,lat,alt)点,我应该将模型定位到铯中,参考(x,y,z)相对于铯坐标(lon,lat,alt )
Eg例如
Origin geo-coordinates (ori_lon, ori_lat, ori_alt) => (-106.690647, 36.806761, 0)原点地理坐标 (ori_lon, ori_lat, ori_alt) => (-106.690647, 36.806761, 0)
Model coordinates (m_x, m_y, m_z) => (-150.9, 126.26, 217.7)模型坐标 (m_x, m_y, m_z) => (-150.9, 126.26, 217.7)
Expecting Coordinates for Cesium: (ori_lon + m_x, ori_lat + m_y, ori_alt + m_z)铯的期望坐标:(ori_lon + m_x、ori_lat + m_y、ori_alt + m_z)
or some algorithm to achieve this.或一些算法来实现这一点。
I have tried with the following article to convert the (x, y, z) to the (long, lat, alt) with some origin (long, lat, alt), but no luck: (我已尝试使用以下文章将 (x, y, z) 转换为具有某些来源 (long, lat, alt) 的 (long, lat, alt),但没有成功:(
(x, y, z) coordinates >> geo-coordinates (x, y, z) 坐标 >> 地理坐标
Advice/help to fix the issue.解决问题的建议/帮助。
EDIT : Since search engines appear to be sending folks here looking for Cartesian-to-cartographic conversions, I'll supply an answer to that here.编辑:由于搜索引擎似乎将人们发送到这里寻找笛卡尔到制图的转换,我将在这里提供一个答案。
The Cartographic.fromCartesian
function is the simplest way to perform this conversion. Cartographic.fromCartesian
函数是执行此转换的最简单方法。 Note that it will return a Cartographic
expressed in radians, not degrees.请注意,它将返回以弧度而非度数表示的Cartographic
。 Height is returned in meters.高度以米为单位返回。
var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
console.log(
'lon ' + Cesium.Math.toDegrees(cartographic.longitude) + ', ' +
'lat ' + Cesium.Math.toDegrees(cartographic.latitude) + ', ' +
'alt ' + cartographic.height);
Original Answer : If you read the details of the original question here, the asker was attempting to add coordinates together in LLA space, which is incorrect.原始答案:如果您在此处阅读原始问题的详细信息,则提问者试图在 LLA 空间中将坐标添加在一起,这是不正确的。 My original answer here explains how to convert them both to Cartesian space and add the results there.我在这里的原始答案解释了如何将它们都转换为笛卡尔空间并在那里添加结果。
This can be done with Cesium.Cartesian3.fromDegrees .这可以通过Cesium.Cartesian3.fromDegrees来完成。
var position = Cesium.Cartesian3.fromDegrees(-106.690647, 36.806761, 0);
var offset = new Cesium.Cartesian3(-150.9, 126.26, 217.7);
Cesium.Cartesian3.add(position, offset, position);
Depending on what coordinate frame offset
is in, it may need a rotation to apply to the global Cartesian space.根据坐标系offset
的不同,它可能需要旋转才能应用于全局笛卡尔空间。 For example, if it's East-North-Up, you would use the corresponding function to create and then apply that transformation.例如,如果它是 East-North-Up,您将使用相应的函数来创建并应用该转换。
Cartesian3 to longlat, in case somebody need Cartesian3 到 longlat,以防有人需要
function toDegrees(cartesian3Pos) { let pos = Cesium.Cartographic.fromCartesian(cartesian3Pos) return [pos.longitude / Math.PI * 180, pos.latitude / Math.PI * 180] } console.log(toDegrees({ x: -1681498.1800000381, y: 4576516.394998055, z: 4098410.649998016 })) // [110.17428132202518, 40.23966923800238]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.