Deleting the shorter edge of a rectangle
3869
9
2
May 6, 2021 11:25 a.m.
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)
tamte
Member
9376 posts
Joined: July 2007
Online
May 7, 2021 9:55 a.m.
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 CG Supervisor Framestore, NY
tamte
Member
9376 posts
Joined: July 2007
Online
May 7, 2021 9:56 a.m.
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 CG Supervisor Framestore, NY
May 7, 2021 10:19 a.m.
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 2That's a great solution! How would I go about applying this on scale, for an arbitrary number of rectangles?
tamte
Member
9376 posts
Joined: July 2007
Online
May 7, 2021 10:46 a.m.
easiest would be to run it through For Each Block that iterates per rectangle
Tomas Slancik CG Supervisor Framestore, NY
K Pavan
Member
65 posts
Joined: Nov. 2014
Offline
May 7, 2021 10:49 a.m.
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 K Pavan - May 7, 2021 10:59:23
Attachments:
use rest length from convert line.png (575.1 KB)
Houdini Fx Artist (Build)
tamte
Member
9376 posts
Joined: July 2007
Online
May 7, 2021 4:06 p.m.
Naga Pavan can sort multiple rectangles with the same blast or delete nodeOnly if no rectangle has larger edge smaller than other rectangle's smaller one
Tomas Slancik CG Supervisor Framestore, NY
May 8, 2021 7:28 a.m.
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)
May 8, 2021 7:53 a.m.
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)
K Pavan
Member
65 posts
Joined: Nov. 2014
Offline
May 9, 2021 1:47 a.m.
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 K Pavan - May 9, 2021 11:11:03
Houdini Fx Artist (Build)