Hello everyone,
I have some trouble recreating a Ellipse. Here's the scene, there is a Ellipse whose normal is (0,0,-1). I want to recreate the Ellipse whose normal is (0,0,1). How should I change the Ellipse's propertites?
public static EllipticalArc2d AsEllipticalArc2d(this EllipticalArc3d ellipticalArc)
{
EllipticalArc2d result = null;
if (ellipticalArc.Normal.IsEqualTo(Vector3d.ZAxis))
{
result = new EllipticalArc2d(ellipticalArc.Center.AsPoint2d(),
ellipticalArc.MajorAxis.AsVector2d(), ellipticalArc.MinorAxis.AsVector2d(),
ellipticalArc.MajorRadius, ellipticalArc.MinorRadius, ellipticalArc.StartAngle, ellipticalArc.EndAngle);
}
else
{
result = new EllipticalArc2d(ellipticalArc.Center.AsPoint2d(),
ellipticalArc.MajorAxis.AsVector2d(), ellipticalArc.MinorAxis.AsVector2d(),
ellipticalArc.MajorRadius, ellipticalArc.MinorRadius, ellipticalArc.StartAngle, ellipticalArc.EndAngle);
}
return result;
}
But the result appear in other quadrants.
As the upper pic shows, if the normal of Ellipse is (0,0,1),result is right. But if the normal of Ellipse is (0,0,-1),result is wrong.
Solved! Go to Solution.
Solved by _gile. Go to Solution.
What happens when you change the Start- and EndAngle when the normal is -1?
So:
result = new EllipticalArc2d(ellipticalArc.Center.AsPoint2d(),
ellipticalArc.MajorAxis.AsVector2d(), ellipticalArc.MinorAxis.AsVector2d(),
ellipticalArc.MajorRadius, ellipticalArc.MinorRadius, ellipticalArc.EndAngle, ellipticalArc.StartAngle);
Hi,
This seems to work.
public static EllipticalArc3d NegateNormal(this EllipticalArc3d source) =>
new EllipticalArc3d(
source.Center,
source.MajorAxis,
source.MinorAxis.Negate(),
source.MajorRadius,
source.MinorRadius,
2.0 * Math.PI - source.EndAngle,
2.0 * Math.PI - source.StartAngle);
Or, to directly replace the selected ellipse:
Extension method:
public static Ellipse NegateNormal(this Ellipse source) =>
new Ellipse(
source.Center,
source.Normal.Negate(),
source.MajorAxis,
source.RadiusRatio,
2.0 * Math.PI - source.EndAngle,
2.0 * Math.PI - source.StartAngle);
Testing command:
[CommandMethod("TEST")]
public static void Test()
{
var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
var peo = new PromptEntityOptions("\nSelect Ellipse: ");
peo.SetRejectMessage("\nSelected object is not an ellipse.");
peo.AddAllowedClass(typeof(Ellipse), true);
var per = ed.GetEntity(peo);
if (per.Status != PromptStatus.OK)
return;
using (var tr = db.TransactionManager.StartTransaction())
{
var source = (Ellipse)tr.GetObject(per.ObjectId, OpenMode.ForWrite);
var ellipse = source.NegateNormal();
var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
curSpace.AppendEntity(ellipse);
tr.AddNewlyCreatedDBObject(ellipse, true);
source.SwapIdWith(ellipse.ObjectId, true, true);
source.Erase();
tr.Commit();
}
}
Can't find what you're looking for? Ask the community or share your knowledge.