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

Recreate a Ellipse by changing its normal

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
哀家爆
423 Views, 4 Replies

Recreate a Ellipse by changing its normal

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.

niaxiapiaF4Z8Y_0-1638875688490.png

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. 

4 REPLIES 4
Message 2 of 5
R.Gerritsen4967
in reply to: 哀家爆

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);

 

Message 3 of 5
_gile
in reply to: 哀家爆

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);


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 4 of 5
_gile
in reply to: _gile

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();
        }
    }

 

 

 

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 5 of 5
哀家爆
in reply to: _gile

Thanks for your reply. Your code works very well!

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report