怎样用C#实现画圆
怎样用C#实现交互式画圆,并得到几何体 <p>交互式绘图要用Jig的</p><p>先看下相关内容吧</p> 定义了类
public class Cir:EntityJig
{
private Point3d m_Start;
private Point3d m_End;
private double m_dir;
private Vector3d m_normal;
private MgGeometry m_MgGeo;
public Cir(Point3d start)
: base(new Circle())
{
Plane plane = new Plane(
Application.DocumentManager.MdiActiveDocument.Database.Ucsorg,
Application.DocumentManager.MdiActiveDocument.Database.Ucsxdir,
Application.DocumentManager.MdiActiveDocument.Database.Ucsydir
);
m_Start = start;
m_End = start;
m_normal = new Vector3d(0.0, 0.0, 1.0);
m_dir = m_Start.DistanceTo(m_End);
if (m_dir == 0)
m_dir = 0.1;
Point2d pt = start.Convert2d(plane);
((Circle)Entity).Center = m_Start;//.AddVertexAt(0, point, 0, 0, 0);
((Circle)Entity).Radius = m_dir;
((Circle)Entity).Normal = m_normal;
//((Circle)Entity).Closed = true;
// Set the color of the selection to Red
this.Entity.Color = Autodesk.AutoCAD.Colors.Color.FromColor(System.Drawing.Color.Red);
}
/// <summary>
/// Acquires user input and define the state of the entity being acquirede.
/// </summary>
/// <param m_name="prompts"> A collection of sampling functions for Jig data acquisition.</param>
protected override SamplerStatus Sampler(JigPrompts prompts)
{
JigPromptPointOptions jigOpts = new JigPromptPointOptions();
jigOpts.UserInputControls = (UserInputControls.Accept3dCoordinates
| UserInputControls.NoZeroResponseAccepted
| UserInputControls.NoNegativeResponseAccepted);
SamplerStatus result = SamplerStatus.NoChange; ;
// For rectangle it only need input once for the next point.
jigOpts.Message = "\n指定另一个对角点";
PromptPointResult promptResult = prompts.AcquirePoint(jigOpts);
if (promptResult.Status == PromptStatus.OK)
{
if (promptResult.Value == m_Start)
return SamplerStatus.NoChange;
m_End = promptResult.Value;
m_dir = m_Start.DistanceTo(m_End);
result = SamplerStatus.OK;
}
return result;
}
}
另外在命令里面调用
public void draw()
{
Editor ed = Util.AcadEditor;
PromptPointOptions opts = new PromptPointOptions("\n指定第一个对角点:");
PromptPointResult res = ed.GetPoint(opts);
// Cancel input at the beginning, no need to draw selection
if (res.Status == PromptStatus.Cancel)
{
return;
}
Cir newcir = new Cir(res.Value);
PromptPointResult pr = (PromptPointResult)(ed.Drag(newcir));
if (pr.Status != PromptStatus.OK)
{
return;
}
newcir.SetCir();
}
确定圆心后 移动鼠标确定半径的过程中显示的却是一小段弧段,不知道什么原因,请二楼指点一下,多谢了
<p>看下这里</p>
<p><u><font color="#810081"><a href="http://bbs.mjtd.com/forum.php?mod=viewthread&tid=75768">http://bbs.mjtd.com/forum.php?mod=viewthread&tid=75768</a></font></u><a href="http://bbs.mjtd.com/forum.php?mod=viewthread&tid=75768"></a></p>
<p> </p> 正需要象这样的基础程序来学习
页:
[1]