.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Polyline3d intersect

5 REPLIES 5
Reply
Message 1 of 6
GStevens
984 Views, 5 Replies

Polyline3d intersect

Hello everyone,

1. How to get the intersection of 2 Polyline3d in different plane?
I tried using IntersectWith() but it return no intersection because the polylines lies in different plane.
2. How about Aparent Intersect? Is there anyone who can teach me how to implement this in my C# code?

Thank you.

GS
5 REPLIES 5
Message 2 of 6
Anonymous
in reply to: GStevens

What about create projections of those Polyline3d on single plan (with help of Polyline3d.GetProjectedCurve method)?
After than you can do IntersectWith() with projections.
Message 3 of 6
GStevens
in reply to: GStevens

Dear Alexander Rivilis,

I'll do that. Thank you.

GS
Message 4 of 6
GStevens
in reply to: GStevens

Dear Alexander Rivilis,

I'll appreciate if you can show me a snippet code how to do it.
Thank you in advance.

GS
Message 5 of 6
Anonymous
in reply to: GStevens

[code]
using System ;
using System.Collections;
using Autodesk.AutoCAD.Runtime ;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.ApplicationServices;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

[assembly: CommandClass(typeof(ClassLibrary.Class))]

namespace ClassLibrary
{
public class Class
{
[CommandMethod("IntPoly3d")]
static public void IntPoly3d()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Polyline3d pl1 = SelectPoly3d("\nSelect first Polyline3d: ");
if (pl1 == null) return;
Polyline3d pl2 = SelectPoly3d("\nSelect second Polyline3d: ");
if (pl2 == null) return;
// We can project our plines in direction of Z axis of WCS,
// but you can use another project plane
Vector3d dir = new Vector3d(0,0,1);
Point3d orig = new Point3d (0,0,0);
// Plane of WCS
Plane planeWCS = new Plane(orig, dir);
Curve pl1_prj = pl1.GetProjectedCurve(planeWCS,dir); pl1.Dispose();
Curve pl2_prj = pl2.GetProjectedCurve(planeWCS,dir); pl2.Dispose();
Point3dCollection pts = new Point3dCollection();
pl1_prj.IntersectWith(pl2_prj,Intersect.OnBothOperands,pts,0,0);
if (pts.Count > 0)
{
ed.WriteMessage("\nNumber of intersection: {0}",pts.Count);
foreach (Point3d pt in pts) ed.WriteMessage("\n Point: {0}",pt);
}
else
{
ed.WriteMessage("\nNo intersection!");
}
pl1_prj.Dispose(); pl2_prj.Dispose();
}
static private Polyline3d SelectPoly3d(string str)
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Database db = HostApplicationServices.WorkingDatabase;
PromptEntityResult rs = ed.GetEntity(str);
if (rs.Status == PromptStatus.OK)
{
Transaction trans = db.TransactionManager.StartTransaction();
Entity ent = (Entity)trans.GetObject(rs.ObjectId, OpenMode.ForRead);
Polyline3d pl = ent as Polyline3d;
trans.Commit();
if (pl == null) ed.WriteMessage("\nIt is not Polyline3d!");
return pl;
}
return null;
}
}
}
[/code]
Message 6 of 6
GStevens
in reply to: GStevens

Dear Alexander Rivilis,
Thank you so much to your help it helps me a lot however its my mistake that I was not able to inform you that I need also the value of Z coordinate. What should I do so that I get also get it like Apparent Intersect does?
Once again thank you.

GS

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost