TheSwamp
Code Red => .NET => Topic started by: dugk on June 18, 2010, 12:55:32 AM
-
Thanks!
Doug
-
I should clarify that I'm looking for a method that takes 4 points and returns a point if the first two points, as a line, intersect with the last two points, as a line.
AutoCAD 2010 Help: Developer Documentation
inters
Finds the intersection of two lines
(inters pt1 pt2 pt3 pt4 [onseg])
All points are expressed in terms of the current UCS. If all four point arguments are 3D, inters checks for 3D intersection. If any of the points are 2D, inters projects the lines onto the current construction plane and checks only for 2D intersection.
Arguments
pt1
One endpoint of the first line.
pt2
The other endpoint of the first line.
pt3
One endpoint of the second line.
pt4
The other endpoint of the second line.
onseg
If specified as nil, the lines defined by the four pt arguments are considered infinite in length. If the onseg argument is omitted or is not nil, the intersection point must lie on both lines or inters returns nil.
Return Values
If the onseg argument is present and is nil, inters returns the point where the lines intersect, even if that point is off the end of one or both of the lines. If the onseg argument is omitted or is not nil, the intersection point must lie on both lines or inters returns nil. The inters function returns nil if the two lines do not intersect.
Examples
(setq a '(1.0 1.0) b '(9.0 9.0))
(setq c '(4.0 1.0) d '(4.0 2.0))
Command: (inters a b c d)
nil
Command: (inters a b c d T)
nil
Command: (inters a b c d nil)
(4.0 4.0)
-
There are many ways to reproduce intersection. One of them is P/Invoke acdbInters:
int acdbInters (const ads_point from1, const ads_point to1, const ads_point from2, const ads_point to2, int teston, ads_point result);
-
Thank you for that very quick reply!
Being a relative newbie to C# and .NET I tried to research P/Invoke.
I searched the "ObjectARX for AutoCAD 2010 : Managed Class Reference Guide" Help file for P/Invoke and PInvoke and it didn't return any results.
I checked out the "NET P/INVOKE Routines" (http://www.theswamp.org/index.php?topic=31886.0) topic but I still fail gain a simple understanding of what P/Invoke is. Can you give me an overview of what P/Invoke is and an example of its use, or point me to those.
Thanks!
Doug
-
public void IntersectWith( ...... );
Declaring Type: Autodesk.AutoCAD.DatabaseServices.Entity
worth a look
in fact, there is a IntersectWith method
and a ProjectedIntersectWith
for most individual classes ...
in Autodesk.AutoCAD.Geometry
-
perhaps something like this (not tested) :-
public static Point3d GetIntersectPoint(Point3d sp1, Point3d ep1, Point3d sp2, Point3d ep2)
{
Geometry.Line3d L1 = new Line3d(sp1, ep1);
Geometry.Line3d L2 = new Line3d(sp2, ep2);
return L1.IntersectWith(L2)[0];
}
-
Hi,
The Geometry.Line3d (unbounded) or Geometry.LineSegment3d (bounded) have an IntersectWith method.
So, a .NET equivalent for the inters function may be something like this:
public Point3d[] Inters(Point3d p1, Point3d p2, Point3d p3, Point3d p4, bool onSeg)
{
LinearEntity3d l1, l2;
if (onSeg)
{
l1 = new LineSegment3d(p1, p2);
l2 = new LineSegment3d(p3, p4);
}
else
{
l1 = new Line3d(p1, p2);
l2 = new Line3d(p3, p4);
}
return l1.IntersectWith(l2);
}
-
for reference
Have a look at
.....SDK\ObjectARX 2011\docs\arxmgd.chm
Search for IntersectWith
that should give a pretty you good idea of the options