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.

Plane tangent and normal to surface?

MichaelPascoeMichaelPascoe Member Posts: 1,979 PRO
I'm trying to place a plane consistently on multiple types of faces to use in a transform. I can get a plane that is normal to the selected face, but I keep getting stuck.

The plane needs the following conditions:
  • Origin: middle of selected curve/edge.
  • Normal: same direction as curve/edge.
  • X-axis: always facing toward the selected face not away from it.
Is there simple way to do this?

        var loopedEdges = qLoopEdges(definition.face);

        var evalLoopedEdges = evaluateQuery(context, loopedEdges);

        var normalPlane = evFaceTangentPlaneAtEdge(context, {
                "edge" : evalLoopedEdges[0],
                "face" : definition.face,
                "parameter" : .5,
                "usingFaceOrientation" : true
            });

My current attempts end up either not aligned with the chosen edge or facing away from the selected face.









Learn more about the Gospel of Christ  ( Here )

CADSharp  -  We make custom features and integrated Onshape apps!   Learn How to FeatureScript Here 🔴

Best Answers

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,671
    Answer ✓
    Use evEdgeTangentLine, then evFaceTangentPlane, then construct the plane from those results. 
    Senior Director, Technical Services, EMEAI
  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    edited October 2020 Answer ✓
    You can borrow this function:
    /**
     * Returns normally oriented (by z axis) coord system in the closest point of reference surface.
     */
    export function evRefCoordSys(context is Context, line is Line, referenceFaces is Query) returns CoordSystem
    {
        var distanceResult = evDistance(context, {
                "side0" : referenceFaces,
                "side1" : line.origin
            });

        var faceNormal = evFaceTangentPlane(context, {
                    "face" : referenceFaces->qNthElement(distanceResult.sides[0].index),
                    "parameter" : distanceResult.sides[0].parameter
                }).normal;

        var dir = line.direction;
        dir = normalize(dir - dot(dir, faceNormal) * faceNormal);

        return coordSystem(line.origin, dir, faceNormal);
    }
    The trick is to perform Orthogonalization procedure of one of the vectors extracted from edge tangent and face normal to make sure those vectors are suiting for coordinate system definition. This is what does this string:
    dir = normalize(dir - dot(dir, faceNormal) * faceNormal);




Answers

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,671
    Answer ✓
    Use evEdgeTangentLine, then evFaceTangentPlane, then construct the plane from those results. 
    Senior Director, Technical Services, EMEAI
  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    edited October 2020 Answer ✓
    You can borrow this function:
    /**
     * Returns normally oriented (by z axis) coord system in the closest point of reference surface.
     */
    export function evRefCoordSys(context is Context, line is Line, referenceFaces is Query) returns CoordSystem
    {
        var distanceResult = evDistance(context, {
                "side0" : referenceFaces,
                "side1" : line.origin
            });

        var faceNormal = evFaceTangentPlane(context, {
                    "face" : referenceFaces->qNthElement(distanceResult.sides[0].index),
                    "parameter" : distanceResult.sides[0].parameter
                }).normal;

        var dir = line.direction;
        dir = normalize(dir - dot(dir, faceNormal) * faceNormal);

        return coordSystem(line.origin, dir, faceNormal);
    }
    The trick is to perform Orthogonalization procedure of one of the vectors extracted from edge tangent and face normal to make sure those vectors are suiting for coordinate system definition. This is what does this string:
    dir = normalize(dir - dot(dir, faceNormal) * faceNormal);




  • Alex_KempenAlex_Kempen Member Posts: 248 EDU
    One solution that should work for placing planes on edges is to use evTangentLine to get a line tangent to the edge. You could then make a new plane with normal equal to the direction of the tangent line and with origin equal to the origin of the tangent line. In order to get the x-direction of the plane to run along the face, you could probably take the cross product of the direction of the line tangent to the edge and the normal of the face, which should give you a vector perpendicular to both.
    In order to make the plane with all of your specifications, you may want to first make a coordsystem, then call plane(coordsystem) on that coordsystem. I hope that helps!
    CS Student at UT Dallas
    Alex.Kempen@utdallas.edu
    Check out my FeatureScripts here:



  • Alex_KempenAlex_Kempen Member Posts: 248 EDU
    edited October 2020
    Also, an easier way to get the edges adjacent to plane might be:
    var edge = qAdjacent(definition.face, AdjacencyType.EDGE, EntityType.EDGE)->qNthElement(0);

    This takes advantage of qNthElement to avoid having to evaluate the query first. 

    CS Student at UT Dallas
    Alex.Kempen@utdallas.edu
    Check out my FeatureScripts here:



  • MichaelPascoeMichaelPascoe Member Posts: 1,979 PRO
    edited October 2020
    I posted this Friday night, woke up at 8am Saturday and already had two great responses! 

    Thank you! @NeilCooke @konstantin_shiriazdanov @Alex_Kempen





    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   Learn How to FeatureScript Here 🔴
Sign In or Register to comment.