本文介绍了如何在两个已知点之间生成坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 背景: 我正在使用运输路线,而Google提供的路线点足够远以创建形状。这些是您在Google地图中看到的巴士/火车路线。 我的要求: Google的观点足以创造出直线。然而,我想要每一个点,比如5米。 问题: 所以,说我有两点[拉特,长]: [ - 33.8824219918503,151.206686052582]和[-33.8815434600467,151.206556440037] 给出这两点我可以计算它们之间的距离。我们可以想象这两点之间的假想直线。 如何为每个5米的假想线生成坐标? 解决方案 p> 给定距离和方位的起始点 应用于您的问题: 类Numeric def to_rad self * Math :: PI / 180 end def to_deg self * 180 / Math :: PI end end 包含Math R = 6371.0 道路点(φ1,λ1,θ,d)φ2= asin(sin(φ1)* cos(d / R)+ cos (sin(θ)* sin(d / R)* cos(φ1),cos(d / R)-sin(d / R)* cos(θ) (φ1)* sin(φ2))λ2=(λ2+ 3 * Math :: PI)%(2 * Math :: PI) - Math :: PI# o -180 .. + 180° [φ2,λ2] end φ1,λ1= -33.to_rad,-71.6.to_rad#Valparaísoφ2 ,λ2= 31.4.to_rad,121.8.to_rad#Shanghai d = R * acos(sin(φ1)* sin(φ2)+ cos(φ1)* cos(φ2)* cos(λ2 - λ1 ))θ= atan2(sin(λ2 - λ1)* cos(φ2),cos(φ1)* sin(φ2) - sin(φ1)* cos(φ2)* cos(λ2 - λ1)) 航点=(0..d).step(2000).map {| d |航点(φ1,λ1,θ,d)} 标记= waypoints.map {|φ,λ| #{φ.to_deg},#{λ.to_deg}} .join(|) putshttp://maps.googleapis.com/maps/api/staticmap?size = 640x320& sensor = false& markers =#{markers} 生成Google Static Maps链接每隔2000公里从瓦尔帕莱索到上海的航点: http://maps.googleapis.com/maps/api/staticmap?大小= 640X320&安培;传感器=假安培;标记= -33.0,-71.60000000000002 | -32.54414813683714,-93.02142653011552 | -28.59922979115139,-113.43958859125276 | -21.877555679819015,-131.91586675556778 | -13.305784544363858,-148.5297601858932 | -3.7370081151180683,-163.94988578467394 | 6.094273692291354,-179.03345538133888 | 15.493534924596633,165.33401731030006 | 23.70233917422386,148.3186618914762 | 29.83806632244171,129.34766276764626 Background:I'm working with transport routes and Google provides Route points far apart enough to create 'shapes'. These are the bus/train routes you see in Google Maps.My Requirement:Google's points are far enough to create straight lines. However I want a point every, say, 5 metres.Problem:So, say I have two points [lat,long]:[-33.8824219918503,151.206686052582] and [-33.8815434600467,151.206556440037]Given those two points I can calculate the distance between them. Say it's 1km for the sake of argument.So we can imagine an imaginary straight line in between those two points.How do I generate coordinates for that imaginary line for every, say, 5 metres? 解决方案 Destination point given distance and bearing from start point applied to your problem:class Numeric def to_rad self * Math::PI / 180 end def to_deg self * 180 / Math::PI endendinclude MathR = 6371.0def waypoint(φ1, λ1, θ, d) φ2 = asin( sin(φ1) * cos(d/R) + cos(φ1) * sin(d/R) * cos(θ) ) λ2 = λ1 + atan2( sin(θ) * sin(d/R) * cos(φ1), cos(d/R) - sin(φ1) * sin(φ2) ) λ2 = (λ2 + 3 * Math::PI) % (2 * Math::PI) - Math::PI # normalise to -180..+180° [φ2, λ2]endφ1, λ1 = -33.to_rad, -71.6.to_rad # Valparaísoφ2, λ2 = 31.4.to_rad, 121.8.to_rad # Shanghaid = R * acos( sin(φ1) * sin(φ2) + cos(φ1) * cos(φ2) * cos(λ2 - λ1) )θ = atan2( sin(λ2 - λ1) * cos(φ2), cos(φ1) * sin(φ2) - sin(φ1) * cos(φ2) * cos(λ2 - λ1) )waypoints = (0..d).step(2000).map { |d| waypoint(φ1, λ1, θ, d) }markers = waypoints.map { |φ, λ| "#{φ.to_deg},#{λ.to_deg}" }.join("|")puts "http://maps.googleapis.com/maps/api/staticmap?size=640x320&sensor=false&markers=#{markers}"Generates a Google Static Maps link with the waypoints from Valparaíso to Shanghai every 2,000 km:http://maps.googleapis.com/maps/api/staticmap?size=640x320&sensor=false&markers=-33.0,-71.60000000000002|-32.54414813683714,-93.02142653011552|-28.59922979115139,-113.43958859125276|-21.877555679819015,-131.91586675556778|-13.305784544363858,-148.5297601858932|-3.7370081151180683,-163.94988578467394|6.094273692291354,-179.03345538133888|15.493534924596633,165.33401731030006|23.70233917422386,148.3186618914762|29.83806632244171,129.34766276764626 这篇关于如何在两个已知点之间生成坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-03 06:18