Daniel I ran yours and the center isn't (50,25,0), maybe I didn't do it right.
I have messed with arcs a bit and they are pretty tricky.
Below is an attempt to add an arc using either ucs points or world points.
I had the hardest time with it as I was using
double startAng = Vector3d.XAxis.GetAngleTo(StartP - Cen);
and GetAngle does'nt work over 180 degrees (rotten thing to do, acad).
This works in 3d as far as I have tested, however the function NormalFromPoints
will give a different normal (reversed) if you change the order of the points you supply it.
This is a lot like fixo's code. (Fatty)
using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;
static public Arc ArcFromCenterWcs(Point3d Cen, Point3d StartP, Point3d EndP)
//3 point arc from 3 Wcs points
{
Document doc = acadApp.DocumentManager.MdiActiveDocument;
Matrix3d ucs = doc.Editor.CurrentUserCoordinateSystem;
Vector3d norm;
if (Cen.Z == 0 && StartP.Z == 0 && EndP.Z==0)
norm = Vector3d.ZAxis;
else
norm = NormalFromPoints(Cen,StartP, EndP);
double Rad = Cen.DistanceTo(StartP);
Plane pn =new Plane(Cen, norm);
double startAng = (StartP - Cen).AngleOnPlane(pn);
double endAng = (EndP - Cen).AngleOnPlane(pn);
Arc oArc = new Arc(Cen, Vector3d.ZAxis, Rad, startAng, endAng);
oArc.Normal = norm;
oArc.ColorIndex = 1;
oArc = AddArc(oArc);
return oArc;
}
static public Arc ArcFromCenter(Point3d Cen, Point3d StartP, Point3d EndP)
//3 point arc from 3 ucs points
{
Document doc = acadApp.DocumentManager.MdiActiveDocument;
Matrix3d ucs = doc.Editor.CurrentUserCoordinateSystem;
double Rad = Cen.DistanceTo(StartP);
CoordinateSystem3d cs = ucs.CoordinateSystem3d;
Plane pn = new Plane(); //world plane
double startAng = (StartP - Cen).AngleOnPlane(pn);
double endAng = (EndP - Cen).AngleOnPlane(pn);
Arc oArc = new Arc(Cen,Vector3d.ZAxis, Rad, startAng, endAng);
oArc.TransformBy(ucs);
oArc = AddArc(oArc);
return oArc;
}
static public Arc AddArc(Arc oArc)
{
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = tr.GetObject
(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord btr = tr.GetObject
(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
btr.AppendEntity(oArc);
tr.AddNewlyCreatedDBObject(oArc, true);
tr.Commit();
}
return oArc;
}
static public Vector3d NormalFromPoints(Point3d p0, Point3d p1, Point3d p2)
//n = u×v = (V1-V0)×(V2-V0)
{
double Unit;
//Get distance from zero
Point3d x = new Point3d(p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z);
Point3d y = new Point3d(p2.X - p0.X, p2.Y - p0.Y, p2.Z - p0.Z);
//get CrossProduct
Vector3d n = new Vector3d(x.Y * y.Z - x.Z * y.Y, x.Z * y.X - x.X * y.Z, x.X * y.Y - x.Y * y.X);
//Convert to unit normal
Unit = Math.Sqrt(n.X * n.X + n.Y * n.Y + n.Z * n.Z);
n = new Vector3d(n.X / Unit, n.Y / Unit, n.Z / Unit);
if (n.X == 0 && n.Y == 0 && n.Z == -1) n = new Vector3d(0, 0, 1);
return n;
}