Pidgy Posted April 13, 2021 Share Posted April 13, 2021 (edited) Currently wondering if it's possible to do something similar to the image below: http://imgur.com/a/wdZXpHU I want to be able to pack rectangles and squares into a uneven grid of points, 2x2, 2x4, 1x3, etc.. I'm not sure how to go about this those as it doesn't seem as simple as making a 2d array and checking if a pointer goes out of bounds? I don't mind if it's brute forced as all the squares don't need to be filled, just most of them. Struggling to find a solution to this though Edited April 13, 2021 by Pidgy Quote Link to comment Share on other sites More sharing options...
Adam Ferestad Posted April 13, 2021 Share Posted April 13, 2021 The points in your image still appear to be a regular square grid with irregular edges, so you could probably accomplish what you are looking for using a grid and some VEX to delete prims that you don't want. I would probably delete them randomly in a while loop, then come up with a check that would be able to detect the patterns. I will have to noodle on it, though I do have some ideas. I'm thinking using area vs perimeter to check if a block has become a valid shape since there is a unique set for both that will mean it has the right shape. That only works if you have a uniform area per prim though. If you want to use non-uniform, it gets much more complex. Doing it this way could actually allow you to select any shape, though mirrors would be identical so an L shape could be possible to find, but the other 3 variations of it would pop up as well. You could also have a half-edge calculation walk around the shape and check the number of corners, so any 4 corner shape would indicate that it is a rectangle, anything more would be ignored. No matter how you slice it, you are asking about a very interesting Comp Sci/Math problem. Quote Link to comment Share on other sites More sharing options...
ryew Posted April 14, 2021 Share Posted April 14, 2021 (edited) Unless I'm misunderstanding, this seems to essentially be a shape/object packing problem - there have been threads on that here with a number of example files, so if that is indeed what you're after, I'm sure you'll find a solution previously posted Plus an entagma tutorial you might find useful: https://entagma.com/houdini-17-quicktip-packing-geometry-using-the-uv-layout-sop/ Edited April 14, 2021 by ryew including links to previous posts Quote Link to comment Share on other sites More sharing options...
Adam Ferestad Posted April 14, 2021 Share Posted April 14, 2021 It is completely a packing problem, I was just trying to keep some of the math speak out of my response. I will definitely look at that post you linked to, looks juciy. Quote Link to comment Share on other sites More sharing options...
Librarian Posted April 14, 2021 Share Posted April 14, 2021 (edited) Fun points Grid vector2 pos = rand (@elemnum)-{.5,.5}; pos *= 10; int pt = addpoint(0,pos); vector scale = fit01(rand(@elemnum+0.1),{0.2,0.5,1},{1,1,1}); float pscale = length(set(scale.x,scale.y)); setpointattrib(0,"scale",pt,scale); setpointattrib(0,"pscale",pt,pscale); vector nor= {0,0,1}; vector up = fit01(rand(@elemnum*0.2),{-1,-1,0},{1,1,0}); up= normalize(up); setpointattrib(0,"up",0,up); solver removevalue(near_pts,@ptnum); vector avg; vector scale; vector pos; vector dir; vector up; int n = len(near_pts); foreach(int pt; near_pts){ scale = point(0,"scale",pt); pos = point (0,"P",pt); dir = @P-pos; up = point(0,"up",pt); if(abs(dot(up,@up))>0.001){ @up += length(@up-up)*(up-@up)/n; } if(abs(dot(dir,v@side))<scale.x+@scale.x && abs(dot(dir,@up))<scale.y+@scale.y){ avg += 1.2*(@P-pos)/pow(length(@P-pos),4); } else if(n<chi("compactnes")){ avg += pow(length(dir),2)*(pos-@P)/n; } } @P += 0.008*normalize(avg); outside int pts[]; matrix xform = instance(@P,@N,@scale,0,@up); foreach (vector pos;{{-1,-1},{-1,1},{1,1},{1,-1}}){ pos *= xform; append ( pts,addpoint(0,pos)); } int prim = addprim(0,"poly",pts); setprimattrib(0,"Cd",prim,vector(rand(0.1*@ptnum))); removepoint(0,@ptnum); Edited April 14, 2021 by Librarian 1 Quote Link to comment Share on other sites More sharing options...
Adam Ferestad Posted April 15, 2021 Share Posted April 15, 2021 That is a really interesting solution and I like it. I would like to figure out how to make it minimized though, so there is a minimum total gap space. Quote Link to comment Share on other sites More sharing options...
Librarian Posted April 15, 2021 Share Posted April 15, 2021 and this file from @Nate... have nice tricks packing_boxes_v001.hiplc Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.