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 do I create a plane that is perpendicular to a surface?

Kira_LeeKira_Lee Member, Developers Posts: 17
I am trying to make a revolved cut feature that I can drop onto a cylinder face (the cylinder should be able to be anywhere in space) but the sketch plane has to be perpendicular to the face chosen.
I've used the code below where realPlane is the plane chosen by the user.
var sketchPlane1 = plane(vector(0, 0, 0) * inch, realPlane.origin);
but if my realPlane.origin happens to also be the world coordinate of 0, 0, 0 in space, this doesn't work.

For this feature, the length of the cylinder isn't fixed nor is it known in the feature - the only input/parameter is the face that's chosen.

Thanks in advance!

Best Answer

Answers

  • _anton_anton Member, Onshape Employees Posts: 510 image
    Answer ✓
    If you have a planar face and you want to make *some* plane perpendicular to it, you can construct it with perpendicularVector(facePlane.normal) as the normal. https://cad.onshape.com/FsDoc/library.html#perpendicularVector-Vector
  • duncan_ledesmaduncan_ledesma Member Posts: 6

    Testing using the TFR planes - perpendicularVector only works for Front "Cannot resolve plane". This is not a complete answer unfortunately.

    Here is my file if you're curious. It attempts to make a sketch given a face and extrudes a cylinder. The relevant portion is three lines long and comprises two println sandwiching the plane.normal reassignment:

    FeatureScript 2837;
    import(path : "onshape/std/common.fs", version : "2837.0");
    
    annotation { "Feature Type Name" : "Cylinder", "Feature Type Description" : "Make a cylinder in the middle of the plane" }
    export const f3 = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            // Define the parameters of the feature type
            annotation { "Name": "Face", "Filter": EntityType.FACE }
            definition.face is Query;
            annotation { "Name" : "Diameter" }
            isLength(definition.diameter, LENGTH_BOUNDS);
            annotation { "Name" : "Length" }
            isLength(definition.length, LENGTH_BOUNDS);
            
        }
        {
            
            // Assertion
            if (definition.diameter <= 0 || definition.length <= 0) throw regenError("Absolute values only");
            
            // Face -> Plane
            var plane = evPlane(
                context, 
                { "face" : definition.face }
            );
            
            println("Before: " ~ plane.normal);
            plane.normal = perpendicularVector(plane.normal);  // uncomment this line to use original behaviour
            println("After: " ~ plane.normal);
            
            // Plane -> Sketch
            var sketch = newSketchOnPlane(
                context, 
                id + "sketch", 
                { "sketchPlane" : plane }
            );
            
            // Sketch -> Add circle 
            skCircle(sketch, "circle", {
                    "center" : vector(0, 0) * millimeter,
                    "radius" : definition.diameter,
            });
            
            skSolve(sketch);
            
            var skr = qSketchRegion(id + "sketch");
            
            opExtrude(context, id + "extrude", {
                "entities" : skr,
                "direction" : evOwnerSketchPlane(context, {"entity" : skr}).normal,
                "startBound": BoundingType.BLIND,
                "startDepth": definition.length / 2,
                "endBound" : BoundingType.BLIND,
                "endDepth" : definition.length / 2
            });   
        });
    

    If I learn of a solution that works for all test cases, I will come back to this thread.

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,952 image

    You can't just change a plane's normal, you need to reconstruct it using plane(plane.origin, perpendicularVector(plane.normal))

    Senior Director, Technical Services, EMEA
  • duncan_ledesmaduncan_ledesma Member Posts: 6

    Replying to confirm that this solved my issue. I spent a shameful amount of time trying to fix it in other ways the other day, but it's obvious even to a non-mathematician.

Sign In or Register to comment.