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.

How to find all intersections points of an edge chain with a plane

brad_phelanbrad_phelan Member Posts: 89 ✭✭
edited February 2018 in FeatureScript
For example I have the loop of a face by

   var loop = qLoopEdges(def.face);

and I have a plane p

   var p = plane(....);

and I would like to find all the intersection points of this loop with the plane. Is there an inbuilt function to do this?

More precisley if I have selected the sketch face in grey I would like to find the intersection of all the dashed planes with the loop of the face. The dashed planes are not sketched by hand they just represent the planes I wish to cut with.



The spacing and direction of the planes can be assumed to be known. 

var direction = vector(...);
var spacing = ...;

For each line I want the list of intersection points with this loop.
Tagged:

Comments

  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    don't think there is a built in way to find multiple intersections if each edge can have more than one. i can only imagine some numeric solution - evaluate an array of points along the edge, evaluate an array of signed distanses from those points to the plane, then iterating by consecutive pairs of points of those array choose those pairs that change the sign of distance, and then start binary search in the found range for each pair of points
  • brad_phelanbrad_phelan Member Posts: 89 ✭✭
    What about finding the edge that is the intersection of a face and a plane? Is that possible?
  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    edited February 2018
    if the assumption is that each edge of the loop has the one or less intersections with each plane as it is on your picture than you can evaluateQuery() of bounding edges and use evDistance in the loop for each edge and for each plane
    What about finding the edge that is the intersection of a face and a plane? Is that possible?
    you can look for builtin project curve feature in standart library source, it uses some hidden parameter in opBoolean to find intersection curve of two surfaces
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,206
    It's hard to say what the best performing solution would be.  One thing I'd try is (working around some limitations we have w.r.t. wire bodies) extrude both the lines and the loop in the normal direction and use opSplit to split the sheets produced by the lines with the sheet produced by the loop.  Then the endpoints of the resulting sheets (say filtered to just those on the original plane) would correspond to the intersections.

    Another option is to require your loop to consist of monotone segments w.r.t. the direction perpendicular to the lines, group them into monotone chains, and do evDistance between each line and each chain -- I think I've seen a version of your code that does that -- any reason that's not working for you?

    One potential performance pitfall is the time to construct the array of lines, say for evDistance: it's fastest to construct one line and then construct the others by copying it and modifying just one of the coordinates on the origin.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • brad_phelanbrad_phelan Member Posts: 89 ✭✭
    The restriction should be that the shape is monotone on the left and right sides. So the below is allowed


    and the following are not



    The challenge would be to identify the left chain and the right chain automatically from the face selection given the above monotone restriction.



    Once the two monotone chains are identified then I could use the evDistance trick ( which I stole from konstantin's code )
  • brad_phelanbrad_phelan Member Posts: 89 ✭✭
    I considered forcing the user to select the left hand side and the right hand side of the panel manually but this doesn't work in onshape. You can see why in this video.

    https://dl.dropboxusercontent.com/s/o1lytztzcp4aior/2018-02-07_15-12-14.mp4

    You can select a face from a sketch but you can't select the sub part of an edge that belongs to only one face. This is a bit onerous on the user to force them to split their edges all the time.

  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,206
    Decomposing into chains is a little tricky.  I'd do the following:

    Use qFarthestAlong in two directions perpendicular to your line direction to get the chain endpoints.  Use constructPath, passing one of the endpoints as referenceGeometry to sort the loop in order around the face.  Walk along the edges in the returned path, until you hit one that is adjacent to the other endpoint -- that is the last edge in your first chain, and the rest of the path is the second chain.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    if the task is to separate edges of the loop into two groups ("left" and "right") i would construct the path and iterate through it edges evaluating edge direction, if direction gives positive dot() with yAxis of the sketch (or any other reference direction vector) it would be in the "left" group else - in the right
  • brad_phelanbrad_phelan Member Posts: 89 ✭✭
    I think the trick is to use

    evTangentLines on the edge using the arc length parameterization. That will give me a series of points around the loop and their tangents. 

    (1) To validate check that there are only two tangent flips from up to down
    (2) Split the returned curves into two groups based on if their tangent is up or down.


  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,206
    @konstantin_shiriazdanov That also works, you just have to be careful of the "flipped" flag in the path.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
Sign In or Register to comment.