Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. Be respectful, on topic and if you see a problem, Flag it.

If you would like to contact our Community Manager personally, feel free to send a private message or an email.

skEllipticalArc between two points

arthur_petersarthur_peters Member Posts: 19
Is there a way to have skEllipticalArc run between two points on the ellipse?

I already have the ellipse "description" (center, major, minor, axis) and the points that are on the ellipse (they are actually how the ellipse description is computed). However, I have not been able to figure out how to compute the start and end parameters for the points. I suspect the parameters is represented a fraction of the perimeter, but ellipse perimeter are terrible and I thought I would ask here before having to do numerical integration in FeatureScript. ;-)

PS: I'm doing ellipse fitting to points and tangents. I'm doing it directly since lofted surfaces seem to behave poorly when the provides use splines. I was unable to reliably use shell or thicken tools, even outward which should always be possible. Using approximations with circular arcs works better and I'm hoping ellipses will also work well and match my original shape better (an airfoil).



- Arthur (he/him)

Comments

  • Jacob_CorderJacob_Corder Member Posts: 65 PRO
    you could create an ellipse and then use evDistance to get the start and end parameters. then use those. It would require either a sketch to delete or 

    Try this. I havent tested it but it might work, it should work.  the only thing i am not sure of is if the ellipse wants arcLengthParameterization to true or false or if it doesn't matter.
     var stParam;
        var endParam;
        var startRef; //something to use to get the start param"
        var endRef; //something to use to get the end param"
        var majorRad =2*inch;
        var minorRad = 1*inch;
        var pln = plane(vector(0,0,0)*inch,vector(0,0,1));
        startFeature(context, id+"testEllipse");
        try
        {
              var testSk = newSketchOnPlane(context, id + "testEllipse", {
                "sketchPlane" : pln
            });
            skEllipse(testSk, "ellipse", {
                    "center" : vector(0, 0) * inch,
                    "majorRadius" : majorRad,
                    "minorRadius" : minorRad
            });
            skSolve(testSk);
            var stDist =evDistance(context, {
                    "side0" : sketchEntityQuery(id + "testEllipse", EntityType.EDGE, "ellipse"),
                    "side1" : startRef,
                    "arcLengthParameterization":false
            });
            var endDist =evDistance(context, {
                    "side0" : sketchEntityQuery(id + "testEllipse", EntityType.EDGE, "ellipse"),
                    "side1" : endRef,
                    "arcLengthParameterization":false
            });
            stParam = stDist.sides[0].parameter;
            endParam = endDist.sides[0].parameter;
        }
        abortFeature(context,id+"testEllipse");
        
        var sk = newSketchOnPlane(context, id + "ellipseArc", {
                "sketchPlane" : plane(vector(0, 0, 0) * inch, vector(0, 0, 1))
            }); 
        skEllipticalArc(sk, "ellipticalArc1", {
                "center" : vector(0, 0) * inch,
                "majorAxis" : normalize(vector(1, 1)),
                "minorRadius" : minorRad,
                "majorRadius" :majorRad,
                "startParameter" : stParam,
                "endParameter" : endParam
        });
        skSolve(sk);


  • arthur_petersarthur_peters Member Posts: 19
    Thanks. I wondered about this. I just assumed that creating and destroying a sketch was absurdly more expensive than a bunch of math. I'll run with your recommendation. It's a good one.
    - Arthur (he/him)
  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    Thanks. I wondered about this. I just assumed that creating and destroying a sketch was absurdly more expensive than a bunch of math. I'll run with your recommendation. It's a good one.
    This is some counterintuitive thing that you will find everywhere in featurescript, it turns out that often its quicker to reduce your computational math problem to evaluation on geometrical entities. This is mostly because those seemingly heavy abstractions are processed with highly optimized and performant core.

  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,120
    For skEllipticalArc the "non-arclength" parameterization is the one you'd expect:

    R * cos(t * 2 * PI)
    r * sin(t * 2 * PI)

    As t runs from 0 to 1 for a full ellipse.  So no need for numerical integration; scaling, followed by atan2 is the thing to use here.  It should also be significantly faster than creating an extraneous sketch (if you already had an ellipse, it'd be faster to use built-in projection methods, but creating a new sketch has non-trivial overhead).
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • arthur_petersarthur_peters Member Posts: 19
    Does skEllipticalArc take an undocumented argument arcLengthParameterization? Or does skEllipticalArc use the "non-arc length" parameterization by default?
    - Arthur (he/him)
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,120
    It uses "non-arclength" parameterization when specifying start and end.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • arthur_petersarthur_peters Member Posts: 19
    Thanks!! This all works. I used it to do this: https://cad.onshape.com/documents/a3fa3ca417afcdc0464cda31/v/631d0a6f6b6a3e6203881d38/e/189464e90615c39820b70d1a I'm happy with it. No idea if it's actually useful, but it mostly works as expected. :smile:

    - Arthur (he/him)
Sign In or Register to comment.