1

これをある程度機能させるために、2D関数を含む複数の関数を試してきましたが、まだ運がありません...

地球上に latlng エンドポイントの 2 つの線分があり、2 つの線が交差するかどうか、またどこで交差するかを知りたいです。

私は現在、物理学専攻が2次元平面の仕事をするべきだと言っていますが、そうではありません。交差に対しては常に true を返します

[コード]関数 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

}[/コード]

4

1 に答える 1

0

Assumption: your line segments are great circle arcs.

Any pair of distinct great circles intersects exactly twice. So, you can:

  1. Find the two points of intersection.
  2. See if the intersection points lie in your arcs.

Here is a discussion of this method.

于 2010-08-13T17:48:21.027 に答える