Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- 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 "?
MichaelPascoe
Member Posts: 1,979 PRO
Is there an efficient way to query all bodies on one side of a plane?
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
0
Best Answers
-
kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565Not 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.2 -
Jacob_Corder Member Posts: 137 PROyou 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.
1 -
christopher_dziuba Member Posts: 57 ✭✭
To anyone who finds this thread in the future there is now a query for this in the FS library:
qInFrontOfPlane
2
Answers
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.
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
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.
To anyone who finds this thread in the future there is now a query for this in the FS library:
qInFrontOfPlane