.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Create Arc with StartPoint EndPoint Radius?

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
dynamicscope
6906 Views, 6 Replies

Create Arc with StartPoint EndPoint Radius?

[Managed ObjectARX 2007 with C#]

 

I am trying to create an arc with start point, end point, and radius.

So that if the arc gets drawn, I going to use the center point.

 

Well, I guess I can use "SendStringToExecute()" or "SendCommand()" and "ObjectAppended" eventhandler to get the arc object.

But this approach seems bit messy, so I am wondering if there is any other simple way.

6 REPLIES 6
Message 2 of 7
hgasty1001
in reply to: dynamicscope

Hi,

 

The problem is that the arc constructor use angles intead points, so you have to calculate the angles from the points, check this link: http://www.theswamp.org/index.php?topic=40382.msg456904#msg456904

 

Gaston Nunez

Message 3 of 7

Creating of arc with startpoint, endpoint and radius can not be unique. Such arcs can be either two or none.

07-02-2013 17-23-46.png

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 4 of 7

As you would know AutoCAD already provides such feature. (Drawing Arc with Start point + End point + Radius).

So I was wondering if there is any API I can use.

 

It looks like I have to manually calculate angles and stuff.

Hmm.....

Message 5 of 7
Hallex
in reply to: dynamicscope

Then you can to look at acedCmd and use the same command promts

as per as in ARC command , just an idea

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 6 of 7

OK. Try this code (as usually minimum error checking done):

[CommandMethod("ARC2PR", CommandFlags.Modal)]
public static void Arc2PointsRadius()
{
  Document doc = Application.DocumentManager.MdiActiveDocument;
  Editor ed = doc.Editor;
  PromptPointResult pRes1 = ed.GetPoint("\nFirst point: ");
  if (pRes1.Status != PromptStatus.OK) return;
  PromptPointResult pRes2 = ed.GetPoint("\nSecond point: ");
  if (pRes2.Status != PromptStatus.OK) return;
  PromptDistanceOptions prDist = 
	new PromptDistanceOptions("\nRadius: ");
  prDist.BasePoint = pRes2.Value;
  prDist.UseBasePoint = true;
  PromptDoubleResult rRes = ed.GetDistance(prDist);
  if (rRes.Status != PromptStatus.OK) return;
  Matrix3d ucsMat = ed.CurrentUserCoordinateSystem;
  Vector3d vNormal = ucsMat.CoordinateSystem3d.Zaxis;
  Point3d pStart = pRes1.Value.TransformBy(ucsMat); // Start point in WCS
  Point3d pEnd = pRes2.Value.TransformBy(ucsMat); // End point in WCS
  //  Finding center point of arc. 
  CircularArc3d circ1 = new CircularArc3d(pStart, vNormal, rRes.Value);
  CircularArc3d circ2 = new CircularArc3d(pEnd, vNormal, rRes.Value);
  Point3d[] pts = circ1.IntersectWith(circ2);
  circ1.Dispose(); circ2.Dispose();
  if (pts.Length < 2) {
    ed.WriteMessage("\nInvalid arguments"); return;
  }
  Point3d pCenter = pts[0];
  Vector3d v1 = pStart - pCenter, v2 = pEnd - pCenter;
  if (v1.CrossProduct(v2).DotProduct(vNormal) < 0) {
    pCenter = pts[1];
  }
  CircularArc3d cCirc = new CircularArc3d(pCenter, vNormal, rRes.Value);
  double parStart = cCirc.GetParameterOf(pStart);
  double parEnd   = cCirc.GetParameterOf(pEnd);
  double parMid = (parStart + parEnd) * 0.5;
  Point3d pMid = cCirc.EvaluatePoint(parMid);
  cCirc.Dispose();
  CircularArc3d cArc = new CircularArc3d(pStart, pMid, pEnd);
  double angle = 
	cArc.ReferenceVector.AngleOnPlane(new Plane(cArc.Center,cArc.Normal));
  Arc arc = 
	new Arc(cArc.Center, cArc.Normal, 
		cArc.Radius, cArc.StartAngle + angle,  cArc.EndAngle + angle);
  cArc.Dispose();
  using (Transaction tr = doc.TransactionManager.StartTransaction()) {
    BlockTableRecord btr = 
	tr.GetObject(doc.Database.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
    btr.AppendEntity(arc);
    tr.AddNewlyCreatedDBObject(arc, true);
    tr.Commit();
  }
}

 

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 7 of 7

WOW!!!

Didn't expect the answer code.

It works great for me and it solves my problem.

 

Plus, I learned a lot from your code.

There are so many APIs I can utilize in ObjectARX.

Awesome!!

 

Thank you always~ 🙂

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost