0
|
8355 Views
|
4 Replies
|
3 Total Likes
View groups...
Share

# Is it OK to use NestList in this situation?

Posted 8 years ago
 Hello friends, I hope you are spending a few moments full of joy and fun, in my case I am having fun breaking my head with the problem that I will try to explain. I have the following function, which it does is cut a prism by the y-axis. dtr[{{x_, y_, z_}, {x1_, y1_, z1_}}] := Module[{yes, xs, zeta, inf, sup, val}, yes = (y1 - y)/2; val = RandomChoice[{1, 3/2, 2, 5/2}]; xs = x1 - x; zeta = z1 - z; inf = {{x, y, z} - {0, 0, val}, {x + xs, y + yes, zeta} - {0, 0, val}}; sup = {{x, y + yes, z} + {0, 0, val}, {x + xs, y + 2 yes, zeta} + {0, 0, val}}; {inf, sup}]  Here is an example of what this function performs dtr[{{0, 0, 0}, {32, 32, 8}}] Graphics3D[Map[Cuboid, %]]  The problem arises, when you want to continue applying the function to the previous result on several occasions, I tried to use NestList, but without success, as shown in the following image. This is something like what you expect to get after you have applied the function four times. {{{0, 0, -6}, {32, 2, 23/2}}, {{0, 2, -3}, {32, 4, 29/2}}, {{0, 4, -3}, {32, 6, 23/2}}, {{0, 6, 0}, {32, 8, 29/2}}, {{0, 8, -(7/2)}, {32, 10, 19/2}}, {{0, 10, -(1/2)}, {32, 12, 25/ 2}}, {{0, 12, -(3/2)}, {32, 14, 19/2}}, {{0, 14, 3/2}, {32, 16, 25/ 2}}, {{0, 16, -4}, {32, 18, 11/2}}, {{0, 18, -2}, {32, 20, 15/ 2}}, {{0, 20, 1}, {32, 22, 11/2}}, {{0, 22, 3}, {32, 24, 15/ 2}}, {{0, 28, 9/2}, {32, 30, 1/2}}, {{0, 30, 13/2}, {32, 32, 5/ 2}}, {{0, 24, 2}, {32, 26, 0}}, {{0, 26, 5}, {32, 28, 3}}}  Could someone help me solve my problem?, Maybe the use of NestList is not correct in this case, any help is welcome. Thanks in advance Attachments:
4 Replies
Sort By:
Posted 8 years ago
 A very interesting solution to analyze and test, thanks for sharing it. Greetings Luis
Posted 8 years ago
 Hi Luis,you do can use Nest in this case (an interesting problem by the way!): r = v : {{x1_, y1_, z1_}, {x2_, y2_, z2_}} :> Sequence @@ dtr[v]; cuboids = Nest[# /. r &, {{{0, 0, 0}, {128, 128, 128}}}, 6]; Graphics3D[Cuboid /@ cuboids] First I was playing around with SubstitutionSystem but I could not make that work ...Regards -- Henrik
Posted 8 years ago
 Hello l van Veen, thanks for your suggestions, I have solved it the following way as I put it in the following image and I share the code.But I have to tell you, the person who told me about the algorithm I'm trying to implement confused me, so I asked for some reference and gave me the following link Planar version, but I still do not finish to find out how the algorithm works, but I think Something will serve what I have done. I hope your comments on this, greetingsLuis Ledesma /...>
Posted 8 years ago
 Hi Luis, it seems to me that dtr is not listable? So uno generates a list of two items. I would try to make dtr map over a list of results. your uno result does not match your pattern in dtr because of this.