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.

Creating 3D Points

billy2billy2 Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,014 PRO
edited June 2016 in FeatureScript
I've scanned this forum for code that does these, I haven't found any solutions.

3 cases
-at a vertex
-on an edge at cursor location
-on a surface at cursor location


case #1:
someone picks a vertex (I got this one working).

code for 3D point at a vertex:
const chinPt = evVertexPoint(context, {"vertex" : evaluateQuery(context, definition.chin)[0]});
opPoint(context, id + "chin", { "point" : chinPt * meter, "origin" : true });


create a 3d point at selected vertex:



case #2

someone picks along an edge

create a 3D point on edge at cursor location:



case #3

someone picks on a surface

create a 3D point on a surface at cursor location:


Comments

  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    There's no way to do this in Onshape right now. I'd say the main reason we don't have it is that our core focus is fully parametric design.

    Features like this don't fit as well in the parametric paradigm because the user has no control over exact coordinates (beyond eyeballing), and, when it comes time to update that point due to upstream changes to that edge or surface, there's no way to infer the original design intent. Did the user want it half an inch from one side? Two inches from the other? 20% along the line?

    See other discussion here.

  • billy2billy2 Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,014 PRO
    edited June 2016
    That's really unfortunate as I have a great little project I was hoping to do in OS with feature script. Not wanting to do it in SW and a 3D sketch.

    Parametrics has no meaning in what I'm doing. I'm working with imported geometry so there won't be any upstream changes. These models are surfaces so we've left the world of accuracy many moons ago and things that look good are surprising good enough. I believe geometry 1st, parametrics 2nd. I'm not needing a parametric solution. Just a 3D point on some 3D geometry.

    Can I sketch a 2D point on a sketch plane then query and find stuff under the point? Does evdistance give me this distance from a sketch plane to an edge at my 2D point location? I can add this to distance to the sketch and then transpose it to the world. This would work for me. I've been following the discussion on uv positions on a surface. But there's no how in these discussions. 

    Can you explain how this is done. I'm really want x,y,z in world coordinates. There is a solution, it is determinant. If I have to use a sketch to get there, hey, let's do it. Seems a little funky but if I can get the view matrix, I'll create a temporary sketch, place 2D point, do my math, get my 3D point coordinates, and clean up all the garbage and I'll have my 3D point.

    Can I query the current view matrix? I see world to sketch and sketch to world, but no world to view. If you're telling me I have to work on a 2D sketch, place my 2D point, run some math and get a normal distance to my edge/surface, transpose it back to world. Yes, a 3D point in world coordinates. Valid for only an instant which is good enough for me.

    Can this be done? I really want to place a 3D point on some 3D geometry. I don't care about parametrics.






  • billy2billy2 Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,014 PRO
    edited June 2016
    Ok so evDistance returns a minimal distance and not a normal distance to a plane which won't allow me to define a 3D point based on a 2D sketch.

    Looking for a way to return a vector with the following intersection:


    Search std lib for intersect and came up with this:

            var intersect = intersection(evSurfaceDefinition(context, {
                    "face" : definition.face
            }), evLine(context, {
                    "edge" : definition.line
            }));
            
            println("intersect " ~ intersect);

    intersection() won't work with a face, only a plane. So let's try an get a vector & a plane working:


    Ok, so featurescript returns LinePlaneInstersection which is a map kinda like an object in javascript?




    So intersect.LinePlaneIntersection.intersection should return a Vector?

    1. How do I extract the Vector out of LinePlaneIntersection? 
       It's intersect.intersection

    yahoo:




    2. How do I intersect with a face?
    3. Do you have a pretty print function for these maps when using println?





  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    evDistance between a Line and a surface query will give you a distance of zero when the (infinite) line passes through the surface. That result will also contain the point at which the distance is zero (i.e. the intersection point).

    If they intersect, that point will be the same on both sides of the result. But for when they don't intersect, you should choose whether you'd rather grab the point on the line closest to the surface, or the point on the surface closest to the line.

  • billy2billy2 Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,014 PRO
    Thanks Kevin-

    I'll play around with an infinite line, surface & evDistance. 


  • billy2billy2 Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,014 PRO


    I guess you can create 3D points on 3D geometry! The secret is in the evDistance() and forcing an infinite line through the 3D geometry. Kevin is right in that the line has to pass through the 3D geometry otherwise you'll get a minimal distance projection.

    The question now is how to create an infinite line inside OS from a skPoint? Shouldn't be that hard.

    Thanks Kevin,


  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,173
    You don't need an infinite line (and in fact you can't create one) -- you just need one that extends past the bounding box (computed using evBox3d with an appropriate coordinate system) -- and you can create one by passing two points into opFitSpline.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    edited June 2016
    Alternatively. you can just create the infinite Line as data, and use that Line as one of the sides to your evDistance call. No need to add that line to your context if you're just using it for calculation.

  • billy2billy2 Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,014 PRO
    Wow, thanks guys.

    Kevin I was wondering if I could use a direction vector call to evDistance. 


    Is a normalized 3D vector inside OS a 4x4 matrix? You can't create this from the UI right.

    Direction approach:
    I'll try this 1st and see if I can skip evBox3D. I'm assuming the normalized 3D Vector needs to be in world. Can I pass a 
    normalized vector from a sketch through one of your transforms and end up with a world direction?

    evBox3D approach:
    I was thinking of Ilya's approach. Just needed to look up how to make evBox3D work in the sketch coordinates. Take Z's from the evBox3D and construct 2 vectors in sketch coordinates based on point, move them to world and construct opFitSpline. I take it opFitSpline is world coordinates and will pass it into evDistance. Should be easy.




  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    For the direction, I would use
    evOwnerSketchPlane(...).normal

    Unfortunately you can't get the view matrix from inside FeatureScript. So the above relies on the user first making a sketch on a plane pointing in the direction they want. Perhaps you can think of a better heuristic but depending on the camera angle is not possible.

  • billy2billy2 Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,014 PRO
    edited June 2016
    Was hoping to pick 3D points but creating a sketch and using skpoints is ok and will work. It also follows OS parametric paradigm.

    I was wondering about view manipulation from featurescript. My thought was to create a sketch on the fly based on the view and the user would never know how the 3D points were created. Oh well, what a crazy idea. 

    This solution I now have will work fine.

    Thanks again,

Sign In or Register to comment.