简体   繁体   English

Cesium JS获取弧点数的最佳方法

[英]Cesium JS best way to get an array of points for an arc

What is the neatest (code design) and most per-formant way of getting an array of points for an arc (polyline), for the purpose of animating using Cesium's timer/clock. 为了使用Cesium的定时器/时钟进行动画制作的目的,为弧(折线)获取点阵列的最新(代码设计)和最常规的方法是什么。

Variable inputs include (start/end location), height (highest point) from earth's surface and number of points for drawing. 可变输入包括(起始/结束位置),地球表面的高度(最高点)和绘图点数。

I'm currently using a polyline collection, so the answer should describe how to generate the points for existing polylines or convert to a different approach. 我目前正在使用折线集合,因此答案应该描述如何为现有折线生成点或转换为不同的方法。

I would also need the arc (color) to fadeIn or fadeOut to opacity 0. 我还需要弧(颜色)fadeIn或fadeOut到不透明度0。

Multiple arcs may be added or removed from the collection per second. 可以每秒从集合中添加或移除多个弧。 Each arc will have different start and end points 每个弧将具有不同的起点和终点

The start and end location should have height 0 (touching the earth). 起点和终点位置应为高度0(接触地球)。

(For Cesium version b26) (适用于铯版本b26)

Just to be sure I understand your question, you have a bunch of polylines on a map and you want to get a bunch of data points along the line for use in animating the something along the path. 为了确保我理解你的问题,你在地图上有一堆折线,你想在线上获得一堆数据点,用于动画沿路径的东西。 I'll also assume you want geodesic lines/arcs for the polylines rather than the straight lines that are normally drawn on Mercator maps as geodesic lines actually follow the spatially accurate path of the polyline ie the same path a plane would take. 我还假设您想要折线的测地线/弧而不是通常在墨卡托地图上绘制的直线,因为测地线实际上遵循折线的空间精确路径,即平面将采用的相同路径。 If this is the case then take a look at this blog post: http://alastaira.wordpress.com/2011/06/27/geodesics-on-bing-maps-v7/ This post describes how to calculate data points along the geodesic path of a polyline. 如果是这种情况,那么请看一下这篇博文: http//alastaira.wordpress.com/2011/06/27/geodesics-on-bing-maps-v7/这篇文章描述了如何计算沿着折线的测地路径。

CesiumJS includes several spline functions that can be used. CesiumJS包含几个可以使用的样条函数。 One of the easier ones to use that an accomplish what you want with just three points is the Catmull-Rom Spline: Catmull-Rom Spline是一个比较容易实现你想要的只有三点的人:

http://cesiumjs.org/Cesium/Build/Documentation/CatmullRomSpline.html http://cesiumjs.org/Cesium/Build/Documentation/CatmullRomSpline.html

You will need to produce a middle point. 你需要产生一个中间点。 To do this you can take a mean of the lat/lon coordinates and add a large height. 为此,您可以采用纬度/经度坐标的平均值并添加较大的高度。 Because of the spline used and the low number of points, it does end up looking a little egg shaped. 由于使用了样条曲线和点数较少,它最终看起来像一个小蛋形。 The benefit to this is that you can ask the spline object for an arbitrary number of points, so the arc can be as smooth as you want. 这样做的好处是你可以向样条线对象询问任意数量的点,因此弧可以像你想要的那样平滑。 Just don't forget to add the first and last points to the array returned by the spline as those are omitted. 只是不要忘记将第一个和最后一个点添加到样条曲线返回的数组中,因为它们被省略了。

There are other types of splines, but I found the Catmull-Rom spline the easiest to use. 还有其他类型的样条曲线,但我发现Catmull-Rom样条曲线最容易使用。 You can search the CesiumJS documentation for some of the other included splines. 您可以在CesiumJS文档中搜索其他一些包含的样条线。

I've been looking into the same thing (minus the time aspect) and I found Cesium.EllipsoidGeodesic(start, end, ellipsoid), which allows you to get points at fractions of the path. 我一直在寻找相同的东西(减去时间方面),我发现了Cesium.EllipsoidGeodesic(开始,结束,椭球),它允许你获得路径分数的点数。 It seems to me that you can choose the fraction based on the distance and calculate regular points using the result. 在我看来,你可以根据距离选择分数,并使用结果计算常规点。

https://cesiumjs.org/Cesium/Build/Documentation/EllipsoidGeodesic.html https://cesiumjs.org/Cesium/Build/Documentation/EllipsoidGeodesic.html

I haven't tried it yet, but it's on my list of things to do. 我还没有尝试过,但这是我要做的事情清单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM