我一直在尝试多种功能,包括2D功能,试图让它有点工作,但没有运气......
我在地球上有两个latlng端点的线段,我想知道这两条线是否相交以及在哪里。
我正在使用这个,一个物理专业的人说应该为二维飞机做这个工作,但事实并非如此。对于交叉
,它总是返回true[code] function intersectPoint($ line1start,$ line1end,$ line2start,$ line2end) //($ p0_x,$ p0_y,$ p1_x,$ p1_y,$ p2_x,$ p2_y,$ p3_x,$ p3_y) { $ p0_x = $ line1start ['lat']; $ p0_y = $ line1start ['lng']; $ p1_x = $ line1end ['lat']; $ p1_y = $ line1end ['lng']; $ p2_x = $ line2start ['lat']; $ p2_y = $ line2start ['lng']; $ p3_x = $ line1end ['lat']; $ p3_y = $ line1end ['lng'];
$s1_x = (double) $p1_x - (double) $p0_x;
$s1_y = (double) $p1_y - (double) $p0_y;
// s1_x = p1_x - p0_x; // s1_y = p1_y - p0_y; $ s2_x =(double)$ p3_x - (double)$ p2_x; $ s2_y =(double)$ p3_y - (double)$ p2_y; $ s3_x =(double)$ p0_x - (double)$ p2_x; $ s3_y =(double)$ p0_y - (double)$ p2_y; // s2_x = p3_x - p2_x; // s2_y = p3_y - p2_y;
$s = (double) ((double)(-$s1_y * $s3_x + $s1_x * $s3_y) / (double) (-$s2_x * $s1_y + $s1_x * $s2_y));
$t = (double) ((double)( $s2_x * $s3_y - $s2_y * $s3_x) / (double) (-$s2_x * $s1_y + $s1_x * $s2_y));
// s =(-s1_y *(p0_x-p2_x)+ s1_x *(p0_y-p2_y))/(-s2_x * s1_y + s1_x * s2_y); // t =(s2_x *(p0_y - p2_y) - s2_y *(p0_x - p2_x))/(-s2_x * s1_y + s1_x * s2_y);
if ($s >= 0 && $s <= 1 && $t >= 0 && $t <= 1)
{
AppCommUtility::echof(" FUNC RETURNED TRUE $s >= 0 && $s <= 1 && $t >= 0 && $t <= 1");
// Collision detected
return array(
'lat' => $p0_x + ($t * $s1_x),
'lng' => $p0_y + ($t * $s1_y)
);
}
return null; // No collision
} [/代码]
答案 0 :(得分:0)