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.

coordinate system with one of its axes directed toward plate

urszula_wachulskaurszula_wachulska Member Posts: 20 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




Best Answers

  • NeilCookeNeilCooke Posts: 1,921
    Accepted Answer
    I 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.
    Neil Cooke, Director of Technical Marketing, Onshape Inc.
  • ilya_baranilya_baran Posts: 888
    Accepted Answer
    Hi,

    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))
    Hope this helps.
    Ilya Baran \ Director of FeatureScript \ Onshape Inc

Answers

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 1,921
    Accepted Answer
    I 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.
    Neil Cooke, Director of Technical Marketing, Onshape Inc.
  • urszula_wachulskaurszula_wachulska Member Posts: 20 PRO
    Thank you very much @NeilCooke !
    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.
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 888
    Accepted Answer
    Hi,

    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))
    Hope this helps.
    Ilya Baran \ Director of FeatureScript \ Onshape Inc
  • urszula_wachulskaurszula_wachulska Member Posts: 20 PRO
    Yes, this helped a lot - writing  0 * meter solved my issue. Thank you for explanation :)

Sign In or Register to comment.