Intersection between two lines

Hi all,

Is it possible to know if two straight lines can intersect? 

I need to know if the extension of two lines (A-B and C-D) intersect at a point. Is there any function or method?

Thanks in advance

Parents
  • Unknown said:
    Is it possible to know if two straight lines can intersect? 

    2D or 3D?  If 3D, you must first check that the lines lie on the same plane.  If non-planar, they never intersect.

     
    Regards, Jon Summers
    LA Solutions

  • Jhon, The lines are in the same plane. I've a DGN 2D.

    Jan, I think that i've to use the Ray3dRay3dIntersectXY method but I don't understand the VBA help. Any example?

    In the help I need Ray0 and Ray1 that are my lines, but I don't know to put in the Point0, Fraction0, Point1 and Fraction1. Always it's True.

    Regards

    Dim LineA As LineElementDim LineB As LineElement
    Dim sRayA As Ray3dDim sRayB As Ray3dDim boolResultado As Boolean.......................................sRayA.Origin = lineA.Origin
    sRayA.Direction = (lineA.EndPoint)
    sRayB.Origin = lineB.Origin
    sRayB.Direction = (lineB.EndPoint)

    boolResultado = Ray3dRay3dIntersectXY(sRayA, sRayB, lineA.EndPoint, -1, lineB.EndPoint, -1)

  • Vector Algebra

    The direction of a line is the vector difference between its start point and end point.

    Unknown said:
    sRayA.Direction = (lineA.EndPoint)

    Your direction is the vector from 0,0 to lineA.EndPoint.

    Try this …

    sRayA.Direction = Point3dSubtract (lineA.EndPoint - lineA.StartPoint)

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions

  • In addition to Jon's advice, your code should looks like this ...

    rayA.Origin = lineAStart
    rayA.Direction = Point3dSubtract(lineAEnd, lineAStart)

    rayB.Origin = lineBStart
    rayB.Direction = Point3dSubtract(lineBEnd, lineBStart)

    Dim inter1 As Point3d
    Dim fract1 As Double
    Dim inter2 As Point3d
    Dim fract2 As Double

    Dim result As Boolean

    result = Ray3dRay3dIntersectXY(rayA, rayB, inter1, fract1, inter2, fract2)

    Because you work in 2D only, important for you is only intersection point inter1, that is the same as point inter2. Fractions express where the intersection point is in terms of the length of the particular ray. This information is important if you need to know if the intersection point lies on the line (between start and end points) or outside.

    HTH Jan

  • Ok Jon, I understood perfectly. But I've a problem because always the lines have a intersection. The lines don't have intersection when are paralell.

    In my case I need to know if the lines have a intersection in your proyection. In the next image, for my case, the lines don't have intersection because the direction is open. It's possible to know this with the method Ray3dRay3dIntersectXY.

    Regards

Reply Children