Deleting the shorter edge of a rectangle

   2952   9   2
User Avatar
Member
5 posts
Joined: 10月 2019
Offline
Hello dear Houdini artists,

I'm relatively new to Houdini and still struggling with some of the more basic concepts.

My problem is the following: I have a rectangle (created from a bound node) and I want to delete either the shorter or the longer edge of that rectangle, so that I can then create a vector that shows me the orientation of that rectangle.

How would I go about doing that? I have measured the lengths of the rectangle with a convert line node, but how can I compare the 2 lengths and remove one or the other?

Is there a better way to go about this?



I would really appreciate some help with this.

Best regards,

Julian

Attachments:
rectangle_problem.JPG (24.8 KB)

User Avatar
Member
8838 posts
Joined: 7月 2007
Offline
julianbragagna
I have measured the lengths of the rectangle with a convert line node, but how can I compare the 2 lengths and remove one or the other?
You can then use Sort SOP to sort prims by your length attribute

And then Blast SOP to keep or delete primitives: 0 1
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
8838 posts
Joined: 7月 2007
Offline
julianbragagna
I have measured the lengths of the rectangle with a convert line node, but how can I compare the 2 lengths and remove one or the other?
You can then use Sort SOP to sort prims by your length attribute

And then Blast SOP to keep or delete primitives: 0 1
As those will be the shortest 2
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
5 posts
Joined: 10月 2019
Offline
tamte
You can then use Sort SOP to sort prims by your length attribute

And then Blast SOP to keep or delete primitives: 0 1
As those will be the shortest 2

That's a great solution! How would I go about applying this on scale, for an arbitrary number of rectangles?
User Avatar
Member
8838 posts
Joined: 7月 2007
Offline
easiest would be to run it through For Each Block that iterates per rectangle
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
58 posts
Joined: 11月 2014
Offline
julianbragagna
How would I go about applying this on scale, for an arbitrary number of rectangles?

using the rest length prim attribute generating form the convertline can sort multiple rectangles with the same blast or delete node
if u precisely need per rectangle sort then go with tamte suggestion
Edited by Houdini Obsession - 2021年5月7日 10:59:23

Attachments:
use rest length from convert line.png (575.1 KB)

Houdini Fx Artist (Build)
User Avatar
Member
8838 posts
Joined: 7月 2007
Offline
Naga Pavan
can sort multiple rectangles with the same blast or delete node
Only if no rectangle has larger edge smaller than other rectangle's smaller one
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
686 posts
Joined: 9月 2013
Offline
julianbragagna
Is there a better way to go about this?

To obtain the short direction you could unroll your rectangles and subtract their minimal position from the primitive's center:

v@dir = normalize(minpos(1, v@P) - v@P);

To obtain the long direction you would calculate the cross product of the short direction and the primitive's normal:

vector nml = prim_normal(0, i@primnum, vector(0.0));
v@perp = normalize(cross(v@dir, nml));

Attachments:
rect_dir.hipnc (96.9 KB)

https://procegen.konstantinmagnus.de/ [procegen.konstantinmagnus.de]
User Avatar
Member
686 posts
Joined: 9月 2013
Offline
Alternatively you could iterate through the primitive's points, and compare the subtractions of their point positions:

int pts[] = primpoints(0, i@primnum);

vector pos_0 = point(0, 'P', pts[0]);
vector pos_1 = point(0, 'P', pts[1]);
vector pos_2 = point(0, 'P', pts[2]);

vector dir_10 = pos_1 - pos_0;
vector dir_21 = pos_2 - pos_1;

v@dir_short;

if(length(dir_10) > length(dir_21)){
    v@dir_short = normalize(dir_21);
}
else{
    v@dir_short = normalize(dir_10);
}

Attachments:
rect_dir_pts.hipnc (100.6 KB)

https://procegen.konstantinmagnus.de/ [procegen.konstantinmagnus.de]
User Avatar
Member
58 posts
Joined: 11月 2014
Offline
tamte
yeah, if rectangles vary in size it fails, I realized sorting with the attribute and deleting 0 1 per connectivity is safer

Konstantin Magnus thank you sharing your sorting methods
Edited by Houdini Obsession - 2021年5月9日 11:11:03
Houdini Fx Artist (Build)
  • Quick Links