1.0.0 2024-03-13 02:17 UTC

This package is auto-updated.

Last update: 2024-09-15 09:44:05 UTC


README

适用于 PHP 8.1+ 的一维几何

几何交点文档

Geometry\Intersects 提供了确定各种一维几何实体(如点、线段和向量)之间交点的功能。

形状

  • :表示一维空间中的一个点。
  • 线段:表示由两个端点定义的线段。
  • 向量:表示从一个点开始并沿指定方向延伸的无限线。

示例用法

以下示例演示了如何在 Geometry 类中使用每个方法。

intersectsPoints 示例

// Create two points
$point1 = new Point(1, true);
$point2 = new Point(1, true);

// Check if the points intersect
$result = Intersects::intersectsPoints($point1, $point2);

// Output: true
echo $result ? 'true' : 'false';

intersectsPointAndSegment 示例

// Create a point and a segment
$point = new Point(2, true);
$segment = new Segment(new Point(1, true), new Point(3, true));

// Check if the point intersects with the segment
$result = Intersects::intersectsPointAndSegment($point, $segment);

// Output: true
echo $result ? 'true' : 'false';

intersectsPointAndVector 示例

// Create a point and a vector
$point = new Point(5, true);
$vector = new Vector(new Point(2, true), true);

// Check if the point intersects with the vector
$result = Intersects::intersectsPointAndVector($point, $vector);

// Output: true
echo $result ? 'true' : 'false';

intersectsSegments 示例

// Create two segments
$segment1 = new Segment(new Point(1, true), new Point(4, true));
$segment2 = new Segment(new Point(3, true), new Point(5, true));

// Check if the segments intersect
$result = Intersects::intersectsSegments($segment1, $segment2);

// Output: true
echo $result ? 'true' : 'false';

intersectsSegmentAndVector 示例

// Create a segment and a vector
$segment = new Segment(new Point(1, true), new Point(3, true));
$vector = new Vector(new Point(2, true), true);

// Check if the segment intersects with the vector
$result = Intersects::intersectsSegmentAndVector($segment, $vector);

// Output: true
echo $result ? 'true' : 'false';

intersectsVectors 示例

// Create two vectors
$vector1 = new Vector(new Point(0, true), true);
$vector2 = new Vector(new Point(2, true), false);

// Check if the vectors intersect
$result = Intersects::intersectsVectors($vector1, $vector2);

// Output: true (since both vectors are infinite in one direction, they intersect)
echo $result ? 'true' : 'false';

这些示例提供了如何在您的 Intersects 类中使用每个方法的实际指南,展示了如何创建 PointSegmentVector 对象,以及如何使用它们来检查交点。