.NET
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Ray Tracing Kind
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
114 Views, 3 Replies
06-14-2012 10:08 PM
I am doing a project where we should detect center of object and automatically draw lines in all directions
example: Lets consider a rectangle, locate center of rectangle and draw lines on all directions
Solved! Go to Solution.
Re: Ray Tracing Kind
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
06-15-2012 04:10 AM in reply to:
amitk_189
For rectangle it would be easy to doing:
[CommandMethod("testDrawLines","tdl", CommandFlags.Modal)]
public static void DrawLines()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.D ocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
try
{
PromptEntityOptions peo = new PromptEntityOptions("\nSelect polyline: ");
peo.SetRejectMessage("Select polyline only!");
peo.AddAllowedClass(typeof(Polyline), true);
PromptEntityResult res = doc.Editor.GetEntity(peo);
if (res.Status != PromptStatus.OK) return;
Entity ent = tr.GetObject(res.ObjectId, OpenMode.ForRead, false) as Entity;
Polyline pline = ent as Polyline;
if (pline == null)
{
Autodesk.AutoCAD.ApplicationServices.Application.S howAlertDialog("No luck");
return;
}
Point3d lp = pline.GeometricExtents.MinPoint;
Point3d up = pline.GeometricExtents.MaxPoint;
Point3d cp = new Point3d((up.X+lp.X)/2,(up.Y+lp.Y)/2,(up.Z+lp.Z)/2) ;
double leng = Math.Abs(up.X - lp.X);
double wid = Math.Abs(up.Y - lp.Y);
if (leng > wid)
leng = wid;
int num = 16;
double ang = Math.PI * 2 / num;
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
for (int i = 0; i < num-1; i++)
{
Point3d ep = PolarPoint(cp, i * ang, leng);
Line ln = new Line(cp, ep);
Point3dCollection ips = new Point3dCollection();
ln.IntersectWith(pline, Intersect.ExtendArgument, ips,0, 0);
Point3d ip = ips[0];
ln.EndPoint = ip;
btr.AppendEntity(ln);
tr.AddNewlyCreatedDBObject(ln, true);
}
tr.Commit();
}
catch (System.Exception ex)
{
Autodesk.AutoCAD.ApplicationServices.Application.D ocumentManager.MdiActiveDocument.Editor.WriteMessa ge(ex.Message + "\n" + ex.StackTrace);
}
}
}
public static Point3d PolarPoint(Point3d basepoint, double angle, double distance)
{
// credits to Tony Tanzillo
return new Point3d(
basepoint.X + (distance * Math.Cos(angle)),
basepoint.Y + (distance * Math.Sin(angle)),
basepoint.Z);
}
~'J'~
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
C6309D9E0751D165D0934D0621DFF27919
Re: Ray Tracing Kind
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
06-17-2012 11:10 PM in reply to:
amitk_189
Getting Error on
Point3d ip = ips[0];
No data is present in here and we have initilised it not assigned data
Re: Ray Tracing Kind
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
06-18-2012 02:43 AM in reply to:
amitk_189
Try again
[CommandMethod("testDrawLines", "tdl", CommandFlags.Modal)]
public static void DrawLines()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.D ocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
try
{
PromptEntityOptions peo = new PromptEntityOptions("\nSelect polyline: ");
peo.SetRejectMessage("Select polyline only!");
peo.AddAllowedClass(typeof(Polyline), true);
PromptEntityResult res = doc.Editor.GetEntity(peo);
if (res.Status != PromptStatus.OK) return;
Entity ent = tr.GetObject(res.ObjectId, OpenMode.ForRead, false) as Entity;
Polyline pline = ent as Polyline;
if (pline == null)
{
Autodesk.AutoCAD.ApplicationServices.Application.S howAlertDialog("No luck");
return;
}
Point3d lp = pline.GeometricExtents.MinPoint;
Point3d up = pline.GeometricExtents.MaxPoint;
Point3d cp = new Point3d((up.X + lp.X) / 2, (up.Y + lp.Y) / 2, (up.Z + lp.Z) / 2);
double leng = Math.Abs(up.X - lp.X);
double wid = Math.Abs(up.Y - lp.Y);
if (leng < wid)
leng = wid;
// number of lines
int num = 16;
double ang = Math.PI * 2 / num;
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
for (int i = 0; i < num - 1; i++)
{
Point3d ep = PolarPoint(cp, i * ang, leng);
Line ln = new Line(cp, ep);
ln.Normal = pline.Normal;
Point3dCollection ips = new Point3dCollection();
ln.IntersectWith(pline, Intersect.ExtendArgument, ips, (int)IntPtr.Zero, (int)IntPtr.Zero);
Point3d ip = ips[0];
ln.EndPoint = ip;
btr.AppendEntity(ln);
tr.AddNewlyCreatedDBObject(ln, true);
}
tr.Commit();
}
catch (System.Exception ex)
{
Autodesk.AutoCAD.ApplicationServices.Application.D ocumentManager.MdiActiveDocument.Editor.WriteMessa ge(ex.Message + "\n" + ex.StackTrace);
}
}
}
~'J'~
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
C6309D9E0751D165D0934D0621DFF27919
