Hi,
Here's a trick (current UCS plane have to be coplanar to WCS plane)
{code}using System;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;
namespace Circle3Points
{
public class CircleJigSample
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = acadApp.DocumentManager.MdiActiveDocument.Editor;
class ArcJig : EntityJig
{
Arc _arc;
Point3d _dragPoint;
Point3d _firstPoint;
Point3d _secondPoint;
Line2d _line;
public ArcJig(Arc arc, Point3d dragPoint, Point3d firstPoint, Point3d secondPoint, Line2d line)
: base(arc)
{
_arc = arc;
_dragPoint = dragPoint;
_firstPoint = firstPoint;
_secondPoint = secondPoint;
_line = line;
}
protected override SamplerStatus Sampler(JigPrompts prompts)
{
JigPromptPointOptions jppo = new JigPromptPointOptions("\nSpecify the third point: ");
jppo.UserInputControls = (UserInputControls.Accept3dCoordinates);
PromptPointResult ppr = prompts.AcquirePoint(jppo);
if (ppr.Status == PromptStatus.OK)
{
if (ppr.Value.IsEqualTo(_dragPoint))
return SamplerStatus.NoChange;
else
{
_dragPoint = ppr.Value;
return SamplerStatus.OK;
}
}
return SamplerStatus.Cancel;
}
protected override bool Update()
{
Point3d cen;
Vector3d vecX = new Vector3d(1.0, 0.0, 0.0);
Vector3d normal = new Vector3d(0.0, 0.0, 1.0);
Point2d[] inters = _line.IntersectWith(Mediatrice(Point3dTo2d(_secondPoint), Point3dTo2d(_dragPoint)));
if (inters != null)
{
cen = new Point3d(inters[0].X, inters[0].Y, 0.0);
_arc.Center = cen;
_arc.Radius = cen.DistanceTo(_dragPoint);
if (Clockwise(_firstPoint, _secondPoint, _dragPoint))
{
_arc.StartAngle = vecX.GetAngleTo(cen.GetVectorTo(_dragPoint), normal);
_arc.EndAngle = vecX.GetAngleTo(cen.GetVectorTo(_firstPoint), normal);
}
else
{
_arc.StartAngle = vecX.GetAngleTo(cen.GetVectorTo(_firstPoint), normal);
_arc.EndAngle = vecX.GetAngleTo(cen.GetVectorTo(_dragPoint), normal);
}
}
return true;
}
public Point3d GetPoint()
{
return _dragPoint;
}
}
[CommandMethod("Test")]
public void Test()
{
Point3d pt1;
Point3d pt2;
PromptPointOptions ppo = new PromptPointOptions("\nSpecifiy the first point: ");
ppo.AllowNone = false;
PromptPointResult ppr = ed.GetPoint(ppo);
if (ppr.Status == PromptStatus.OK)
{
pt1 = ppr.Value;
ppo.Message = "\nSpecify the second point: ";
ppo.AllowNone = false;
ppo.BasePoint = pt1;
ppo.UseBasePoint = true;
ppr = ed.GetPoint(ppo);
if (ppr.Status == PromptStatus.OK)
{
try
{
pt2 = ppr.Value;
pt1 = pt1.TransformBy(ed.CurrentUserCoordinateSystem);
pt2 = pt2.TransformBy(ed.CurrentUserCoordinateSystem);
Line2d med = Mediatrice(Point3dTo2d(pt1), Point3dTo2d(pt2));
Vector3d vec = pt1.GetVectorTo(pt2) / 2;
Arc ghost = new Arc(pt1 + vec, vec.Length, 0.0, pi);
ArcJig jig = new ArcJig(ghost, pt2, pt1, pt2, med);
PromptResult res = ed.Drag(jig);
if (res.Status == PromptStatus.OK)
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
btr.AppendEntity(ghost);
tr.AddNewlyCreatedDBObject(ghost, true);
tr.Commit();
}
}
else
ghost.Dispose();
}
catch(System.Exception ex)
{
ed.WriteMessage("\nError: " + ex.Message);
}
}
}
}
private static Line2d Mediatrice(Point2d p1, Point2d p2)
{
Vector2d vector = p1.GetVectorTo(p2);
Point2d midPt = p1 + (vector / 2);
return new Line2d(midPt, vector.TransformBy(Matrix2d.Rotation(pi / 2.0, p1)));
}
private static Point2d Point3dTo2d(Point3d pt)
{
return new Point2d(pt.X, pt.Y);
}
private static bool Clockwise(Point3d p1, Point3d p2, Point3d p3)
{
Vector3d vec1 = p1.GetVectorTo(p2);
Vector3d vec2 = p2.GetVectorTo(p3);
Vector3d norm = new Vector3d(0.0, 0.0, 1.0);
return vec1.GetAngleTo(vec2, norm) > pi;
}
private const double pi = 3.141592653589793;
}
}{code}