Bug with Entity.IntersectWith method

Bug with Entity.IntersectWith method

Anonymous
Not applicable
1,098 Views
5 Replies
Message 1 of 6

Bug with Entity.IntersectWith method

Anonymous
Not applicable
I've encountered a known bug with Autocad where the entity.intersectwith
method returns intersection points where no intersection exists. (this has
been verified via ADN: CR#662189). I'm detecting the intersection between
a plane and a 3d line.

Before I pull out the old geometry books to write my own methods, does anyone
know of any work arounds for this problem? Of course at this point I'm in
a time crunch or I wouldn't bring it up.

Thanks,
Mike
0 Likes
1,099 Views
5 Replies
Replies (5)
Message 2 of 6

_gile
Consultant
Consultant
Hi,

Here's a way using vectors dot product.

{code}private bool IntersectPlaneLine(Plane plane, Line3d line, out Point3d intersPt)
{
Point3d org = plane.PointOnPlane;
Vector3d normal = plane.Normal;
Point3d pt = line.PointOnLine;
Vector3d dir = line.Direction;
double scl = dir.DotProduct(normal);
if (scl == 0)
return false;
scl = normal.DotProduct(pt - org) / scl;
intersPt = pt + dir.Negate().MultiplyBy(scl);
return true;
}{code}


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 6

Anonymous
Not applicable
Hello _gile,
Thanks I'll give it a try.

> Hi,
>
> Here's a way using vectors dot product.
>
> {code}private bool IntersectPlaneLine(Plane plane, Line3d line, out
> Point3d intersPt)
> {
> Point3d org = plane.PointOnPlane;
> Vector3d normal = plane.Normal;
> Point3d pt = line.PointOnLine;
> Vector3d dir = line.Direction;
> double scl = dir.DotProduct(normal);
> if (scl == 0)
> return false;
> scl = normal.DotProduct(pt - org) / scl;
> intersPt = pt + dir.Negate().MultiplyBy(scl);
> return true;
> }{code}
0 Likes
Message 4 of 6

Anonymous
Not applicable
{quote}

I'm detecting the intersection between a plane and a 3d line.

{quote}

IntersectWith() operates on two entities.

What kind of entity is the 'plane'?

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");
0 Likes
Message 5 of 6

_gile
Consultant
Consultant
Reading Tony's reply I realise I perhaps misunderstood the request.
I read 3d line and plane, so I thaught you wanted the intersecion between a Line3d(unbounded) and a Plane (infinite), maybe due to my poor English...
The method I gave works this way.
It will always return true exept if the Line3d is parallel to the plane.


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 6 of 6

Anonymous
Not applicable
Hello Tony,
What I'm doing is traversing down a Civil3D alignment at each station, detecting
if any plan view graphics would intersect with a line that is perpendicular
at the station out a certain distance then doing some special coding. I've
dropped all the problem entities down to plan Autocad entities and tested
in plain Autocad 2010 and get the same result.

This is working great except for a few places where intersections are detected
where they don't exist. ADN said these show up sometimes when "Large Coordinates"
are encountered. The Civil3D team now codes around this known bug by transforming
copies of the objects in memory closer to the drawing origin (thus smaller
coordinates) where the bug doesn't show itself.

I've attached at dwg file that shows this behavior of Large Coordinates.
The green line represents the station line and the yellow line is the plan
graphic.

Below is my method that takes in: a SelectionSet and the line representing
the line perpendicular to the alignment at the current station
It returns a ObjectIDCollection and Point3D collection of what and where
it found intersections.

{code}
Public Shared Sub GetIntersections(ByRef cPts As Point3dCollection, ByRef
cObjs As ObjectIdCollection, ByVal ss As SelectionSet, ByVal db As Database,
ByVal oLine As Line)
Dim ent As Autodesk.AutoCAD.DatabaseServices.Entity = Nothing
Dim tm As DBTransactionManager = db.TransactionManager
cObjs = New ObjectIdCollection
cPts = New Point3dCollection

Using ta As Transaction = tm.StartTransaction()
If Not ss Is Nothing Then
'see if the entities found intersect with the corridor frequency
lines at the current station
For i As Integer = 0 To ss.Count
Try
ent = ta.GetObject(ss.Item(i).ObjectId, OpenMode.ForRead,
False, True)
Dim iPts As Point3dCollection = New Point3dCollection
'create plane perpendicular to the alignment at the
current station origin
Dim xyPlane As Plane = New Plane(New Point3d(0, 0,
0), New Vector3d(0, 0, 1))
Dim int As Integer = 0
Dim intPointer As IntPtr = int

ent.IntersectWith(oLine, Intersect.OnBothOperands,
xyPlane, iPts, System.IntPtr.Zero, System.IntPtr.Zero)
If Not iPts Is Nothing Then 'intersection found
For Each tPt As Point3d In iPts
Dim bInserted As Boolean = False
If cPts.Count > 0 Then
Dim j As Integer = 0
Dim sPt As Point3d = oLine.StartPoint
Dim tDist As Double = sPt.DistanceTo(tPt)
For j = 0 To cPts.Count
If tDist < sPt.DistanceTo(cPts(j))
Then
cPts.Insert(j, tPt)
cObjs.Insert(j, ent.ObjectId)
bInserted = True
Exit For
End If
Next
End If
If Not bInserted Then
cPts.Add(tPt)
cObjs.Add(ent.ObjectId)
End If
Next
End If
Catch
End Try
Next
End If
End Using
End Sub
{code}

> {quote}
>
> I'm detecting the intersection between a plane and a 3d line.
>
> {quote}
>
> IntersectWith() operates on two entities.
>
> What kind of entity is the 'plane'?
>
> AcadXTabs: MDI Document Tabs for AutoCAD
> Supporting AutoCAD 2000 through 2010
> http://www.acadxtabs.com
>
> Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");
>
0 Likes