using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.GraphicsInterface;
using Autodesk.AutoCAD.Runtime;
namespace AcadTest
{
public class TestEditorDraw
{
[CommandMethod("TestEditorDrawArc")]
public void Run()
{
Support.InitializeVars(out Document adoc, out Editor ed, out Database db);
ed.PointMonitor += Ed_PointMonitor;
ed.GetPoint("\nSelect point");
ed.PointMonitor -= Ed_PointMonitor;
}
private void Ed_PointMonitor(object sender, PointMonitorEventArgs e)
{
if (e.Context.PointComputed)
{
Point3d pt = e.Context.ComputedPoint;
double
radius = Point3d.Origin.DistanceTo(pt),
angle = Vector3d.XAxis.GetAngleTo(Point3d.Origin.GetVectorTo(pt), Vector3d.ZAxis);
Vector3d radHor = Vector3d.XAxis.MultiplyBy(radius);
Point3d
start = Point3d.Origin + radHor,
pointOnArc = Point3d.Origin + radHor.RotateBy(angle / 2.0, Vector3d.ZAxis),
end = Point3d.Origin + radHor.RotateBy(angle, Vector3d.ZAxis);
DrawArc(e.Context.DrawContext.Geometry, start, pointOnArc, end);
}
}
static void DrawArc(ViewportGeometry geometry, Point3d start, Point3d pointOnArc, Point3d end)
{
if (Application.Version.Major == 21)
{
using (CircularArc3d arc = new CircularArc3d(start, pointOnArc, end))
{
double
startParam = arc.GetParameterOf(start),
endParam = arc.GetParameterOf(end),
arcLength = arc.GetLength(startParam, endParam, Tolerance.Global.EqualPoint),
delta = 0.3; // Шаг аппроксимации
Point3d prevPt = start;
double
tmpLength = 0.0,
prevParam = startParam;
while ((tmpLength += delta) < arcLength)
{
double curParam = arc.GetParameterAtLength
(prevParam, delta, true, Tolerance.Global.EqualPoint);
Point3d curPt = arc.EvaluatePoint(curParam);
geometry.WorldLine(prevPt, curPt);
prevPt = curPt;
prevParam = curParam;
}
geometry.WorldLine(prevPt, end);
}
}
else
{
geometry.CircularArc(start, pointOnArc, end, ArcType.ArcSimple);
}
}
}
}