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.

Is it possible to check if a point(x,y,z) is on a surface or in free space?

i'm making a script that genrates some holes automatically.. I'll need to check if the polygon i'm extruding is in free space or on a surface? is that possible and how?
Tagged:

Best Answer

  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    edited February 2018 Answer ✓
    const distanceResult = evDistance(context, {"side0" : someFace, "extendSide0" : true, "side1" : somePoint});
    if (distanceResult.distance < TOLERANCE.zeroLength)
    {
        // somePoint lies on the underlying surface of someFace
    }
    else
    {
        // somePoint does not lie on the underlying surface of someFace<br>
    }

    'somePoint' can be a Query for a Vertex, a vector (like vector(1, 2, 3) * inch or the result of evVertexPoint), or even a Query for all the vertices of your polygon (the 'distance' will be the distance of the closest point, so by doing this you could tell if any of the points lie on the surface).

    Jake Rosenfeld - Modeling Team

Answers

  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    When you say 'Surface', do you mean a Query for a face?  If so you can use evDistance().  If the distance returned is less than 'TOLERANCE.zeroLength', than the point and face are touching.  If you use the 'extendSide<i>' option for evDistance, you can extend the input faces to their full (possibly infinite) underlying surface.

    https://cad.onshape.com/FsDoc/library.html#evDistance-Context-map
    Jake Rosenfeld - Modeling Team
  • frederik_larsen108frederik_larsen108 Member Posts: 9 EDU
    edited February 2018
    Yes i mean the query of a face :) What would you have as input in evDistance? and how do i check a certain point and not the entire face?
  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    edited February 2018 Answer ✓
    const distanceResult = evDistance(context, {"side0" : someFace, "extendSide0" : true, "side1" : somePoint});
    if (distanceResult.distance < TOLERANCE.zeroLength)
    {
        // somePoint lies on the underlying surface of someFace
    }
    else
    {
        // somePoint does not lie on the underlying surface of someFace<br>
    }

    'somePoint' can be a Query for a Vertex, a vector (like vector(1, 2, 3) * inch or the result of evVertexPoint), or even a Query for all the vertices of your polygon (the 'distance' will be the distance of the closest point, so by doing this you could tell if any of the points lie on the surface).

    Jake Rosenfeld - Modeling Team
  • frederik_larsen108frederik_larsen108 Member Posts: 9 EDU
    This works, but i would like to check if the point is within the face of the body... i tried to remove the "extendSide" part but then no point lies on the surface.. 
  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    @frederik_larsen108

    Could you provide a URL for a document that has an example of the issue you're facing? It would be easier to answer if I could see what's going on.
    Jake Rosenfeld - Modeling Team
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,714
    @frederik_larsen108Have you tried qContainsPoint?
    Senior Director, Technical Services, EMEAI
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,215
    qContainsPoint should work.  Removing extendSide0 should also work.  I can see a couple of issues with the units: for side1, the units in your vector are already length units -- multiplying by meter turns them into area (that's incorrect, but it shouldn't fix the problem).  In the comparison to zeroLength, you divide by millimiter, whereas zeroLength tolerance is intended for meters.
    If that doesn't help, try focusing on one of the points in your pointArray and displaying it and the points returned by evDistance using the debug function.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
Sign In or Register to comment.