如何确定面要素落在直线的哪一边?


9

我有与行数据相交的宗地数据。在宗地数据中,有些宗地不与直线相交。如何以编程方式确定不相交的宗地是在直线的右侧还是左侧?谢谢。

Answers:


8

使用IHitTest界面。您的查询点将是多边形质心,输入几何形状将是线。输出之一将是布尔值(bRightSide),它将告诉您行所在的哪一侧。


2

您可以为此使用点积

/// <summary>
/// Used to indicate the orientation of an object in space 
/// with respect to another object
/// </summary>
public enum OrientationType
{
    Left,
    Right,
    Coincident,
    Unknown
}


/// <summary>
    /// Determines if a point is oriented left, right or coincident with
    /// a directed line. 
    /// Line direction is determined by its From and To points.
    /// </summary>
    /// <param name="p">The point to test.</param>
    /// <param name="segment">The line dividing the space</param>
    /// <returns>An OrientationType indicating the orientation.</returns>
    public static OrientationType GetPointOrientation(IPoint p, ISegment segment)
    {

        OrientationType result = OrientationType.Unknown;

        double Ax = segment.FromPoint.X;
        double Ay = segment.FromPoint.Y;
        double Bx = segment.ToPoint.X;
        double By = segment.ToPoint.Y;
        double Px = p.X;
        double Py = p.Y;

        double nDotV = ((Ay - By) * (Px - Ax)) + ((Bx - Ax) * (Py - Ay));

        if (nDotV < 0)
        {
            result = OrientationType.Right;//opposite direction to normal vector
        }
        else if (nDotV > 0)
        {
            result = OrientationType.Left;
        }
        else if (nDotV == 0)
        {
            result = OrientationType.Coincident;
        }

        return result;
    }

1
我认为值得指出的是,该技术要求输入线必须是仅由2个顶点组成的线,因为它接受了ISegment对象。
Hornbydd 2011年

这对于正确的欧几里得线(整个东西,而不仅仅是段或光线)来说是很好的工作,但是我很确定OP使用“ line”和“ line data”作为多义线的松散同义词其中点积方法失败。
ub

2

获得预期结果的算法:

  1. 重点关注
  2. 在“线”几何的右侧(或左侧)添加一些缓冲区(0.0000005)。
  3. 检查缓冲区几何是在多边形几何的“内部”还是在多边形几何的“重叠”。
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.