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
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 LineElementDim sRayA As Ray3dDim sRayB As Ray3dDim boolResultado As Boolean.......................................sRayA.Origin = lineA.OriginsRayA.Direction = (lineA.EndPoint)sRayB.Origin = lineB.OriginsRayB.Direction = (lineB.EndPoint)boolResultado = Ray3dRay3dIntersectXY(sRayA, sRayB, lineA.EndPoint, -1, lineB.EndPoint, -1)
Dim LineA As LineElement
Dim LineB As LineElement
Dim sRayA As Ray3d
Dim sRayB As Ray3d
Dim boolResultado As Boolean
.......................................
sRayA.Origin = lineA.OriginsRayA.Direction = (lineA.EndPoint)sRayB.Origin = lineB.OriginsRayB.Direction = (lineB.EndPoint)boolResultado = Ray3dRay3dIntersectXY(sRayA, sRayB, lineA.EndPoint, -1, lineB.EndPoint, -1)
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)
In addition to Jon's advice, your code should looks like this ...
rayA.Origin = lineAStartrayA.Direction = Point3dSubtract(lineAEnd, lineAStart)rayB.Origin = lineBStartrayB.Direction = Point3dSubtract(lineBEnd, lineBStart)Dim inter1 As Point3dDim fract1 As DoubleDim inter2 As Point3dDim fract2 As DoubleDim result As Booleanresult = 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
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
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.
Unknown said:In my case I need to know if the lines have a intersection in your proyection
Unknown said: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.
I think you have an answer. Follow Jan's advice and examine the value of those fractions.
To be more precise:
Regards,
Jan
Jon, I didn't see the answer of Jan.
Effectively I have tested the code of Jan and it works. Whit the values of these fractions I resolved the problem.
Thanks both