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.

# Query "bodies this side of plane "?

Member Posts: 1,805 PRO
Is there an efficient way to query all bodies on one side of a plane?

CADSharp  -  We make custom features and integrated Onshape apps!   cadsharp.com/featurescripts 💎
Tagged:

• Onshape Employees, Developers, HDM Posts: 565
Not with just a query.

A simple solution is to just evaluate all part bounding boxes and check the bounds directly. To make it faster, you could evaluate 1 bound instead of 6 with a clever evDistance: Evaluate evDistance between each body and far-off plane pointing toward the desired split plane, e.g. plane(vector(-500, 0, 0) * meter, X_DIRECTION). A resulting distance over 500 meters means the body is fully on the positive-x side of the plane YZ plane.

Neither way will win any award for efficiency but they shouldn't be prohibitively time-consuming unless there are thousands of parts.
• Member Posts: 131 PRO
you could use evdistance on all the bodies. then get the direction between the evdistance side points.

var offsetPlane = plane(plane.origin + (plane.normal * 0.1*millimeter),plane.normal,plane.x);
for(var i=0;i<size(bodies);i+=1)
{
var dist = evDistance(context,{
"side0":plane,
"side1":body[i]});
if(tolerantEquals(dist.distance, 0*meter)
{
//Re run it with the offset plane to detect if it is just touching the body or if it is intersecting it.
dist =  evDistance(context,{
"side0":offsetPlane ,
"side1":body[i]});
//If this returns > 0 meter then you know that its touching the original plane but not this one. this tells you its behind your plane but touching your            plane. Adjust the offset plane distance to fine tune to your application.
}
if(tolerantEquals(dist.distance,0*meter)==false)
{
var directionTo = normalize( dist.sides[1].point- dist.sides[0].point );
if(angleBetween(directionTo,plane.normal) > angleBetween(directionTo,plane.normal*-1)
{
// this should be on the back side of the plane.
}
}
}

my logic may be flipped in here but the point is to get the mid distance direction from the plane to each point on the bodies to determine if they are in front or in back of the plane.

I think.

• Onshape Employees, Developers, HDM Posts: 565
Not with just a query.

A simple solution is to just evaluate all part bounding boxes and check the bounds directly. To make it faster, you could evaluate 1 bound instead of 6 with a clever evDistance: Evaluate evDistance between each body and far-off plane pointing toward the desired split plane, e.g. plane(vector(-500, 0, 0) * meter, X_DIRECTION). A resulting distance over 500 meters means the body is fully on the positive-x side of the plane YZ plane.

Neither way will win any award for efficiency but they shouldn't be prohibitively time-consuming unless there are thousands of parts.
• Member Posts: 1,805 PRO

CADSharp  -  We make custom features and integrated Onshape apps!   cadsharp.com/featurescripts 💎
• Member Posts: 131 PRO
you could use evdistance on all the bodies. then get the direction between the evdistance side points.

var offsetPlane = plane(plane.origin + (plane.normal * 0.1*millimeter),plane.normal,plane.x);
for(var i=0;i<size(bodies);i+=1)
{
var dist = evDistance(context,{
"side0":plane,
"side1":body[i]});
if(tolerantEquals(dist.distance, 0*meter)
{
//Re run it with the offset plane to detect if it is just touching the body or if it is intersecting it.
dist =  evDistance(context,{
"side0":offsetPlane ,
"side1":body[i]});
//If this returns > 0 meter then you know that its touching the original plane but not this one. this tells you its behind your plane but touching your            plane. Adjust the offset plane distance to fine tune to your application.
}
if(tolerantEquals(dist.distance,0*meter)==false)
{
var directionTo = normalize( dist.sides[1].point- dist.sides[0].point );
if(angleBetween(directionTo,plane.normal) > angleBetween(directionTo,plane.normal*-1)
{
// this should be on the back side of the plane.
}
}
}

my logic may be flipped in here but the point is to get the mid distance direction from the plane to each point on the bodies to determine if they are in front or in back of the plane.

I think.