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.
coordinate system with one of its axes directed toward plate
urszula_wachulska
Member Posts: 21 PRO
Hello,
I start my adventure with feature script and need some help.
I wanted to create coordinate system with one of its axes directed toward plate.
My input data are two plate edges - long edge and plate width.
Here is what I thought feature script should do:
1. get end points of plate width - point 1 and point 2
2. create plane that contains long edge and is perpendicular to plate width - checkPlane
3. check distance from point 1 and checkPlane
4. create vector - if point 1 lies on checkPlane vector should be from point1 to point 2 - otherwise vector should be from point2 to point1
5. then create coordinate system based on long edge origin, long edge direction and previously created vector
Until step no 4 everthing works, but created vector always points in the same direction, no matter which edges I choose.
I would appreciate pointing my mistake and way of fixing it.
Here is script of point 4:
var gVector;
if (checkDistance==0)
{
gVector = normalize(gPoint1-gPoint2);
}
else
{
gVector = normalize(gPoint2 - gPoint1);
}
Here is link to document:
https://cad.onshape.com/documents/fac80ab085093029274a32a1/v/36c4e4b7acbd884df07409e8/e/220f6478d80cca549309f77b
I start my adventure with feature script and need some help.
I wanted to create coordinate system with one of its axes directed toward plate.
My input data are two plate edges - long edge and plate width.
Here is what I thought feature script should do:
1. get end points of plate width - point 1 and point 2
2. create plane that contains long edge and is perpendicular to plate width - checkPlane
3. check distance from point 1 and checkPlane
4. create vector - if point 1 lies on checkPlane vector should be from point1 to point 2 - otherwise vector should be from point2 to point1
5. then create coordinate system based on long edge origin, long edge direction and previously created vector
Until step no 4 everthing works, but created vector always points in the same direction, no matter which edges I choose.
I would appreciate pointing my mistake and way of fixing it.
Here is script of point 4:
var gVector;
if (checkDistance==0)
{
gVector = normalize(gPoint1-gPoint2);
}
else
{
gVector = normalize(gPoint2 - gPoint1);
}
Here is link to document:
https://cad.onshape.com/documents/fac80ab085093029274a32a1/v/36c4e4b7acbd884df07409e8/e/220f6478d80cca549309f77b
0
Best Answers
-
NeilCooke Moderator, Onshape Employees Posts: 5,683I haven't looked at your code, but you could assume that the thickness is always going to be less than the front face area, then use qEdgeAdjactent to find both faces then qLargest to get the front face then create a plane with a normal opposite to the face.Senior Director, Technical Services, EMEAI2
-
ilya_baran Onshape Employees, Developers, HDM Posts: 1,212Hi,
I can see two possible issues:
First, checkDistance is a length, and 0 is a number. They will never compare equal. You can use 0 * meter instead.
Second, you should do a tolerant comparison in case checkDistance is not exactly zero because of floating point roundoff error. The check I would use is something like:if (tolerantEquals(checkDistance, 0 * meter))<br>
Hope this helps.Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc1
Answers
Your way works great and is so much shorter
Although for the sake of learning purposes I would love to know, why my way hasn't worked as expected. So it would be great if somebody has some free time and could explain it to me.
I can see two possible issues:
First, checkDistance is a length, and 0 is a number. They will never compare equal. You can use 0 * meter instead.
Second, you should do a tolerant comparison in case checkDistance is not exactly zero because of floating point roundoff error. The check I would use is something like:
if (tolerantEquals(checkDistance, 0 * meter))<br>
Hope this helps.