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.

Querying faces/objects located on one side of a plane

yurii_haiovyiyurii_haiovyi Member Posts: 8
Is there any way to query faces that are located on one or another side of a given plane? qSplitBy doesn't return unaffected faces from faceTargets query, so there's no way of knowing what's where.

Thanks!

Comments

  • mahirmahir Member, Developers Posts: 1,309 ✭✭✭✭✭
    I'm hoping there is a simpler method that someone can come up with, but I have a couple ideas.

    You could use a dummy plane (PlaneB) that is just slightly offset to the wrong side of the original plane (PlaneA). Then, for each object of interest you can perform evDistance to both planes. If an object is closer to PlaneA than PlaneB, then it's on the right side. 

    Alternatively, you can create a giant dummy volume bordering your plane and query for all objects that intersect with it.
  • MichaelPascoeMichaelPascoe Member Posts: 2,012 PRO
    edited January 2023

    Here is a similar approach to what @mahir was suggesting. This approach takes the centroid of every part and checks if it is on the positive side or negative side of the plane. The key here is taking that centroid vector and getting the Z value from it. Vectors are stored in array format like this [x, y, z]. To get the Z value from it would look like this centroidVector[2]. Then you can determine if it is positive or negative relative to the measuring plane.

    I have placed this inside of a function so that all you need to do is import the function into your project to be able to use the function in your feature definition. 

    https://cad.onshape.com/documents/3b7cb6cdfff8caa4fde98d8e/w/e656ed116b6492f6e01625fd/e/eadcf365f911e7410b5d0e23?renderMode=0&uiState=63bd72f62e5bc928d81b9c1b


    Place this at the top of your FeatureScript: 
    import(path : "3b7cb6cdfff8caa4fde98d8e/9d6b44408c25f318c0d42e1b/36ee53f33bea2a368d4066a5", version : "7ce6f473ce4f41d1a7b55134");

    Then, you can use the function qThisSidePascoe() like this within your feature. This will return the entities on either side of the plane you give it:
    const entities = qThisSidePascoe(context, query, plane, oppositeDirection);

    If you don't want to import the function and would rather do it manually, here is how you can do that:
            var everything = qAllNonMeshSolidBodies();
            everything = evaluateQuery(context, everything);
            
            const evalPlane = evPlane(context, {
                    "face" : definition.plane
            });
    
            var entities = qNothing();
    
            for (var i = 0; i < size(everything); i += 1)
            {
                const centroid = evApproximateCentroid(context, {
                            "entities" : everything[i]
                        });
                
                const localVector = worldToPlane3D(evalPlane, centroid);
    
                const sign = definition.oppositeDirection ? -1 : 1;
    
                if (localVector[2] * sign >= 0)
                {
                    entities = qUnion([entities, everything[i]]);
                }
            }
            debug(context, entities, DebugColor.CYAN);


    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   Learn How to FeatureScript Here 🔴
Sign In or Register to comment.