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.

Finding 90 degree angled vertices among selected lines

eric_ma454eric_ma454 Member Posts: 14
Hi all,
My name is Eric Ma, and myself and 3 others represent a subteam of AguaClara Cornell dedicated to using Featurescript to model our plants. We just switched to OnShape, and are new to Featurescript, so we'll probably be showing up on the forums much more frequently. We're excited to learn more about the language, and all help would be greatly appreciated!

Our current project involves inserting elbows into a selection of created pipes. This is a modification off of the current Beam feature, which is being used to model pipes. The current feature takes an input of edges, and creates "beams" from the edges. Our goal is to find all the points within the given selection of edges that have a 90 degree vertex, and insert an elbow of a specific size there. Our current issue stems from finding the specific 90 degree points. We have found all adjacent points with qVertexAdjacent, but the issue is we're unsure how to find that the vertices that only have two lines stemming from it at 90 degrees. Any help would be appreciated, on this specific question or on Featurescript in general.

Best,
Eric Ma
AguaClara Cornell 


@ethan_keller924

Comments

  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    As i see you need to iterate through a list of given vertices in the loop and for each vertex query its adjacent line edges and check if the number of edges is exactly 2 and if the vectors of edge lines are perpendicular.

    so if definition.vertices is a Query of verteces then you get:

    normalAdjacentEdges = [];
    for vertex in evaluateQuery(context, definition.vertices)
    {
    var lineEdges =qGeometry( qVertexAdjacent(vertex, EntityType.EDGE), GeometryType.LINE);
    lineEdges = evaluateQuery(context, lineEdges);
    if (size(lineEdges)==2)
    {
    var line1 = evLine(..., lineEdges[0]);
    var line2 = evLine(..., lineEdges[1]);
    if (perpendicularVectors(line1.direction, line2.direction))
    normalAdjacentEdges =  append(normalAdjacentEdges, lineEdges);
    }
    }
  • MBartlett21MBartlett21 Member, OS Professional, Developers Posts: 2,050 ✭✭✭✭✭
    @konstantin_shiriazdanov & @eric_ma454

    You may want to use qWithinRadius if they are sketch lines to find adjacent ones.

    Example code (Replace variables in BOLD_ITALICS with your variables:
    var perpendicularPointsAndLines = [];
    var evaluatedVertices = evaluateQuery(context, <b><i>VERTICES</i></b>);
    for(var vertex in evaluatedVertices){
        var vertexPoint = evVertexPoint(context, {"vertex" : vertex });
        var lineEdges = evaluateQuery(context, qGeometry(qWithinRadius(<b><i>LINES_FROM_INPUT</i></b>, vertexPoint, TOLERANCE.zeroLength * meter),
             GeometryType.LINE));
        if(size(lineEdges) == 2){
             var d1 = evLine(context, {"edge" : lineEdges[0]}).direction;
             var d2 = evLine(context, {"edge" : lineEdges[1]}).direction;
             if(perpendicularVectors(d1,d2))
                 perpendicularPointsAndLines = append(perpendicularPointsAndLines, {"vertex" : vertexPoint,"edges" : lineEdges});
        }
    }

    mb - draftsman - also FS author: View FeatureScripts
    IR for AS/NZS 1100
  • ethan_keller924ethan_keller924 Member, csevp Posts: 42 PRO
    Another option is to create an array of all the angles between adjacent lines within a constructed path. This feature should work for you!:
    FeatureScript 937;
    import(path : "onshape/std/geometry.fs", version : "937.0");
    
    annotation { "Feature Type Name" : "FindAngles" }
    export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            // Define the parameters of the feature type
            annotation { "Name" : "Lines or arcs", "Filter" : EntityType.EDGE && (GeometryType.LINE || GeometryType.ARC) }
            definition.edges is Query;
        }
        {
            var path = constructPath(context, definition.edges);
            var nLines = size(path.edges);
            var tangentLines = evPathTangentLines(context, path, range(0,1,nLines));
            var angles = [];
            for (var i = 0; i<nLines-1; i=i+1){
                var angle = angleBetween(tangentLines.tangentLines[i].direction, tangentLines.tangentLines[i+1].direction);
                angles = append(angles, angle);
            }
            print("An array of the angle at each of the points along the selected path: ");
            print(angles);
        });


Sign In or Register to comment.