Author Topic: Is there a .Net equivalent to AutoLISP's inters function?  (Read 4326 times)

0 Members and 1 Guest are viewing this topic.

dugk

  • Guest
Is there a .Net equivalent to AutoLISP's inters function?
« on: June 18, 2010, 12:55:32 AM »
Thanks!
Doug

dugk

  • Guest
Re: Is there a .Net equivalent to AutoLISP's inters function?
« Reply #1 on: June 18, 2010, 12:59:40 AM »
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)



Alexander Rivilis

  • Bull Frog
  • Posts: 214
  • Programmer from Kyiv (Ukraine)
Re: Is there a .Net equivalent to AutoLISP's inters function?
« Reply #2 on: June 18, 2010, 01:09:18 AM »
There are many ways to reproduce intersection. One of them is P/Invoke acdbInters:
Code: [Select]
int acdbInters (const ads_point from1, const ads_point to1, const ads_point from2, const ads_point to2, int teston, ads_point result);

dugk

  • Guest
Re: Is there a .Net equivalent to AutoLISP's inters function?
« Reply #3 on: June 18, 2010, 01:54:10 AM »
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

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Is there a .Net equivalent to AutoLISP's inters function?
« Reply #4 on: June 18, 2010, 02:01:57 AM »
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

« Last Edit: June 18, 2010, 02:07:09 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Is there a .Net equivalent to AutoLISP's inters function?
« Reply #5 on: June 18, 2010, 02:42:54 AM »

perhaps something like this (not tested) :-
Code: [Select]
         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];
        }
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Is there a .Net equivalent to AutoLISP's inters function?
« Reply #6 on: June 18, 2010, 02:44:18 AM »
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:
Code: [Select]
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);
        }
Speaking English as a French Frog

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Is there a .Net equivalent to AutoLISP's inters function?
« Reply #7 on: June 18, 2010, 04:05:56 AM »

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
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.