Pick side of the rectangle

Hi!
I would like to choose right, left, top and bottom side of rectangle laying on any plane by positive and negative X,Y vectors of this plane. How can I do this?


Your images seems unrelated each-other, so i’m not sure I’m understanding correctly your request.

Explode your rectangle and use List Item component, the 4 sides of your rectangle should have always the same order, from the point of view of the plane you used to create the rectangle.

While this is not exactly what you were asking for, the sides can be constructed by the corner points:
https://developer.rhino3d.com/api/rhinocommon/rhino.geometry.rectangle3d/corner#point3dcorner(int32)


rectangle_line_by_vector.gh (7.5 KB)

1 Like

Well, my mistake. I attached screenshot of script without rotate component and rhino viewport with rectangle rotated 45 degrees. Of course in this simple case I can explode this rectangle and list any segment. In my target script I would like to indicate exact side of rectangle for adding dimensions.

This is exactly, what I was thinking of. Thank you @dn.aur !!!

I tried your script yesterday at my private computer, in Rhino 8 and it worked. Today I tried to open it at work in Rhino 7, and I got an error message, that this script needs RhinoCodePluginGH to open correctly. Creating new GhPython Script component and rewriting code also didn’t work. I asked ChatGPT to create C# code based on Python, and it’s working the same way, like yours.

Here is the code:

  1. Set up the Grasshopper environment:
  • Place a C# Script component on the Grasshopper canvas.
  • Set the inputs to rectangle (type Rectangle3d) and side (type int).
  1. Example C# script:
using Rhino.Geometry;

private void RunScript(Rectangle3d rectangle, int side, ref object A)
{
    // Indices of the rectangle corners
    int i = 0;
    int j = 0;

    // Select the appropriate indices based on the given direction
    if (side == 1) // +X
    {
        i = 1;
        j = 2;
    }
    else if (side == 2) // -X
    {
        i = 3;
        j = 0;
    }
    else if (side == 3) // +Y
    {
        i = 2;
        j = 3;
    }
    else if (side == 4) // -Y
    {
        i = 0;
        j = 1;
    }
    else
    {
        throw new System.ArgumentException("Invalid side value");
    }

    // Create a line based on the selected corners
    Line line = new Line(rectangle.Corner(i), rectangle.Corner(j));

    // Output
    A = line;
}

There’s no need to go coding python/c# for such trivial things (apart from to learn coding)… just use list item:


rectangle sides.gh (4.9 KB)

Well, I still look for the soultion. Maybe I didn’t specify my need well. I’ll try to describe it with a different example.

Let’s take a box and its faces - rectangles opposite each other. Each of them (blue and green) has different local planes that define the vertices’ start index. So for every face of this box, you have sides (right, left, top, bottom) depending on its local plane.

I would like to take any plane (in this case, the yellow plane XZ) and, based on its X and Y directions, choose the sides of the rectangles (not by vertices’ index).

So I mean script where I choose reference plane, blue rectangle and right side and as a result achieve side (0-1). The same with green rectangle - side (2-3).


rectangle_side_test.gh (11.4 KB)

If you are working in a context where everything is expected to be fully orthogonal, a simple way would be to do the boundingbox of your rectangles by using your plane as system of orientation.
It should be a “flat box”.
Then deconstruct your flat box and with the U and V domains recreate a new rectangle on an offset plane at W distance.
This rectangle will have your usual orientation.


Another way would be picking the mid point of each side of the rectangle, find its coordinate on your plane, sort by U > first and last are your left and right vertical sides … or sort by V > first and last are your bottom and top sides.


You are not wrong, but i did refer to U,V,W as the direction of a coordinate system (“plane” in gh) different from WorldXYZ.


@DavidRutten I think this was discussed before.
Maybe for GH2, it is possible to have more coherence in the input/output names?

I think it would make more sense to have X,Y,Z be used only when the vectors are used exclusively as orthogonal to WorldXYZ, in all other cases… wouldn’t be better call them U,V,W , like in “Point oriented”?

Also, point are almost always “P” but so are planes!
Exception, on “Plane coordinates” planes are “system” S.
Exception, on “Plane closest point” points are “sample point” S.

A bit of a mess?

Even with “Full names” off, some name are made with 2 letters, like “Pt” , “xy” , “uv”.

Maybe always using “Pt” for points and “Pl” for planes? (as S is for surfaces…)

… just an idea…