2017-10-18 152 views
-2

假设我们有一个矩形或一个正方形,并且我们知道其角落(四角)的x,y坐标。算法检测一个点何时何地将退出一个矩形区域

另外假设我们知道它的坐标(x,y),它的速度(km/h),它的航向(方向度为0,北向为180,南等等)以及具有这些属性的时间点(以秒为单位的历元时间)。

我们如何计算点将退出矩形的时间点(以秒为单位的时间点)以及出口的坐标(x,y)?

+1

正方形/长方形的两边是否与指南针的方向一致? –

+0

是的,它们是对齐的。 –

+0

欢迎来到StackOverflow。请阅读并遵守帮助文档中的发布准则。 [在主题](http://stackoverflow.com/help/on-topic)和[如何提问](http://stackoverflow.com/help/how-to-ask)适用于此处。球面坐标中的时间和运动是课本和在线记录的主题。 – Prune

回答

1

您需要先找到哪条边相交。使方程沿两个坐标移动并计算第一次相交。

请注意,对于地理坐标,您可能需要更复杂的计算,因为Lat/Lon坐标定义的“矩形”在地球表面上确实是弯曲的梯形。查看this page的“两条路径的交点,给出起点和轴承”一章,以获得旅行时间。

vx = V * Cos(heading + Pi/2) //for y-axis north=0 
vy = V * Sin(heading + Pi/2) 

x = x0 + vx * t 
y = y0 + vy * t 

//potential border positions  
if vx > 0 then 
    ex = x2 
else 
    ex = x1 

if vy > 0 then 
    ey = y2 
else 
    ey = y1 

//check for horizontal/vertical directions 
if vx = 0 then 
return cx = x0, cy = ey, ct = (ey - y0)/vy 

if vy = 0 then 
    return cx = ex, cy = y0, ct = (ex - x0)/vx 


//in general case find times of intersections with horizontal and vertical edge line 
    tx = (ex - x0)/vx 
    ty = (ey - y0)/vy 

//and get intersection for smaller parameter value 
if tx <= ty then 
    return cx = ex, cy = y0 + tx * vy, ct = tx 
else 
    return cx = x0 + ty * vx, cy = ey, ct = ty 
+0

把你的算法放在一个平面上而不是球面上的测试中,x0 = 8.0,y0 = 2.0(我假设这些是点的坐标),t = 1508327031(epcoh秒,其中点具有这些属性),V = 5.0km/h和航向= 90.0(方向度),x1 = 0.0,x2 = 10.0,y1 = 0.0,y2 = 10.0(我还假设这些值是最小/最大X/Y矩形的坐标)我得到的结果是cx = 4.0,cy = 0.0和ct = 0.89这是错误的。 –

+0

@AlJenssen您是否将90度转换为以弧度表示的标题? –

+0

即使我将其转换为弧度,结果也不正确。 –

相关问题