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.

Howto set a point/ball into the center of mass?

wolfgang_maierwolfgang_maier Member Posts: 39 ✭✭✭
Hello,

howto set a point/ball into the center of mass of a solid.

regards
Wolfgang

Comments

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,686
    This will give you an approximate center:

    FeatureScript 877;
    import(path : "onshape/std/geometry.fs", version : "877.0");
    
    annotation { "Feature Type Name" : "C of G" }
    export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            annotation { "Name" : "Select part", "Filter" : EntityType.BODY && BodyType.SOLID, "MaxNumberOfPicks" : 1 }
            definition.Part is Query;
        }
        {
            var point = evApproximateCentroid(context, { "entities" : definition.Part });
            var sketch = newSketchOnPlane(context, id, { "sketchPlane" : plane(point, vector(0, 0, 1)) });
            var pt = skPoint(sketch, "point1", { "position" : vector(0, 0) * meter });  
            skSolve(sketch);       
            debug(context, point);
        });
    


    Senior Director, Technical Services, EMEAI
  • billy2billy2 Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,068 PRO
    @NeilCooke this ones a keeper

    This one should be published, good job!



  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,686
    Thanks to @Jake_Rosenfeld for pointing out the error of my ways... this is a much simpler solution...

    FeatureScript 877;
    import(path : "onshape/std/geometry.fs", version : "877.0");
    
    annotation { "Feature Type Name" : "C of G" }
    export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            annotation { "Name" : "Select part", "Filter" : EntityType.BODY && BodyType.SOLID, "MaxNumberOfPicks" : 1 }
            definition.Part is Query;
        }
        {
            opPoint(context, id + "point1", { "point" : evApproximateCentroid(context, { "entities" : definition.Part })});
        });


    Senior Director, Technical Services, EMEAI
  • EvanReeseEvanReese Member, Mentor Posts: 2,136 ✭✭✭✭✭
    @NeilCooke
    why does the documentation say "Warning: This is an approximate value and it is not recommended to use this for modeling purposes". Any insight into what makes it "approximate"?
    Evan Reese
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,686
    @Evan_Reese - that is all that is provided by Parasolid, so hence the warning. You would think a solid modeling kernel would give you a very precise value, but apparently not. If you look at mass properties, we show the +/- deviation that is returned from Parasolid. The centroid would have similar deviations based upon the model complexity.
    Senior Director, Technical Services, EMEAI
  • EvanReeseEvanReese Member, Mentor Posts: 2,136 ✭✭✭✭✭
    @NeilCooke
    Thanks for the answer. It definitely is strange to me, and now I have no idea how much to trust it. I guess I'll just avoid it for life-and-death designs  :#. I made a feature that places a mate connector there. It's public here: https://cad.onshape.com/documents/e5f0ac7e68b8ac1794dc8a8d/w/a05b9505cb476fcb7d78e6a5/e/ae4e26f2c8201d3259caab0c
    Evan Reese
Sign In or Register to comment.