problem in drawing hexagoan

problem in drawing hexagoan

Anonymous
Not applicable
1,387 Views
6 Replies
Message 1 of 7

problem in drawing hexagoan

Anonymous
Not applicable
I am trying to draw the Hexagon using Polyline in AutoCAD using C#.net technology, but i cant. I am giving first point through prompt and that is in Point3d format and when we add vertex to polyline in hexagon that required point in point2d format. give me the way that I get success.
also tell me how to calculate that angle in hexagon. which is 120 if hexagon and 108 in pentagon.

I am drawing polygon on my own points,like this
Polyline p = new Polyline(6);
p.AddVertexAt(0, new Point2d(9.50,10), 0, 0, 0);
p.AddVertexAt(1, new Point2d(21, 10), 0, 0, 0);
p.AddVertexAt(2, new Point2d(26.30, 20), 0, 0, 0);
p.AddVertexAt(3, new Point2d(21, 30), 0, 0, 0);
p.AddVertexAt(4, new Point2d(9.60, 30), 0, 0, 0);
p.AddVertexAt(5, new Point2d(3, 20), 0, 0, 0);
p.AddVertexAt(6, new Point2d(9.50, 10), 0, 0, 0);
btr.AppendEntity(p);
trans.AddNewlyCreatedDBObject(p, true);

I want to draw the polygon with user choices. help me.
0 Likes
1,388 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
Find PolarPoint function here:

http://discussion.autodesk.com/forums/thread.jspa?messageID=5764413

Bill
0 Likes
Message 3 of 7

Anonymous
Not applicable
hey Thanks but not working properly? can we draw the Hexagon in AutoCAD with c#?
0 Likes
Message 4 of 7

Anonymous
Not applicable
The PolarPoint method works fine.

And Yes you can create a Polyline in C#.

This should help you learn how to do that:
http://through-the-interface.typepad.com/through_the_interface/2006/11/controlling_int.html


Bill
0 Likes
Message 5 of 7

Anonymous
Not applicable
Thanks Bill, its working. Again I have a problem to draw the hexagon using polyline, I want to have the standard angle of the hexagon. is there is any solution. is it possible or not.

Thanks & Regards
Mr. Hemant. Edited by: hemant.chaudhari on Feb 18, 2009 12:10 PM
0 Likes
Message 6 of 7

Anonymous
Not applicable
You need help with elemetary math?

I can show you what I would do to create a 6 sided polygon.
Don't forget to lock your document for this.



if (point.Status == PromptStatus.OK)
{
double seg = (Math.PI / 3.0);
double ang = 0;
Point2d bpt = new Point2d(point.Value.X, point.Value.Y);

using (Transaction transaction = document.TransactionManager.StartTransaction())
{
Polyline pl = new Polyline();

for (int x = 0; x < 6; x++)
{
Point2d p = PolarPoint2D(bpt, ang, 1.0);
pl.AddVertexAt(x, p, 0.0, 0.0, 0.0);
ang = ang + seg;
}
pl.Closed = true;

BlockTable table = (BlockTable)transaction.GetObject(database.BlockTableId, OpenMode.ForRead);
BlockTableRecord record = (BlockTableRecord)transaction.GetObject(table[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

record.AppendEntity(pl);
transaction.AddNewlyCreatedDBObject(pl, true);
transaction.Commit();
}
}


Also note I changed the PolarPoint function to PolarPoint2D for simplicity:


public Point2d PolarPoint2D(Point2d basepoint, double angle, double distance)
{
return new Point2d(basepoint.X + (distance * Math.Cos(angle)), basepoint.Y + (distance * Math.Sin(angle)));
}


HTH

Bill
0 Likes
Message 7 of 7

Anonymous
Not applicable
Thanks Bill It's working.

Thanks & Regards
Mr. Hemant.
0 Likes